-
Notifications
You must be signed in to change notification settings - Fork 13
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
lanto-razafindrabe
wants to merge
1
commit into
16.0
Choose a base branch
from
TA#72112
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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." | ||
) | ||
) |
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,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 Codacy Production / Codacy Static Code Analysishr_expense_same_month/tests/test_hr_expense_sheet.py#L36
|
||
|
||
@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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @lanto-razafindrabe
we can use record.mapped('expense_line_ids.date.month'), it will return direction a liste of month. No need to add a loop.