diff --git a/account_operating_unit/README.rst b/account_operating_unit/README.rst index 7a5d698309..5fa570ab00 100644 --- a/account_operating_unit/README.rst +++ b/account_operating_unit/README.rst @@ -128,6 +128,9 @@ Contributors * Jarsa Sistemas * Alan Ramos * Hieu, Vo Minh Bao +* `PyTech `_: + + * Simone Rubino Maintainers ~~~~~~~~~~~ diff --git a/account_operating_unit/models/account_journal.py b/account_operating_unit/models/account_journal.py index 6e1e452577..203d5b5b17 100644 --- a/account_operating_unit/models/account_journal.py +++ b/account_operating_unit/models/account_journal.py @@ -11,7 +11,6 @@ class AccountJournal(models.Model): operating_unit_id = fields.Many2one( comodel_name="operating.unit", - domain="[('user_ids', '=', uid)]", help="Operating Unit that will be used in payments, " "when this journal is used.", ) diff --git a/account_operating_unit/models/account_move.py b/account_operating_unit/models/account_move.py index d1c483f9fb..45bd73a55a 100644 --- a/account_operating_unit/models/account_move.py +++ b/account_operating_unit/models/account_move.py @@ -10,7 +10,7 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" operating_unit_id = fields.Many2one( - comodel_name="operating.unit", domain="[('user_ids', '=', uid)]" + comodel_name="operating.unit", ) @api.model_create_multi @@ -138,7 +138,6 @@ def _default_operating_unit_id(self): operating_unit_id = fields.Many2one( comodel_name="operating.unit", default=_default_operating_unit_id, - domain="[('user_ids', '=', uid)]", help="This operating unit will be defaulted in the move lines.", readonly=True, states={"draft": [("readonly", False)]}, diff --git a/account_operating_unit/models/account_payment.py b/account_operating_unit/models/account_payment.py index 1bcf6bb68a..c268ebf44d 100644 --- a/account_operating_unit/models/account_payment.py +++ b/account_operating_unit/models/account_payment.py @@ -16,7 +16,6 @@ def _compute_operating_unit_id(self): operating_unit_id = fields.Many2one( comodel_name="operating.unit", - domain="[('user_ids', '=', uid)]", compute="_compute_operating_unit_id", store=True, ) diff --git a/account_operating_unit/readme/CONTRIBUTORS.rst b/account_operating_unit/readme/CONTRIBUTORS.rst index 429b98df69..70905f1a98 100644 --- a/account_operating_unit/readme/CONTRIBUTORS.rst +++ b/account_operating_unit/readme/CONTRIBUTORS.rst @@ -7,3 +7,6 @@ * Jarsa Sistemas * Alan Ramos * Hieu, Vo Minh Bao +* `PyTech `_: + + * Simone Rubino diff --git a/account_operating_unit/static/description/index.html b/account_operating_unit/static/description/index.html index 7af235128d..d87a87e3b6 100644 --- a/account_operating_unit/static/description/index.html +++ b/account_operating_unit/static/description/index.html @@ -480,6 +480,10 @@

Contributors

  • Jarsa Sistemas <info@jarsa.com.mx>
  • Alan Ramos <alan.ramos@jarsa.com.mx>
  • Hieu, Vo Minh Bao <hieu.vmb@komit-consulting.com>
  • +
  • PyTech: +
  • diff --git a/account_operating_unit/tests/test_account_operating_unit.py b/account_operating_unit/tests/test_account_operating_unit.py index f1dc5d485e..97994ab0ee 100644 --- a/account_operating_unit/tests/test_account_operating_unit.py +++ b/account_operating_unit/tests/test_account_operating_unit.py @@ -5,6 +5,7 @@ import odoo.tests from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.mail.tests.common import mail_new_test_user @odoo.tests.tagged("post_install", "-at_install") @@ -22,6 +23,7 @@ def setUp(self): # company self.company = self.env.user.company_id + self.grp_ou_manager_xmlid = "operating_unit.group_manager_operating_unit" self.grp_acc_manager = self.env.ref("account.group_account_manager") # Main Operating Unit self.ou1 = self.env.ref("operating_unit.main_operating_unit") @@ -68,6 +70,18 @@ def setUp(self): "groups_id": [(6, 0, [self.grp_acc_manager.id])], } ) + admin_groups = self.env.ref("base.user_admin").groups_id + self.ou_manager_user = mail_new_test_user( + self.env, + login="OU Manager", + groups=",".join( + [xmlid for gid, xmlid in admin_groups.get_external_id().items()] + + [ + self.grp_ou_manager_xmlid, + ] + ), + ) + # Create cash - test account user_type = self.env.ref("account.data_account_type_current_assets") self.current_asset_account_id = self.account_model.create( diff --git a/account_operating_unit/tests/test_invoice_operating_unit.py b/account_operating_unit/tests/test_invoice_operating_unit.py index 1610109e6d..7454729f5c 100644 --- a/account_operating_unit/tests/test_invoice_operating_unit.py +++ b/account_operating_unit/tests/test_invoice_operating_unit.py @@ -2,12 +2,13 @@ # © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -import odoo.tests +from odoo import tests +from odoo.tools.safe_eval import safe_eval from . import test_account_operating_unit as test_ou -@odoo.tests.tagged("post_install", "-at_install") +@tests.tagged("post_install", "-at_install") class TestInvoiceOperatingUnit(test_ou.TestAccountOperatingUnit): def test_create_invoice_validate(self): """Create & Validate the invoice. @@ -33,3 +34,32 @@ def test_create_invoice_validate(self): False, "Journal Entries have different Operating Units.", ) + + def test_manager_select_operating_unit(self): + """A Manager of Operating Units can + assign any Operating Unit to an invoice.""" + # Arrange + manager_user = self.ou_manager_user + # pre-condition + self.assertTrue(manager_user.has_group(self.grp_ou_manager_xmlid)) + + # Act + invoice_form = tests.Form(self.move_model.with_user(manager_user.id)) + invoice = invoice_form.save() + + # Assert + invoice_form_OU_field = invoice_form._view["fields"]["operating_unit_id"] + selectable_OUs_domain = safe_eval( + invoice_form_OU_field.get("domain") or "[]", + globals_dict=dict( + invoice.read()[0], + uid=invoice.env.uid, + ), + ) + selectable_OUs = ( + self.env["operating.unit"] + .with_user(manager_user.id) + .search(selectable_OUs_domain) + ) + manager_OUs = manager_user.with_company(invoice.company_id).operating_unit_ids + self.assertEqual(manager_OUs, selectable_OUs)