diff --git a/account_operating_unit/__manifest__.py b/account_operating_unit/__manifest__.py index 5b7eb797e0..e87e9873e1 100644 --- a/account_operating_unit/__manifest__.py +++ b/account_operating_unit/__manifest__.py @@ -5,7 +5,7 @@ "name": "Accounting with Operating Units", "summary": "Introduces Operating Unit (OU) in invoices and " "Accounting Entries with clearing account", - "version": "15.0.1.1.0", + "version": "16.0.1.0.0", "author": "ForgeFlow, " "Serpent Consulting Services Pvt. Ltd.," "WilldooIT Pty Ltd," diff --git a/account_operating_unit/models/account_move.py b/account_operating_unit/models/account_move.py index 01aecc8e34..c6e116a32c 100644 --- a/account_operating_unit/models/account_move.py +++ b/account_operating_unit/models/account_move.py @@ -2,6 +2,8 @@ # © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from contextlib import contextmanager + from odoo import _, api, fields, models from odoo.exceptions import UserError @@ -88,11 +90,9 @@ def _default_operating_unit_id(self): @api.onchange("invoice_line_ids") def _onchange_invoice_line_ids(self): - res = super()._onchange_invoice_line_ids() if self.operating_unit_id: for line in self.line_ids: line.operating_unit_id = self.operating_unit_id - return res @api.onchange("operating_unit_id") def _onchange_operating_unit(self): @@ -190,10 +190,12 @@ def _post(self, soft=True): return super()._post(soft) - def _check_balanced(self): + @contextmanager + def _check_balanced(self, container): if self.env.context.get("wip"): - return True - return super()._check_balanced() + yield + else: + yield super()._check_balanced(container) @api.constrains("line_ids") def _check_ou(self): diff --git a/account_operating_unit/readme/CONTRIBUTORS.rst b/account_operating_unit/readme/CONTRIBUTORS.rst index 69709a3b2d..7e6c69495f 100644 --- a/account_operating_unit/readme/CONTRIBUTORS.rst +++ b/account_operating_unit/readme/CONTRIBUTORS.rst @@ -9,3 +9,4 @@ * Saran Lim. * Pimolnat Suntian * Hieu, Vo Minh Bao +* Alejandro Leonard diff --git a/account_operating_unit/tests/test_account_operating_unit.py b/account_operating_unit/tests/test_account_operating_unit.py index 2a9f379081..6b5e75d91d 100644 --- a/account_operating_unit/tests/test_account_operating_unit.py +++ b/account_operating_unit/tests/test_account_operating_unit.py @@ -9,147 +9,148 @@ @tagged("post_install", "-at_install") class TestAccountOperatingUnit(AccountTestInvoicingCommon): - def setUp(self): - super().setUp() - self.res_users_model = self.env["res.users"] - self.aml_model = self.env["account.move.line"] - self.move_model = self.env["account.move"] - self.account_model = self.env["account.account"] - self.journal_model = self.env["account.journal"] - self.product_model = self.env["product.product"] - self.payment_model = self.env["account.payment"] - self.register_payments_model = self.env["account.payment.register"] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.res_users_model = cls.env["res.users"] + cls.aml_model = cls.env["account.move.line"] + cls.move_model = cls.env["account.move"] + cls.account_model = cls.env["account.account"] + cls.journal_model = cls.env["account.journal"] + cls.product_model = cls.env["product.product"] + cls.payment_model = cls.env["account.payment"] + cls.register_payments_model = cls.env["account.payment.register"] # company - self.company = self.env.user.company_id - self.grp_acc_manager = self.env.ref("account.group_account_manager") + cls.company = cls.env.user.company_id + cls.grp_acc_manager = cls.env.ref("account.group_account_manager") # Main Operating Unit - self.ou1 = self.env.ref("operating_unit.main_operating_unit") + cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") # B2B Operating Unit - self.b2b = self.env.ref("operating_unit.b2b_operating_unit") + cls.b2b = cls.env.ref("operating_unit.b2b_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") # Assign user to main company to allow to write OU - self.env.user.write( + cls.env.user.write( { - "company_ids": [(4, self.env.ref("base.main_company").id)], + "company_ids": [(4, cls.env.ref("base.main_company").id)], "operating_unit_ids": [ - (4, self.b2b.id), - (4, self.b2c.id), + (4, cls.b2b.id), + (4, cls.b2c.id), ], } ) # Assign company to OU - (self.ou1 + self.b2b + self.b2c).write({"company_id": self.company.id}) + (cls.ou1 + cls.b2b + cls.b2c).write({"company_id": cls.company.id}) # Partner - self.partner1 = self.env.ref("base.res_partner_1") + cls.partner1 = cls.env.ref("base.res_partner_1") # Products - self.product1 = self.env.ref("product.product_product_7") - self.product2 = self.env.ref("product.product_product_9") - self.product3 = self.env.ref("product.product_product_11") + cls.product1 = cls.env.ref("product.product_product_7") + cls.product2 = cls.env.ref("product.product_product_9") + cls.product3 = cls.env.ref("product.product_product_11") # Payment methods - self.payment_method_manual_in = self.env.ref( + cls.payment_method_manual_in = cls.env.ref( "account.account_payment_method_manual_in" ) # Create user1 - self.user_id = self.res_users_model.with_context(no_reset_password=True).create( + cls.user_id = cls.res_users_model.with_context(no_reset_password=True).create( { "name": "Test Account User", "login": "user_1", "password": "demo", "email": "example@yourcompany.com", - "company_id": self.company.id, - "company_ids": [(4, self.company.id)], - "operating_unit_ids": [(4, self.b2b.id), (4, self.b2c.id)], - "groups_id": [(6, 0, [self.grp_acc_manager.id])], + "company_id": cls.company.id, + "company_ids": [(4, cls.company.id)], + "operating_unit_ids": [(4, cls.b2b.id), (4, cls.b2c.id)], + "groups_id": [(6, 0, [cls.grp_acc_manager.id])], } ) # Create cash - test account - user_type = self.env.ref("account.data_account_type_current_assets") - self.current_asset_account_id = self.account_model.create( + # user_type = cls.env.ref("account.data_account_type_current_assets") + cls.current_asset_account_id = cls.account_model.create( { "name": "Current asset - Test", - "code": "test_current_asset", - "user_type_id": user_type.id, - "company_id": self.company.id, + "code": "TEST", + "account_type": "asset_current", + "company_id": cls.company.id, } ) # Create Inter-OU Clearing - test account - user_type = self.env.ref("account.data_account_type_equity") - self.inter_ou_account_id = self.account_model.create( + # user_type = cls.env.ref("account.data_account_type_equity") + cls.inter_ou_account_id = cls.account_model.create( { "name": "Inter-OU Clearing", - "code": "test_inter_ou", - "user_type_id": user_type.id, - "company_id": self.company.id, + "code": "inter", + # "user_type_id": user_type.id, + "account_type": "equity", + "company_id": cls.company.id, } ) # Assign the Inter-OU Clearing account to the company - self.company.inter_ou_clearing_account_id = self.inter_ou_account_id.id - self.company.ou_is_self_balanced = True + cls.company.inter_ou_clearing_account_id = cls.inter_ou_account_id.id + cls.company.ou_is_self_balanced = True # Create user2 - self.user2_id = self.res_users_model.with_context( - no_reset_password=True - ).create( + cls.user2_id = cls.res_users_model.with_context(no_reset_password=True).create( { "name": "Test Account User", "login": "user_2", "password": "demo", "email": "example@yourcompany.com", - "company_id": self.company.id, - "company_ids": [(4, self.company.id)], - "operating_unit_ids": [(4, self.b2c.id)], - "groups_id": [(6, 0, [self.grp_acc_manager.id])], + "company_id": cls.company.id, + "company_ids": [(4, cls.company.id)], + "operating_unit_ids": [(4, cls.b2c.id)], + "groups_id": [(6, 0, [cls.grp_acc_manager.id])], } ) # Create a cash account 1 - user_type = self.env.ref("account.data_account_type_liquidity") - self.cash1_account_id = self.account_model.create( + # user_type = cls.env.ref("account.data_account_type_liquidity") + cls.cash1_account_id = cls.account_model.create( { "name": "Cash 1 - Test", - "code": "test_cash_1", - "user_type_id": user_type.id, - "company_id": self.company.id, + "code": "testcash1", + # "user_type_id": user_type.id, + "account_type": "asset_cash", + "company_id": cls.company.id, } ) # Create a journal for cash account 1, associated to the main # operating unit - self.cash_journal_ou1 = self.journal_model.create( + cls.cash_journal_ou1 = cls.journal_model.create( { "name": "Cash Journal 1 - Test", "code": "cash1", "type": "cash", - "company_id": self.company.id, - "default_account_id": self.cash1_account_id.id, - "operating_unit_id": self.ou1.id, + "company_id": cls.company.id, + "default_account_id": cls.cash1_account_id.id, + "operating_unit_id": cls.ou1.id, } ) # Create a cash account 2 - user_type = self.env.ref("account.data_account_type_liquidity") - self.cash2_account_id = self.account_model.create( + # user_type = cls.env.ref("account.data_account_type_liquidity") + cls.cash2_account_id = cls.account_model.create( { "name": "Cash 2 - Test", "code": "cash2", - "user_type_id": user_type.id, - "company_id": self.company.id, + "account_type": "liability_payable", + "company_id": cls.company.id, } ) # Create a journal for cash account 2, associated to the operating # unit B2B - self.cash2_journal_b2b = self.journal_model.create( + cls.cash2_journal_b2b = cls.journal_model.create( { "name": "Cash Journal 2 - Test", - "code": "test_cash_2", + "code": "testcash2", "type": "cash", - "company_id": self.company.id, - "default_account_id": self.cash2_account_id.id, - "operating_unit_id": self.b2b.id, + "company_id": cls.company.id, + "default_account_id": cls.cash2_account_id.id, + "operating_unit_id": cls.b2b.id, } ) @@ -161,7 +162,8 @@ def _prepare_invoice(self, operating_unit_id, name="Test Supplier Invoice"): ] # Prepare invoice lines lines = [] - acc_type = self.env.ref("account.data_account_type_expenses") + # acc_type = self.env.ref("account.data_account_type_expenses") + for product, qty in line_products: line_values = { "name": product.name, @@ -169,8 +171,10 @@ def _prepare_invoice(self, operating_unit_id, name="Test Supplier Invoice"): "quantity": qty, "price_unit": 50, "account_id": self.env["account.account"] - .search([("user_type_id", "=", acc_type.id)], limit=1) + .search([("account_type", "=", "expense")], limit=1) .id, + # Adding this line so the taxes are explicitly excluded from the lines + "tax_ids": [], } lines.append((0, 0, line_values)) inv_vals = { diff --git a/account_operating_unit/tests/test_cross_ou_journal_entry.py b/account_operating_unit/tests/test_cross_ou_journal_entry.py index 1107ce1b44..2ce2fdb1a7 100644 --- a/account_operating_unit/tests/test_cross_ou_journal_entry.py +++ b/account_operating_unit/tests/test_cross_ou_journal_entry.py @@ -11,8 +11,9 @@ @tagged("post_install", "-at_install") class TestCrossOuJournalEntry(test_ou.TestAccountOperatingUnit): - def setUp(self): - super().setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() def _check_balance(self, account_id, acc_type="clearing"): # Check balance for all operating units @@ -93,31 +94,17 @@ def test_cross_ou_journal_entry(self): move_vals.update( {"journal_id": journal_ids and journal_ids.id, "line_ids": lines} ) - move = self.move_model.with_user(self.user_id.id).create(move_vals) + move = ( + self.move_model.with_user(self.user_id.id) + .with_context(check_move_validity=False) + .create(move_vals) + ) # Post journal entries move.action_post() # Check the balance of the account self._check_balance(self.current_asset_account_id.id, acc_type="other") clearing_account_id = self.company.inter_ou_clearing_account_id.id self._check_balance(clearing_account_id, acc_type="clearing") - # Report journal - report_journal = ( - self.env["report.account.report_journal"] - .sudo() - ._get_report_values( - docids=[journal_ids.id], - data={ - "form": { - "journal_ids": journal_ids.ids, - "company_id": journal_ids.company_id, - "used_context": { - "operating_unit_ids": journal_ids.operating_unit_id.id - }, - } - }, - ) - ) - self.assertTrue(report_journal) def test_journal_no_ou(self): """Test journal can not create if use self-balance but not ou in journal""" @@ -125,5 +112,5 @@ def test_journal_no_ou(self): with Form(self.journal_model) as f: f.type = "bank" f.name = "Test new bank not ou" - f.code = "testcode" + f.code = "bankcode" f.save() diff --git a/account_operating_unit/views/account_move_view.xml b/account_operating_unit/views/account_move_view.xml index 0e15d049c0..92b7084206 100644 --- a/account_operating_unit/views/account_move_view.xml +++ b/account_operating_unit/views/account_move_view.xml @@ -32,21 +32,7 @@ - - account.move.line.tree.grouped - account.move.line - - - - - - - + Journal Items account.move.line @@ -57,8 +43,10 @@ name="operating_unit_id" groups="operating_unit.group_multi_operating_unit" /> + + + @@ -80,7 +69,11 @@ options="{'no_create': True}" groups="operating_unit.group_multi_operating_unit" /> + + + + {'default_move_type': context.get('default_move_type'), @@ -90,26 +83,6 @@ 'operating_unit_id': operating_unit_id} - - - ['|', ('company_id', '=', False), ('company_id', '=', - parent.company_id), '|', ('operating_unit_ids', '=', - context.get('operating_unit_id', False)), ('operating_unit_ids', - '=', False)] - - - - - ['|', ('operating_unit_ids', '=', context.get('operating_unit_id', - False)), ('operating_unit_ids', '=', False)] - - { @@ -132,27 +105,27 @@ groups="operating_unit.group_multi_operating_unit" /> - - - ['|', ('company_id', '=', parent.company_id), ('company_id', '=', - False), '|', ('operating_unit_ids', '=', - context.get('default_operating_unit_id', False)), - ('operating_unit_ids', '=', False)] - - - - - ['|', ('operating_unit_ids', '=', - context.get('default_operating_unit_id', False)), - ('operating_unit_ids', '=', False)] - - + + + + + + + + + + + + + + + + + + + + + @@ -167,6 +140,7 @@ optional="show" groups="operating_unit.group_multi_operating_unit" /> + @@ -180,6 +154,7 @@ name="operating_unit_id" groups="operating_unit.group_multi_operating_unit" /> +