Skip to content

Commit 58a0b55

Browse files
committed
Merge PR #824 into 14.0
Signed-off-by AaronHForgeFlow
2 parents f328a80 + 8b23d50 commit 58a0b55

File tree

8 files changed

+57
-6
lines changed

8 files changed

+57
-6
lines changed

account_operating_unit/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ Contributors
128128
* Jarsa Sistemas <[email protected]>
129129
* Alan Ramos <[email protected]>
130130
* Hieu, Vo Minh Bao <[email protected]>
131+
* `PyTech <https://www.pytech.it>`_:
132+
133+
* Simone Rubino <[email protected]>
131134

132135
Maintainers
133136
~~~~~~~~~~~

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/readme/CONTRIBUTORS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
* Jarsa Sistemas <[email protected]>
88
* Alan Ramos <[email protected]>
99
* Hieu, Vo Minh Bao <[email protected]>
10+
* `PyTech <https://www.pytech.it>`_:
11+
12+
* Simone Rubino <[email protected]>

account_operating_unit/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
480480
<li>Jarsa Sistemas &lt;<a class="reference external" href="mailto:info&#64;jarsa.com.mx">info&#64;jarsa.com.mx</a>&gt;</li>
481481
<li>Alan Ramos &lt;<a class="reference external" href="mailto:alan.ramos&#64;jarsa.com.mx">alan.ramos&#64;jarsa.com.mx</a>&gt;</li>
482482
<li>Hieu, Vo Minh Bao &lt;<a class="reference external" href="mailto:hieu.vmb&#64;komit-consulting.com">hieu.vmb&#64;komit-consulting.com</a>&gt;</li>
483+
<li><a class="reference external" href="https://www.pytech.it">PyTech</a>:<ul>
484+
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;pytech.it">simone.rubino&#64;pytech.it</a>&gt;</li>
485+
</ul>
486+
</li>
483487
</ul>
484488
</div>
485489
<div class="section" id="maintainers">

account_operating_unit/tests/test_account_operating_unit.py

Lines changed: 14 additions & 0 deletions
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,6 +23,7 @@ def setUp(self):
2223

2324
# company
2425
self.company = self.env.user.company_id
26+
self.grp_ou_manager_xmlid = "operating_unit.group_manager_operating_unit"
2527
self.grp_acc_manager = self.env.ref("account.group_account_manager")
2628
# Main Operating Unit
2729
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
@@ -68,6 +70,18 @@ def setUp(self):
6870
"groups_id": [(6, 0, [self.grp_acc_manager.id])],
6971
}
7072
)
73+
admin_groups = self.env.ref("base.user_admin").groups_id
74+
self.ou_manager_user = mail_new_test_user(
75+
self.env,
76+
login="OU Manager",
77+
groups=",".join(
78+
[xmlid for gid, xmlid in admin_groups.get_external_id().items()]
79+
+ [
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+
# pre-condition
44+
self.assertTrue(manager_user.has_group(self.grp_ou_manager_xmlid))
45+
46+
# Act
47+
invoice_form = tests.Form(self.move_model.with_user(manager_user.id))
48+
invoice = invoice_form.save()
49+
50+
# Assert
51+
invoice_form_OU_field = invoice_form._view["fields"]["operating_unit_id"]
52+
selectable_OUs_domain = safe_eval(
53+
invoice_form_OU_field.get("domain") or "[]",
54+
globals_dict=dict(
55+
invoice.read()[0],
56+
uid=invoice.env.uid,
57+
),
58+
)
59+
selectable_OUs = (
60+
self.env["operating.unit"]
61+
.with_user(manager_user.id)
62+
.search(selectable_OUs_domain)
63+
)
64+
manager_OUs = manager_user.with_company(invoice.company_id).operating_unit_ids
65+
self.assertEqual(manager_OUs, selectable_OUs)

0 commit comments

Comments
 (0)