From 47430b38ce2ba6b6809be09c623cf46a03ee083b Mon Sep 17 00:00:00 2001 From: Marina Alapont Date: Thu, 30 May 2024 12:24:52 +0200 Subject: [PATCH] [IMP] account_invoice_inter_company: add setting to disable or enable intercompany invoicing This commit adds a new setting called intercompany_invoicing that allows the user to activate or deactivate the intercompany invoicing. When positing an intercompany invoice, if one of the companies have the setting disabled, the other invoice will not be automatically created. --- account_invoice_inter_company/README.rst | 2 +- .../models/account_move.py | 6 ++++++ .../models/res_company.py | 8 ++++++++ .../models/res_config_settings.py | 10 ++++++++++ .../readme/CONFIGURE.rst | 2 +- .../static/description/index.html | 14 ++++++++------ .../tests/test_inter_company_invoice.py | 15 +++++++++++++++ .../views/res_config_settings_view.xml | 18 ++++++++++++++++-- 8 files changed, 65 insertions(+), 10 deletions(-) diff --git a/account_invoice_inter_company/README.rst b/account_invoice_inter_company/README.rst index de0c18388ac..67c98864a79 100644 --- a/account_invoice_inter_company/README.rst +++ b/account_invoice_inter_company/README.rst @@ -45,7 +45,7 @@ Configuration To configure this module, you need to go to the menu *Settings > General Settings*, go to the tab *Multi-Companies* then check *Multi-companies* -You now have access to other checks *Common Product Catalog* and *Invoice Auto Validation*. +You now have access to other checks *Common Product Catalog*, *Generate Intercompany Invoices* and *Invoice Auto Validation*. To customize products sharing don't hesitate to override `_compute_share_product()` in `res.company` model. diff --git a/account_invoice_inter_company/models/account_move.py b/account_invoice_inter_company/models/account_move.py index ca3ffe2f303..1e74984da6b 100644 --- a/account_invoice_inter_company/models/account_move.py +++ b/account_invoice_inter_company/models/account_move.py @@ -82,6 +82,12 @@ def create_counterpart_invoices(self): # nor the invoices that were already validated in the past dest_company = src_invoice._find_company_from_invoice_partner() if dest_company: + # If one of the involved companies have the intercompany setting disabled, skip + if ( + not dest_company.intercompany_invoicing + or not src_invoice.company_id.intercompany_invoicing + ): + continue intercompany_user = dest_company.intercompany_invoice_user_id if intercompany_user: src_invoice = src_invoice.with_user(intercompany_user).sudo() diff --git a/account_invoice_inter_company/models/res_company.py b/account_invoice_inter_company/models/res_company.py index 89a148501ce..bac93207b77 100644 --- a/account_invoice_inter_company/models/res_company.py +++ b/account_invoice_inter_company/models/res_company.py @@ -23,6 +23,14 @@ class ResCompany(models.Model): help="Responsible user for creation of invoices triggered by " "intercompany rules.", ) + intercompany_invoicing = fields.Boolean( + string="Generate Inter company Invoices", + help="Enable intercompany invoicing: " + "\n* Generate a Customer Invoice when a bill with this company is created." + "\n* Generate a Vendor Bill when an invoice with this company as a customer" + " is created.", + default=True, + ) def _compute_share_product(self): product_rule = self.env.ref("product.product_comp_rule") diff --git a/account_invoice_inter_company/models/res_config_settings.py b/account_invoice_inter_company/models/res_config_settings.py index 8d328a90f02..240d614d512 100644 --- a/account_invoice_inter_company/models/res_config_settings.py +++ b/account_invoice_inter_company/models/res_config_settings.py @@ -31,6 +31,16 @@ class ResConfigSettings(models.TransientModel): "company are visible for all companies.", ) + intercompany_invoicing = fields.Boolean( + string="Generate Inter company Invoices", + related="company_id.intercompany_invoicing", + help="Enable intercompany invoicing: " + "\n * Generate a Customer Invoice when a bill with this company is created." + "\n * Generate a Vendor Bill when an invoice with this company as a customer" + " is created.", + readonly=False, + ) + @api.model def get_values(self): res = super(ResConfigSettings, self).get_values() diff --git a/account_invoice_inter_company/readme/CONFIGURE.rst b/account_invoice_inter_company/readme/CONFIGURE.rst index bf03782170c..cbd47393f92 100644 --- a/account_invoice_inter_company/readme/CONFIGURE.rst +++ b/account_invoice_inter_company/readme/CONFIGURE.rst @@ -1,5 +1,5 @@ To configure this module, you need to go to the menu *Settings > General Settings*, go to the tab *Multi-Companies* then check *Multi-companies* -You now have access to other checks *Common Product Catalog* and *Invoice Auto Validation*. +You now have access to other checks *Common Product Catalog*, *Generate Intercompany Invoices* and *Invoice Auto Validation*. To customize products sharing don't hesitate to override `_compute_share_product()` in `res.company` model. diff --git a/account_invoice_inter_company/static/description/index.html b/account_invoice_inter_company/static/description/index.html index ac4836eb925..f87387df84d 100644 --- a/account_invoice_inter_company/static/description/index.html +++ b/account_invoice_inter_company/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -392,7 +392,7 @@

Inter Company Invoices

Configuration

To configure this module, you need to go to the menu Settings > General Settings, go to the tab Multi-Companies then check Multi-companies

-

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

+

You now have access to other checks Common Product Catalog, Generate Intercompany Invoices and Invoice Auto Validation.

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

@@ -458,7 +458,9 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

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 41cc70605e5..49e5101c123 100644 --- a/account_invoice_inter_company/tests/test_inter_company_invoice.py +++ b/account_invoice_inter_company/tests/test_inter_company_invoice.py @@ -30,6 +30,7 @@ def setUpClass(cls): "country_id": cls.env.ref("base.fr").id, "parent_id": cls.env.ref("base.main_company").id, "invoice_auto_validation": True, + "intercompany_invoicing": True, } ) cls.chart.try_loading(cls.company_a) @@ -41,6 +42,7 @@ def setUpClass(cls): "country_id": cls.env.ref("base.fr").id, "parent_id": cls.env.ref("base.main_company").id, "invoice_auto_validation": True, + "intercompany_invoicing": True, } ) cls.chart.try_loading(cls.company_b) @@ -627,3 +629,16 @@ def test_confirm_invoice_and_full_refund(self): [("auto_invoice_id", "=", refund_company_a.id)] ) self.assertEqual(len(refund), 1) + + def test_confirm_invoice_intercompany_disabled(self): + # ensure the catalog is shared + self.env.ref("product.product_comp_rule").write({"active": False}) + # Disable the configuration in company A + self.company_a.intercompany_invoicing = False + # Confirm the invoice of company A + self.invoice_company_a.with_user(self.user_company_a.id).action_post() + # Check that no destination invoice has been created in company B + invoices = self.account_move_obj.with_user(self.user_company_b.id).search( + [("auto_invoice_id", "=", self.invoice_company_a.id)] + ) + self.assertFalse(invoices) 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 bcfbae3e3ae..94ddeb3cf21 100644 --- a/account_invoice_inter_company/views/res_config_settings_view.xml +++ b/account_invoice_inter_company/views/res_config_settings_view.xml @@ -33,7 +33,18 @@
Invoicing
-
+
+ +
+
-
+