Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#72112 [16.0][MIG] hr_expense_same_month #75

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"license": "LGPL-3",
"category": "Other",
"summary": "Install all addons required for testing.",
"depends": [
"hr",
],
"depends": ["hr_expense_same_month"],
"installable": True,
}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ RUN gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS

USER odoo

COPY hr_expense_same_month /mnt/extra-addons/hr_expense_same_month

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
9 changes: 9 additions & 0 deletions hr_expense_same_month/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HR Expense Same Month
=====================
This module forces all the expenses added to a hr expense sheet are on the same month.

.. image:: static/description/expense_sheet_constraint.png

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions hr_expense_same_month/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2018 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models

Check notice on line 4 in hr_expense_same_month/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_expense_same_month/__init__.py#L4

'.models' imported but unused (F401)
17 changes: 17 additions & 0 deletions hr_expense_same_month/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 - Today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in hr_expense_same_month/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_expense_same_month/__manifest__.py#L4

Statement seems to have no effect
'name': 'HR Expense Same Month',
'version': "16.0.1.0.0",
'author': 'Numigi',
'maintainer': 'Numigi',
"website": "https://www.numigi.com",
'license': 'LGPL-3',
'category': 'Human Resources',
'summary': 'Force all the expense of a sheet to be for the same month',
'depends': [
'hr_expense',
],
'installable': True,
}
28 changes: 28 additions & 0 deletions hr_expense_same_month/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_expense_same_month
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-01-17 14:23+0000\n"
"PO-Revision-Date: 2020-01-17 14:23+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_expense_same_month
#: code:addons/hr_expense_same_month/models.py:63
#, python-format
msgid "All expenses must be from the same month. Please review the list of expenses."
msgstr "Toutes les dépenses doivent être du même mois. Merci de revoir la liste des dépenses."

#. module: hr_expense_same_month
#: model:ir.model,name:hr_expense_same_month.model_hr_expense_sheet
msgid "Expense Report"
msgstr "Rapport de dépense"

4 changes: 4 additions & 0 deletions hr_expense_same_month/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2018 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import hr_expense_sheet

Check notice on line 4 in hr_expense_same_month/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_expense_same_month/models/__init__.py#L4

'.hr_expense_sheet' imported but unused (F401)
24 changes: 24 additions & 0 deletions hr_expense_same_month/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2018 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging
from odoo import models, api, _
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)


class HrExpenseSheetConstrain(models.Model):
_inherit = 'hr.expense.sheet'

@api.constrains('expense_line_ids')
def _are_expenses_same_months(self):
for record in self:
months = {line.date.month for line in record.expense_line_ids}

if len(months) > 1:
raise ValidationError(
_(
"All expenses must be from the same month."
" Please review the list of expenses."
)
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hr_expense_same_month/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions hr_expense_same_month/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2020 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
86 changes: 86 additions & 0 deletions hr_expense_same_month/tests/test_hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2020 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import pytest
from odoo.exceptions import ValidationError
from odoo.tests import common
from ddt import ddt, data


@ddt
class TestHrExpenseSheet(common.SavepointCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.expense_pool = cls.env["hr.expense"]
cls.sheet_pool = cls.env["hr.expense.sheet"]
cls.employee = cls.env.ref("hr.employee_admin")
cls.expense = cls.env.ref("hr_expense.travel_by_air_expense").copy()

@data(
("2020-01-01",),
("2020-01-01", "2020-01-25"),
("2020-02-01", "2020-02-25"),
)
def test_create_successPaths(self, dates):
expenses = self._create_expenses_from_date(dates)

sheet = self.sheet_pool.create(
{
"name": "tsheet",
"employee_id": self.employee.id,
"expense_line_ids": [(6, False, expenses)],
}
)
assert sheet

Check warning on line 36 in hr_expense_same_month/tests/test_hr_expense_sheet.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_expense_same_month/tests/test_hr_expense_sheet.py#L36

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

@data(("2020-01-01", "2020-02-01"))
def test_create_faillingPaths(self, dates):
expenses = self._create_expenses_from_date(dates)

with pytest.raises(ValidationError):
self.sheet_pool.create(
{
"name": "tsheet",
"employee_id": self.employee.id,
"expense_line_ids": [(6, False, expenses)],
}
)

@data(
("2020-01-01",),
("2020-01-01", "2020-01-25"),
("2020-02-01", "2020-02-25"),
)
def test_write_successPaths(self, dates):
expenses = self._create_expenses_from_date(dates)
sheet = self.sheet_pool.create(
{
"name": "tsheet",
"employee_id": self.employee.id,
}
)
sheet.write({"expense_line_ids": [(6, False, expenses)]})
assert sheet

@data(("2020-01-01", "2020-02-01"))
def test_write_faillingPaths(self, dates):
expenses = self._create_expenses_from_date(dates)
sheet = self.sheet_pool.create(
{
"name": "tsheet",
"employee_id": self.employee.id,
}
)

with pytest.raises(ValidationError):
sheet.write({"expense_line_ids": [(6, False, expenses)]})

def _create_expenses_from_date(self, dates):
expenses = []
for date in dates:
expense = self.expense.copy()
expense.date = date
expenses.append(expense.id)
return expenses
Loading