Skip to content

Commit

Permalink
TA#72112 [16.0][MIG] hr_expense_same_month (#75)
Browse files Browse the repository at this point in the history
* TA#72112 [16.0][MIG] hr_expense_same_month
---------

Co-authored-by: Majda EL MARIOULI <[email protected]>
  • Loading branch information
lanto-razafindrabe and majouda authored Jan 29, 2025
1 parent dbbdb8a commit 8ee8e52
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"summary": "Install all addons required for testing.",
"depends": [
"hr_contract_wage_type",
"hr_expense_same_month",
"hr_working_space",
],
"installable": True,
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ COPY ./gitoo.yml /gitoo.yml
RUN gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS}"

USER odoo

COPY hr_contract_wage_type /mnt/extra-addons/hr_contract_wage_type
COPY hr_expense_same_month /mnt/extra-addons/hr_expense_same_month
COPY hr_working_space /mnt/extra-addons/hr_working_space

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
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
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).

{
"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
22 changes: 22 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,22 @@
# 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 odoo import api, models, _
from odoo.exceptions import ValidationError


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).
85 changes: 85 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,85 @@
# 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

@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

0 comments on commit 8ee8e52

Please sign in to comment.