From dfe366325e3609c65ec92673e75ad06b150aa170 Mon Sep 17 00:00:00 2001
From: Holger Brunn
Date: Thu, 8 Aug 2024 13:10:10 +0200
Subject: [PATCH] [MIG] hr_expense_operating_unit: Migration to 16.0
---
hr_expense_operating_unit/README.rst | 10 +-
hr_expense_operating_unit/__init__.py | 1 -
hr_expense_operating_unit/__manifest__.py | 2 +-
.../models/hr_expense.py | 21 ++-
.../static/description/index.html | 7 +-
.../tests/test_hr_expense_operating_unit.py | 137 +++++++++---------
hr_expense_operating_unit/wizards/__init__.py | 3 -
.../wizards/account_payment_register.py | 16 --
8 files changed, 94 insertions(+), 103 deletions(-)
delete mode 100644 hr_expense_operating_unit/wizards/__init__.py
delete mode 100644 hr_expense_operating_unit/wizards/account_payment_register.py
diff --git a/hr_expense_operating_unit/README.rst b/hr_expense_operating_unit/README.rst
index d351dace68..f0e1cf7e64 100644
--- a/hr_expense_operating_unit/README.rst
+++ b/hr_expense_operating_unit/README.rst
@@ -17,13 +17,13 @@ HR Expense Operating Unit
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
- :target: https://github.com/OCA/operating-unit/tree/15.0/hr_expense_operating_unit
+ :target: https://github.com/OCA/operating-unit/tree/16.0/hr_expense_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-hr_expense_operating_unit
+ :target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-hr_expense_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=15.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -56,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -90,6 +90,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/operating-unit `_ project on GitHub.
+This module is part of the `OCA/operating-unit `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_expense_operating_unit/__init__.py b/hr_expense_operating_unit/__init__.py
index 69f54da63c..44f9fd7c13 100644
--- a/hr_expense_operating_unit/__init__.py
+++ b/hr_expense_operating_unit/__init__.py
@@ -1,4 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
-from . import wizards
diff --git a/hr_expense_operating_unit/__manifest__.py b/hr_expense_operating_unit/__manifest__.py
index d90651bb7f..e828f014c6 100644
--- a/hr_expense_operating_unit/__manifest__.py
+++ b/hr_expense_operating_unit/__manifest__.py
@@ -4,7 +4,7 @@
{
"name": "HR Expense Operating Unit",
- "version": "15.0.1.0.0",
+ "version": "16.0.1.0.0",
"license": "LGPL-3",
"author": "ForgeFlow S.L., "
"Serpent Consulting Services Pvt. Ltd.,"
diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py
index 9e6584a5ac..d197f7133e 100644
--- a/hr_expense_operating_unit/models/hr_expense.py
+++ b/hr_expense_operating_unit/models/hr_expense.py
@@ -65,10 +65,9 @@ def _check_expense_operating_unit(self):
)
def _get_default_expense_sheet_values(self):
- sheet = super()._get_default_expense_sheet_values()
- if len(self.mapped("operating_unit_id")) != 1 or any(
- not expense.operating_unit_id for expense in self
- ):
+ sheet_values = super()._get_default_expense_sheet_values()
+ ous = self.mapped("operating_unit_id")
+ if len(ous) != 1 or any(not expense.operating_unit_id for expense in self):
raise ValidationError(
_(
"You cannot submit the Expenses having "
@@ -76,14 +75,20 @@ def _get_default_expense_sheet_values(self):
"no Operating Unit"
)
)
- sheet.update({"operating_unit_id": self.mapped("operating_unit_id").id})
- return sheet
+ for sheet in sheet_values:
+ sheet.update({"operating_unit_id": ous.id})
+ return sheet_values
- def _prepare_move_values(self):
- move_values = super()._prepare_move_values()
+ def _prepare_move_vals(self):
+ move_values = super()._prepare_move_vals()
move_values["operating_unit_id"] = self.operating_unit_id.id
return move_values
+ def _prepare_move_line_vals(self):
+ move_line_values = super()._prepare_move_line_vals()
+ move_line_values["operating_unit_id"] = self.operating_unit_id.id
+ return move_line_values
+
class HrExpenseSheet(models.Model):
_inherit = "hr.expense.sheet"
diff --git a/hr_expense_operating_unit/static/description/index.html b/hr_expense_operating_unit/static/description/index.html
index a27d9ebde8..c67f890f36 100644
--- a/hr_expense_operating_unit/static/description/index.html
+++ b/hr_expense_operating_unit/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,7 +368,7 @@ HR Expense Operating Unit
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:13f1a13af9ebc3b43564bf45cd6662d058459aee3a7a74028e0fc7b36078e0ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
This module introduces the following features:
- Adds the Operating Unit (OU) to the Expense.
@@ -403,7 +402,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -431,7 +430,7 @@
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/operating-unit project on GitHub.
+
This module is part of the OCA/operating-unit project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py
index f04eb12f7d..558283d1ea 100644
--- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py
+++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py
@@ -2,65 +2,67 @@
# Copyright 2016-19 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-from odoo import fields
+from odoo import fields, tools
from odoo.exceptions import ValidationError
from odoo.tests.common import Form, TransactionCase
class TestHrExpenseOperatingUnit(TransactionCase):
- def setUp(self):
- super(TestHrExpenseOperatingUnit, self).setUp()
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
- self.res_users_model = self.env["res.users"]
- self.hr_expense_model = self.env["hr.expense"]
- self.hr_expense_sheet_model = self.env["hr.expense.sheet"]
- self.hr_employee_model = self.env["hr.employee"]
+ cls.res_users_model = cls.env["res.users"]
+ cls.hr_expense_model = cls.env["hr.expense"]
+ cls.hr_expense_sheet_model = cls.env["hr.expense.sheet"]
+ cls.hr_employee_model = cls.env["hr.employee"]
- self.company = self.env.ref("base.main_company")
- self.partner1 = self.env.ref("base.res_partner_1")
- self.partner2 = self.env.ref("base.res_partner_2")
+ cls.company = cls.env.ref("base.main_company")
+ cls.partner1 = cls.env.ref("base.res_partner_1")
+ cls.partner2 = cls.env.ref("base.res_partner_2")
# Expense Product
- self.product1 = self.env.ref("hr_expense.trans_expense_product")
+ cls.product1 = cls.env.ref("hr_expense.expense_product_mileage")
- self.grp_hr_user = self.env.ref("hr.group_hr_user")
- self.grp_accou_mng = self.env.ref("account.group_account_manager")
- self.grp_account_invoice = self.env.ref("account.group_account_invoice")
+ cls.grp_hr_user = cls.env.ref("hr.group_hr_user")
+ cls.grp_accou_mng = cls.env.ref("account.group_account_manager")
+ cls.grp_account_invoice = cls.env.ref("account.group_account_invoice")
# Main Operating Unit
- self.ou1 = self.env.ref("operating_unit.main_operating_unit")
+ cls.ou1 = cls.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
- self.b2c = self.env.ref("operating_unit.b2c_operating_unit")
+ cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit")
- self.user1 = self._create_user(
+ cls.user1 = cls._create_user(
"Test HR User 1",
"user_1",
"demo1",
- [self.grp_hr_user, self.grp_accou_mng, self.grp_account_invoice],
- self.company,
- [self.ou1, self.b2c],
+ [cls.grp_hr_user, cls.grp_accou_mng, cls.grp_account_invoice],
+ cls.company,
+ [cls.ou1, cls.b2c],
)
- self.user2 = self._create_user(
+ cls.user2 = cls._create_user(
"Test HR User 2",
"user_2",
"demo2",
- [self.grp_hr_user, self.grp_accou_mng, self.grp_account_invoice],
- self.company,
- [self.b2c],
+ [cls.grp_hr_user, cls.grp_accou_mng, cls.grp_account_invoice],
+ cls.company,
+ [cls.b2c],
)
- self.emp = self._create_hr_employee()
+ cls.emp = cls._create_hr_employee()
- self.hr_expense1 = self._create_hr_expense(self.ou1, self.emp)
+ cls.hr_expense1 = cls._create_hr_expense(cls.ou1, cls.emp)
- self.hr_expense2 = self._create_hr_expense(self.b2c, self.emp)
+ cls.hr_expense2 = cls._create_hr_expense(cls.b2c, cls.emp)
+ @classmethod
def _create_user(
- self, name, login, pwd, groups, company, operating_units, context=None
+ cls, name, login, pwd, groups, company, operating_units, context=None
):
"""Creates a user."""
group_ids = [group.id for group in groups]
- user = self.res_users_model.create(
+ user = cls.res_users_model.create(
{
"name": name,
"login": login,
@@ -74,19 +76,21 @@ def _create_user(
)
return user
- def _create_hr_employee(self):
+ @classmethod
+ def _create_hr_employee(cls):
"""Creates an Employee."""
- emp = self.hr_employee_model.create(
- {"name": "Test Employee", "address_home_id": self.partner1.id}
+ emp = cls.hr_employee_model.create(
+ {"name": "Test Employee", "address_home_id": cls.partner1.id}
)
return emp
- def _create_hr_expense(self, operating_unit, emp):
+ @classmethod
+ def _create_hr_expense(cls, operating_unit, emp):
"""Creates Expense for employee."""
- hr_expense = self.hr_expense_model.create(
+ hr_expense = cls.hr_expense_model.create(
{
"name": "Traveling Expense",
- "product_id": self.product1.id,
+ "product_id": cls.product1.id,
"operating_unit_id": operating_unit.id,
"unit_amount": "10.0",
"quantity": "5",
@@ -147,44 +151,47 @@ def test_security(self):
)
self._register_payment(self.hr_expense_sheet1.account_move_id, 50.0)
+ @tools.mute_logger(
+ "odoo.addons.hr_expense_operating_unit.tests.test_hr_expense_operating_unit"
+ )
def test_constrains_error(self):
+ hr_expense_dict1 = self.hr_expense1.action_submit_expenses()
+ sheet_context = hr_expense_dict1.get("context")
+ sheet_dict = {
+ "name": sheet_context.get("default_name", ""),
+ "employee_id": sheet_context.get("default_employee_id", False),
+ "company_id": sheet_context.get("default_company_id", False),
+ "state": sheet_context.get("default_state", ""),
+ "expense_line_ids": sheet_context.get("default_expense_line_ids", []),
+ }
+ self.hr_expense_sheet1 = self.hr_expense_sheet_model.create(sheet_dict)
with self.assertRaises(ValidationError):
- hr_expense_dict1 = self.hr_expense1.action_submit_expenses()
- sheet_context = hr_expense_dict1.get("context")
- sheet_dict = {
- "name": sheet_context.get("default_name", ""),
- "employee_id": sheet_context.get("default_employee_id", False),
- "company_id": sheet_context.get("default_company_id", False),
- "state": sheet_context.get("default_state", ""),
- "expense_line_ids": sheet_context.get("default_expense_line_ids", []),
- }
- self.hr_expense_sheet1 = self.hr_expense_sheet_model.create(sheet_dict)
self.hr_expense_sheet1.expense_line_ids.write(
{"operating_unit_id": self.b2c.id}
)
+ hr_expense_dict2 = self.hr_expense2.action_submit_expenses()
+ sheet_context = hr_expense_dict2.get("context")
+ sheet_dict = {
+ "name": sheet_context.get("default_name", ""),
+ "employee_id": sheet_context.get("default_employee_id", False),
+ "company_id": sheet_context.get("default_company_id", False),
+ "state": sheet_context.get("default_state", ""),
+ "expense_line_ids": sheet_context.get("default_expense_line_ids", []),
+ }
with self.assertRaises(ValidationError):
- hr_expense_dict2 = self.hr_expense2.action_submit_expenses()
- sheet_context = hr_expense_dict2.get("context")
- sheet_dict = {
- "name": sheet_context.get("default_name", ""),
- "employee_id": sheet_context.get("default_employee_id", False),
- "company_id": sheet_context.get("default_company_id", False),
- "state": sheet_context.get("default_state", ""),
- "expense_line_ids": sheet_context.get("default_expense_line_ids", []),
- }
self.hr_expense_sheet2 = self.hr_expense_sheet_model.create(sheet_dict)
- with self.assertRaises(ValidationError):
- self.hr_expense3 = self.hr_expense_model.create(
- {
- "name": "Traveling Expense",
- "product_id": self.product1.id,
- "unit_amount": "10.0",
- "quantity": "5",
- "operating_unit_id": False,
- "employee_id": self.emp.id,
- }
- )
+ self.hr_expense3 = self.hr_expense_model.create(
+ {
+ "name": "Traveling Expense",
+ "product_id": self.product1.id,
+ "unit_amount": "10.0",
+ "quantity": "5",
+ "operating_unit_id": False,
+ "employee_id": self.emp.id,
+ }
+ )
+ with self.assertRaises(ValidationError):
self.hr_expense3.action_submit_expenses()
diff --git a/hr_expense_operating_unit/wizards/__init__.py b/hr_expense_operating_unit/wizards/__init__.py
deleted file mode 100644
index 77e487c8c7..0000000000
--- a/hr_expense_operating_unit/wizards/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-
-from . import account_payment_register
diff --git a/hr_expense_operating_unit/wizards/account_payment_register.py b/hr_expense_operating_unit/wizards/account_payment_register.py
deleted file mode 100644
index 4b6bba2d33..0000000000
--- a/hr_expense_operating_unit/wizards/account_payment_register.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright 2023 Ecosoft Co., Ltd (http://ecosoft.co.th/)
-# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-
-from odoo import models
-
-
-class AccountPaymentRegister(models.TransientModel):
- _inherit = "account.payment.register"
-
- def _get_reconciled_moves(self, payment):
- expenses = payment.move_id.line_ids.mapped("expense_id")
- return (
- expenses.mapped("sheet_id.account_move_id")
- if expenses
- else super()._get_reconciled_moves(payment)
- )