-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#72112 [16.0][MIG] hr_expense_same_month (#75)
* TA#72112 [16.0][MIG] hr_expense_same_month --------- Co-authored-by: Majda EL MARIOULI <[email protected]>
- Loading branch information
1 parent
dbbdb8a
commit 8ee8e52
Showing
12 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
) | ||
) |
Binary file added
BIN
+80.4 KB
hr_expense_same_month/static/description/expense_sheet_constraint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |