diff --git a/account_invoice_inter_company/models/account_move.py b/account_invoice_inter_company/models/account_move.py index 1e74984da6b..9333fecc901 100644 --- a/account_invoice_inter_company/models/account_move.py +++ b/account_invoice_inter_company/models/account_move.py @@ -328,6 +328,8 @@ def write(self, vals): if self.env.context.get("skip_check_amount_difference"): return res for move in self.filtered("auto_invoice_id"): + if not move.company_id.intercompany_invoice_lock: + continue if ( float_compare( move.amount_total, diff --git a/account_invoice_inter_company/models/res_company.py b/account_invoice_inter_company/models/res_company.py index bac93207b77..4ed3c9a6bd3 100644 --- a/account_invoice_inter_company/models/res_company.py +++ b/account_invoice_inter_company/models/res_company.py @@ -17,6 +17,10 @@ class ResCompany(models.Model): "for this company, it will automatically validate it", default=True, ) + intercompany_invoice_lock = fields.Boolean( + help="Don't allow changing an autogenerated invoice.", + default=True, + ) intercompany_invoice_user_id = fields.Many2one( "res.users", string="Inter Company Invoice User", diff --git a/account_invoice_inter_company/models/res_config_settings.py b/account_invoice_inter_company/models/res_config_settings.py index 240d614d512..6704b3d3ed5 100644 --- a/account_invoice_inter_company/models/res_config_settings.py +++ b/account_invoice_inter_company/models/res_config_settings.py @@ -14,6 +14,12 @@ class ResConfigSettings(models.TransientModel): help="When an invoice is created by a multi company rule for " "this company, it will automatically validate it.", ) + intercompany_invoice_lock = fields.Boolean( + related="company_id.intercompany_invoice_lock", + string="Lock auto-generated invoices", + readonly=False, + help="Don't allow changing an autogenerated invoice.", + ) intercompany_invoice_user_id = fields.Many2one( related="company_id.intercompany_invoice_user_id", readonly=False, 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 49e5101c123..455483a8650 100644 --- a/account_invoice_inter_company/tests/test_inter_company_invoice.py +++ b/account_invoice_inter_company/tests/test_inter_company_invoice.py @@ -504,6 +504,12 @@ def test03_confirm_invoice_and_cancel(self): with move_form.invoice_line_ids.edit(0) as line_form: line_form.price_unit = 33.3 move_form.save() + # Check that we can modify it after we disable the setting + dest_invoice.company_id.intercompany_invoice_lock = False + move_form = Form(dest_invoice) + with move_form.invoice_line_ids.edit(0) as line_form: + line_form.price_unit = 33.3 + move_form.save() def test_confirm_invoice_with_child_partner(self): # ensure the catalog is shared 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 94ddeb3cf21..417c9a9ab9f 100644 --- a/account_invoice_inter_company/views/res_config_settings_view.xml +++ b/account_invoice_inter_company/views/res_config_settings_view.xml @@ -66,6 +66,14 @@ for="invoice_auto_validation" /> +
+ +