Skip to content

Commit

Permalink
[MIG] hr_expense_operating_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Aug 8, 2024
1 parent 7eb0e72 commit dfe3663
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 103 deletions.
10 changes: 5 additions & 5 deletions hr_expense_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -56,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/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 <https://github.com/OCA/operating-unit/issues/new?body=module:%20hr_expense_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20hr_expense_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -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 <https://github.com/OCA/operating-unit/tree/15.0/hr_expense_operating_unit>`_ project on GitHub.
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/hr_expense_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion hr_expense_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
from . import wizards
2 changes: 1 addition & 1 deletion hr_expense_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.,"
Expand Down
21 changes: 13 additions & 8 deletions hr_expense_operating_unit/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,30 @@ 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 "
"different Operating Units or with "
"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"
Expand Down
7 changes: 3 additions & 4 deletions hr_expense_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">HR Expense Operating Unit</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:13f1a13af9ebc3b43564bf45cd6662d058459aee3a7a74028e0fc7b36078e0ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/15.0/hr_expense_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-hr_expense_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/16.0/hr_expense_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-hr_expense_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module introduces the following features:</p>
<ul class="simple">
<li>Adds the Operating Unit (OU) to the Expense.</li>
Expand Down Expand Up @@ -403,7 +402,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20hr_expense_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20hr_expense_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -431,7 +430,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/hr_expense_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/16.0/hr_expense_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
137 changes: 72 additions & 65 deletions hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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()
3 changes: 0 additions & 3 deletions hr_expense_operating_unit/wizards/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions hr_expense_operating_unit/wizards/account_payment_register.py

This file was deleted.

0 comments on commit dfe3663

Please sign in to comment.