From 41a8fccbe831080a4dfab79237b1285462177446 Mon Sep 17 00:00:00 2001 From: Guillaume MASSON Date: Wed, 11 Dec 2024 14:54:40 +0100 Subject: [PATCH] [FIX] account_invoice_inter_company : creating a credit note should generate a supplier refund in the other company Fixes #736 --- .../models/account_move.py | 4 +-- .../tests/test_inter_company_invoice.py | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/account_invoice_inter_company/models/account_move.py b/account_invoice_inter_company/models/account_move.py index bc856fcb224..f9da2ff9c5f 100644 --- a/account_invoice_inter_company/models/account_move.py +++ b/account_invoice_inter_company/models/account_move.py @@ -40,9 +40,9 @@ def _find_company_from_invoice_partner(self): ) return company or False - def action_post(self): + def _post(self, soft=True): """Validated invoice generate cross invoice base on company rules""" - res = super().action_post() + res = super()._post(soft=soft) # Intercompany account entries or receipts aren't supported supported_types = {"out_invoice", "in_invoice", "out_refund", "in_refund"} for src_invoice in self.filtered(lambda x: x.move_type in supported_types): 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 1d9fa690bf7..9c0d3b44f64 100644 --- a/account_invoice_inter_company/tests/test_inter_company_invoice.py +++ b/account_invoice_inter_company/tests/test_inter_company_invoice.py @@ -541,6 +541,31 @@ def _confirm_invoice_with_product(self): self.assertEqual(len(invoices), 1) return invoices + def test_invoice_full_refund(self): + # Confirm the invoice for company A + self.invoice_company_a.with_user(self.user_company_a.id).action_post() + # Open the account move reversal wizard + # We use a form to pass the context properly to the depends_context move_ids field + context = { + "active_model": "account.move", + "active_ids": self.invoice_company_a.ids, + } + with Form( + self.env["account.move.reversal"] + .with_context(**context) + .with_user(self.user_company_a.id) + ) as wizard_form: + wizard_form.refund_method = "cancel" + wizard = wizard_form.save() + # Create the reversal move. + wizard.reverse_moves() + self.assertTrue(wizard.new_move_ids) + self.assertTrue( + self.env["account.move"] + .with_user(self.user_company_b) + .search([("auto_invoice_id", "=", wizard.new_move_ids.id)]) + ) + def test_confirm_invoice_intercompany_disabled(self): # ensure the catalog is shared self.env.ref("product.product_comp_rule").write({"active": False})