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
78from . 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" )
1112class 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