Skip to content

Commit 4e1698e

Browse files
committed
[FIX] account_operating_unit: Manager can select all OUs
Steps: 1. Create a Manager of Operating Units 2. Create some Operating Units 3. Log in as the created Manager 4. Create an Invoice 5. Click on the Operating Unit field Before this change: Not all Operating Units can be selected. After this change: All Operating Units can be selected.
1 parent f328a80 commit 4e1698e

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

account_operating_unit/models/account_journal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class AccountJournal(models.Model):
1111

1212
operating_unit_id = fields.Many2one(
1313
comodel_name="operating.unit",
14-
domain="[('user_ids', '=', uid)]",
1514
help="Operating Unit that will be used in payments, "
1615
"when this journal is used.",
1716
)

account_operating_unit/models/account_move.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AccountMoveLine(models.Model):
1010
_inherit = "account.move.line"
1111

1212
operating_unit_id = fields.Many2one(
13-
comodel_name="operating.unit", domain="[('user_ids', '=', uid)]"
13+
comodel_name="operating.unit",
1414
)
1515

1616
@api.model_create_multi
@@ -138,7 +138,6 @@ def _default_operating_unit_id(self):
138138
operating_unit_id = fields.Many2one(
139139
comodel_name="operating.unit",
140140
default=_default_operating_unit_id,
141-
domain="[('user_ids', '=', uid)]",
142141
help="This operating unit will be defaulted in the move lines.",
143142
readonly=True,
144143
states={"draft": [("readonly", False)]},

account_operating_unit/models/account_payment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def _compute_operating_unit_id(self):
1616

1717
operating_unit_id = fields.Many2one(
1818
comodel_name="operating.unit",
19-
domain="[('user_ids', '=', uid)]",
2019
compute="_compute_operating_unit_id",
2120
store=True,
2221
)

account_operating_unit/tests/test_account_operating_unit.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import odoo.tests
66

77
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
8+
from odoo.addons.mail.tests.common import mail_new_test_user
89

910

1011
@odoo.tests.tagged("post_install", "-at_install")
@@ -22,7 +23,9 @@ def setUp(self):
2223

2324
# company
2425
self.company = self.env.user.company_id
25-
self.grp_acc_manager = self.env.ref("account.group_account_manager")
26+
self.grp_acc_manager_xmlid = "account.group_account_manager"
27+
self.grp_ou_manager_xmlid = "operating_unit.group_manager_operating_unit"
28+
self.grp_acc_manager = self.env.ref(self.grp_acc_manager_xmlid)
2629
# Main Operating Unit
2730
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
2831
# B2B Operating Unit
@@ -68,6 +71,17 @@ def setUp(self):
6871
"groups_id": [(6, 0, [self.grp_acc_manager.id])],
6972
}
7073
)
74+
self.ou_manager_user = mail_new_test_user(
75+
self.env,
76+
login="OU Manager",
77+
groups=",".join(
78+
[
79+
self.grp_acc_manager_xmlid,
80+
self.grp_ou_manager_xmlid,
81+
]
82+
),
83+
)
84+
7185
# Create cash - test account
7286
user_type = self.env.ref("account.data_account_type_current_assets")
7387
self.current_asset_account_id = self.account_model.create(

account_operating_unit/tests/test_invoice_operating_unit.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# © 2019 Serpent Consulting Services Pvt. Ltd.
33
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

5-
import odoo.tests
5+
from odoo import tests
6+
from odoo.tools.safe_eval import safe_eval
67

78
from . import test_account_operating_unit as test_ou
89

910

10-
@odoo.tests.tagged("post_install", "-at_install")
11+
@tests.tagged("post_install", "-at_install")
1112
class TestInvoiceOperatingUnit(test_ou.TestAccountOperatingUnit):
1213
def test_create_invoice_validate(self):
1314
"""Create & Validate the invoice.
@@ -33,3 +34,32 @@ def test_create_invoice_validate(self):
3334
False,
3435
"Journal Entries have different Operating Units.",
3536
)
37+
38+
def test_manager_select_operating_unit(self):
39+
"""A Manager of Operating Units can
40+
assign any Operating Unit to an invoice."""
41+
# Arrange
42+
manager_user = self.ou_manager_user
43+
manager_OUs = manager_user.operating_unit_ids
44+
# pre-condition
45+
self.assertTrue(manager_user.has_group(self.grp_ou_manager_xmlid))
46+
47+
# Act
48+
invoice_form = tests.Form(self.move_model.with_user(manager_user.id))
49+
invoice = invoice_form.save()
50+
51+
# Assert
52+
invoice_form_OU_field = invoice_form._view["fields"]["operating_unit_id"]
53+
selectable_OUs_domain = safe_eval(
54+
invoice_form_OU_field.get("domain") or "[]",
55+
globals_dict=dict(
56+
invoice.read()[0],
57+
uid=invoice.env.uid,
58+
),
59+
)
60+
selectable_OUs = (
61+
self.env["operating.unit"]
62+
.with_user(manager_user.id)
63+
.search(selectable_OUs_domain)
64+
)
65+
self.assertEqual(manager_OUs, selectable_OUs)

0 commit comments

Comments
 (0)