From 67f8aefa61ca3569713eb5c9ce6a79651c27612f Mon Sep 17 00:00:00 2001 From: "Cuong, Nguyen Minh Tran Manh" Date: Fri, 15 Mar 2024 18:01:09 +0700 Subject: [PATCH] [MIG] account_invoice_inter_company: Migration to 17.0 --- account_invoice_inter_company/README.rst | 7 +- account_invoice_inter_company/__manifest__.py | 2 +- .../models/account_move.py | 2 - .../models/res_company.py | 16 --- .../models/res_config_settings.py | 26 +--- .../readme/CONFIGURE.md | 2 +- .../readme/CONTRIBUTORS.md | 2 + .../static/description/index.html | 8 +- .../tests/test_inter_company_invoice.py | 113 +++++++++++------- .../views/res_config_settings_view.xml | 73 +++-------- 10 files changed, 103 insertions(+), 148 deletions(-) diff --git a/account_invoice_inter_company/README.rst b/account_invoice_inter_company/README.rst index 38f89af8dc1..2006cff2750 100644 --- a/account_invoice_inter_company/README.rst +++ b/account_invoice_inter_company/README.rst @@ -50,8 +50,8 @@ Configuration To configure this module, you need to go to the menu *Settings > General Settings*, go to the tab *Companies / Inter Company OCA features* -You now have access to other checks *Common Product Catalog* and -*Invoice Auto Validation*. +You now have access to other options *Intercompany user for invoices* +and *Invoice Auto Validation*. To customize products sharing don't hesitate to override \_compute_share_product() in res.company model. @@ -106,6 +106,9 @@ Contributors - Pedro M. Baeza - Isaac Gallart +- \`Komit \`: + + - Cuong Nguyen Mtm Maintainers ----------- diff --git a/account_invoice_inter_company/__manifest__.py b/account_invoice_inter_company/__manifest__.py index d18d089efed..c01f677ec0c 100644 --- a/account_invoice_inter_company/__manifest__.py +++ b/account_invoice_inter_company/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Inter Company Invoices", "summary": "Intercompany invoice rules", - "version": "16.0.1.0.2", + "version": "17.0.1.0.0", "category": "Accounting & Finance", "website": "https://github.com/OCA/multi-company", "author": "Odoo SA, Akretion, Odoo Community Association (OCA)", diff --git a/account_invoice_inter_company/models/account_move.py b/account_invoice_inter_company/models/account_move.py index 766ed38328b..274940dd606 100644 --- a/account_invoice_inter_company/models/account_move.py +++ b/account_invoice_inter_company/models/account_move.py @@ -62,8 +62,6 @@ def action_post(self): def _check_intercompany_product(self, dest_company): self.ensure_one() - if dest_company.company_share_product: - return domain = dest_company._get_user_domain() dest_user = self.env["res.users"].search(domain, limit=1) for line in self.invoice_line_ids: diff --git a/account_invoice_inter_company/models/res_company.py b/account_invoice_inter_company/models/res_company.py index f1a2c0e6d10..fba6085e4f8 100644 --- a/account_invoice_inter_company/models/res_company.py +++ b/account_invoice_inter_company/models/res_company.py @@ -6,17 +6,6 @@ class ResCompany(models.Model): _inherit = "res.company" - company_share_product = fields.Boolean( - "Share product to all companies", - compute="_compute_share_product", - compute_sudo=True, - help="Share your product to all companies defined in your instance.\n" - " * Checked : Product are visible for every company, " - "even if a company is defined on the partner.\n" - " * Unchecked : Each company can see only its product " - "(product where company is defined). Product not related to a " - "company are visible for all companies.", - ) invoice_auto_validation = fields.Boolean( help="When an invoice is created by a multi company rule " "for this company, it will automatically validate it", @@ -29,11 +18,6 @@ class ResCompany(models.Model): "intercompany rules.", ) - def _compute_share_product(self): - product_rule = self.env.ref("product.product_comp_rule") - for company in self: - company.company_share_product = not bool(product_rule.active) - def _get_user_domain(self): self.ensure_one() group_account_invoice = self.env.ref("account.group_account_invoice") diff --git a/account_invoice_inter_company/models/res_config_settings.py b/account_invoice_inter_company/models/res_config_settings.py index 0488a311362..3f8e06784d2 100644 --- a/account_invoice_inter_company/models/res_config_settings.py +++ b/account_invoice_inter_company/models/res_config_settings.py @@ -1,6 +1,6 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class ResConfigSettings(models.TransientModel): @@ -20,27 +20,3 @@ class ResConfigSettings(models.TransientModel): "intercompany rules. If not set the user initiating the" "transaction will be used", ) - company_share_product = fields.Boolean( - "Share product to all companies", - help="Share your product to all companies defined in your instance.\n" - " * Checked : Product are visible for every company, " - "even if a company is defined on the partner.\n" - " * Unchecked : Each company can see only its product " - "(product where company is defined). Product not related to a " - "company are visible for all companies.", - ) - - @api.model - def get_values(self): - res = super().get_values() - product_rule = self.env.ref("product.product_comp_rule") - res.update( - company_share_product=not bool(product_rule.active), - ) - return res - - def set_values(self): - res = super().set_values() - product_rule = self.env.ref("product.product_comp_rule") - product_rule.write({"active": not bool(self.company_share_product)}) - return res diff --git a/account_invoice_inter_company/readme/CONFIGURE.md b/account_invoice_inter_company/readme/CONFIGURE.md index 2508934e770..62e6f69d2c2 100644 --- a/account_invoice_inter_company/readme/CONFIGURE.md +++ b/account_invoice_inter_company/readme/CONFIGURE.md @@ -2,7 +2,7 @@ To configure this module, you need to go to the menu *Settings \> General Settings*, go to the tab *Companies / Inter Company OCA features* -You now have access to other checks *Common Product Catalog* and +You now have access to other options *Intercompany user for invoices* and *Invoice Auto Validation*. To customize products sharing don't hesitate to override diff --git a/account_invoice_inter_company/readme/CONTRIBUTORS.md b/account_invoice_inter_company/readme/CONTRIBUTORS.md index 9b1b5f303cc..2bf8eb3b5f7 100644 --- a/account_invoice_inter_company/readme/CONTRIBUTORS.md +++ b/account_invoice_inter_company/readme/CONTRIBUTORS.md @@ -11,3 +11,5 @@ - David Vidal - Pedro M. Baeza - Isaac Gallart \<\> +- \`Komit \<\>\`: + - Cuong Nguyen Mtm \<\> diff --git a/account_invoice_inter_company/static/description/index.html b/account_invoice_inter_company/static/description/index.html index 8db7de61c1f..3f9f4e55dd3 100644 --- a/account_invoice_inter_company/static/description/index.html +++ b/account_invoice_inter_company/static/description/index.html @@ -397,8 +397,8 @@

Inter Company Invoices

Configuration

To configure this module, you need to go to the menu Settings > General Settings, go to the tab Companies / Inter Company OCA features

-

You now have access to other checks Common Product Catalog and -Invoice Auto Validation.

+

You now have access to other options Intercompany user for invoices +and Invoice Auto Validation.

To customize products sharing don’t hesitate to override _compute_share_product() in res.company model.

@@ -453,6 +453,10 @@

Contributors

  • Isaac Gallart <igallart@puntsistemes.es>
  • +
  • `Komit <https://komit-consulting.com>`: +
  • diff --git a/account_invoice_inter_company/tests/test_inter_company_invoice.py b/account_invoice_inter_company/tests/test_inter_company_invoice.py index 2e4e5cb3563..13940765e73 100644 --- a/account_invoice_inter_company/tests/test_inter_company_invoice.py +++ b/account_invoice_inter_company/tests/test_inter_company_invoice.py @@ -3,36 +3,60 @@ # Copyright 2020 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import _ -from odoo.exceptions import UserError, ValidationError +from unittest.mock import patch + +from odoo.exceptions import UserError from odoo.tests import tagged from odoo.tests.common import Form, TransactionCase +from odoo.addons.account.models.chart_template import AccountChartTemplate +from odoo.addons.account.tests.test_chart_template import test_get_data + + +def _get_chart_template_mapping(self, get_all=False): + return { + "test": { + "name": "test", + "country_id": None, + "country_code": None, + "modules": ["account"], + "parent": None, + } + } + @tagged("post_install", "-at_install") +@patch.object( + AccountChartTemplate, "_get_chart_template_mapping", _get_chart_template_mapping +) class TestAccountInvoiceInterCompanyBase(TransactionCase): @classmethod + @patch.object( + AccountChartTemplate, "_get_chart_template_mapping", _get_chart_template_mapping + ) def setUpClass(cls): super().setUpClass() cls.account_obj = cls.env["account.account"] cls.account_move_obj = cls.env["account.move"] - cls.chart = cls.env["account.chart.template"].search([], limit=1) - if not cls.chart: - raise ValidationError( - # translation to avoid pylint warnings - _("No Chart of Account Template has been defined !") - ) cls.company_a = cls.env["res.company"].create( { "name": "Company A", "currency_id": cls.env.ref("base.EUR").id, "country_id": cls.env.ref("base.fr").id, - "parent_id": cls.env.ref("base.main_company").id, + # "parent_id": cls.env.ref("base.main_company").id, "invoice_auto_validation": True, } ) - cls.chart.try_loading(company=cls.company_a, install_demo=False) + with patch.object( + AccountChartTemplate, + "_get_chart_template_data", + side_effect=test_get_data, + autospec=True, + ): + cls.env["account.chart.template"].try_loading( + "test", company=cls.company_a, install_demo=False + ) cls.partner_company_a = cls.env["res.partner"].create( {"name": cls.company_a.name, "is_company": True} ) @@ -42,11 +66,19 @@ def setUpClass(cls): "name": "Company B", "currency_id": cls.env.ref("base.EUR").id, "country_id": cls.env.ref("base.fr").id, - "parent_id": cls.env.ref("base.main_company").id, + # "parent_id": cls.env.ref("base.main_company").id, "invoice_auto_validation": True, } ) - cls.chart.try_loading(company=cls.company_b, install_demo=False) + with patch.object( + AccountChartTemplate, + "_get_chart_template_data", + side_effect=test_get_data, + autospec=True, + ): + cls.env["account.chart.template"].try_loading( + "test", company=cls.company_b, install_demo=False + ) cls.partner_company_b = cls.env["res.partner"].create( {"name": cls.company_b.name, "is_company": True} ) @@ -332,15 +364,6 @@ def setUpClass(cls): "company_id": cls.company_a.id, } ) - cls.pcg_X58 = cls.env["account.account.template"].create( - { - "name": "Internal Transfers", - "code": "X58", - "account_type": "asset_current", - "reconcile": True, - } - ) - cls.a_recv_company_a = cls.account_obj.create( { "code": "X11002.A", @@ -363,8 +386,18 @@ def setUpClass(cls): cls.partner_company_a.property_account_receivable_id = cls.a_recv_company_a.id cls.partner_company_a.property_account_payable_id = cls.a_pay_company_a.id - cls.partner_company_b.property_account_receivable_id = cls.a_recv_company_b.id - cls.partner_company_b.property_account_payable_id = cls.a_pay_company_b.id + cls.partner_company_b.with_user( + cls.user_company_a.id + ).property_account_receivable_id = cls.a_recv_company_a.id + cls.partner_company_b.with_user( + cls.user_company_a.id + ).property_account_payable_id = cls.a_pay_company_a.id + cls.partner_company_b.with_user( + cls.user_company_b.id + ).property_account_receivable_id = cls.a_recv_company_b.id + cls.partner_company_b.with_user( + cls.user_company_b.id + ).property_account_payable_id = cls.a_pay_company_b.id cls.invoice_company_a = Form( cls.account_move_obj.with_user(cls.user_company_a.id).with_context( @@ -390,7 +423,7 @@ def setUpClass(cls): cls.product_a = cls.invoice_line_a.product_id cls.product_a.with_user( cls.user_company_b.id - ).property_account_expense_id = cls.a_expense_company_b.id + ).sudo().property_account_expense_id = cls.a_expense_company_b.id class TestAccountInvoiceInterCompany(TestAccountInvoiceInterCompanyBase): @@ -415,7 +448,9 @@ def test03_confirm_invoice_and_cancel(self): # ensure the catalog is shared self.env.ref("product.product_comp_rule").write({"active": False}) # Make sure there are no taxes in target company for the used product - self.product_a.with_user(self.user_company_b.id).supplier_taxes_id = False + self.product_a.with_user( + self.user_company_b.id + ).sudo().supplier_taxes_id = False # Confirm the invoice of company A self.invoice_company_a.with_user(self.user_company_a.id).action_post() # Check destination invoice created in company B @@ -443,9 +478,9 @@ def test03_confirm_invoice_and_cancel(self): self.invoice_company_a.invoice_line_ids[0].product_id, ) # Cancel the invoice of company A - invoice_origin = ("%s - Canceled Invoice: %s") % ( - self.invoice_company_a.company_id.name, - self.invoice_company_a.name, + invoice_origin = "{company_name} - Canceled Invoice: {invoice_name}".format( + company_name=self.invoice_company_a.company_id.name, + invoice_name=self.invoice_company_a.name, ) self.invoice_company_a.with_user(self.user_company_a.id).button_cancel() # Check invoices after to cancel invoice of company A @@ -454,6 +489,7 @@ def test03_confirm_invoice_and_cancel(self): self.assertEqual(invoices[0].invoice_origin, invoice_origin) # Check if keep the invoice number invoice_number = self.invoice_company_a.name + self.invoice_company_a.with_user(self.user_company_a.id).button_draft() self.invoice_company_a.with_user(self.user_company_a.id).action_post() self.assertEqual(self.invoice_company_a.name, invoice_number) # When the destination invoice is posted we can't modify the origin either @@ -484,19 +520,6 @@ def test_confirm_invoice_with_child_partner(self): ) self.assertEqual(len(invoices), 1) - def test_confirm_invoice_with_product_and_shared_catalog(self): - """With no security rule, child company have access to any product. - Then child invoice can share the same product - """ - # ensure the catalog is shared even if product is in other company - self.env.ref("product.product_comp_rule").write({"active": False}) - # Product is set to a specific company - self.product_a.write({"company_id": self.company_a.id}) - invoices = self._confirm_invoice_with_product() - self.assertNotEqual( - invoices.invoice_line_ids[0].product_id, self.env["product.product"] - ) - def test_confirm_invoice_with_native_product_rule_and_shared_product(self): """With native security rule, products with access in both companies must be present in parent and child invoices. @@ -504,10 +527,10 @@ def test_confirm_invoice_with_native_product_rule_and_shared_product(self): # ensure the catalog is shared even if product is in other company self.env.ref("product.product_comp_rule").write({"active": True}) # Product is set to a specific company - self.product_a.write({"company_id": False}) + self.product_a.sudo().write({"company_id": False}) # If product_multi_company is installed if "company_ids" in dir(self.product_a): - self.product_a.write({"company_ids": [(5, 0, 0)]}) + self.product_a.sudo().write({"company_ids": [(5, 0, 0)]}) invoices = self._confirm_invoice_with_product() self.assertEqual(invoices.invoice_line_ids[0].product_id, self.product_a) @@ -518,10 +541,10 @@ def test_confirm_invoice_with_native_product_rule_and_unshared_product(self): # ensure the catalog is shared even if product is in other company self.env.ref("product.product_comp_rule").write({"active": True}) # Product is set to a specific company - self.product_a.write({"company_id": self.company_a.id}) + self.product_a.sudo().write({"company_id": self.company_a.id}) # If product_multi_company is installed if "company_ids" in dir(self.product_a): - self.product_a.write({"company_ids": [(6, 0, [self.company_a.id])]}) + self.product_a.sudo().write({"company_ids": [(6, 0, [self.company_a.id])]}) with self.assertRaises(UserError): self._confirm_invoice_with_product() diff --git a/account_invoice_inter_company/views/res_config_settings_view.xml b/account_invoice_inter_company/views/res_config_settings_view.xml index 4dd7c2e34b5..65cbcfad16f 100644 --- a/account_invoice_inter_company/views/res_config_settings_view.xml +++ b/account_invoice_inter_company/views/res_config_settings_view.xml @@ -4,74 +4,39 @@ res.config.settings - - + + 1 - -
    Inter Company OCA features - -
    -
    - -
    - -
    -
    - -
    -
    -
    -
    Invoicing
    -
    + + +
    Invoice
    +
    +
    -
    - +
    -
    -
    - - {'invisible': True} - - - {'invisible': True} - - - {'invisible': True} +