From 225e3a0804db92b3eb89fd479a39a51af1953209 Mon Sep 17 00:00:00 2001 From: jguenat Date: Mon, 17 Apr 2023 16:02:43 +0200 Subject: [PATCH] [FIX] account_commission: revert settlement in invoiced state to settled when deleting settlement invoice - fix bug when deleting a draft settlement invoice, the settlement is stuck on "invoiced" state --- account_commission/models/account_move.py | 7 +++++++ account_commission/tests/test_account_commission.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/account_commission/models/account_move.py b/account_commission/models/account_move.py index 2c2fae81c..00b863763 100644 --- a/account_commission/models/account_move.py +++ b/account_commission/models/account_move.py @@ -114,6 +114,13 @@ def fields_view_get( res["arch"] = etree.tostring(invoice_xml) return res + def unlink(self): + """Put 'invoiced' settlements associated to the invoices back in settled state.""" + self.invoice_line_ids.settlement_id.filtered( + lambda s: s.state == "invoiced" + ).write({"state": "settled"}) + return super().unlink() + class AccountMoveLine(models.Model): _inherit = [ diff --git a/account_commission/tests/test_account_commission.py b/account_commission/tests/test_account_commission.py index 94652c8f3..13e80609e 100644 --- a/account_commission/tests/test_account_commission.py +++ b/account_commission/tests/test_account_commission.py @@ -454,3 +454,14 @@ def test_account_commission_multiple_settlement_ids(self): settlements.make_invoices(self.journal, self.commission_product, grouped=True) invoices = settlements.mapped("invoice_id") self.assertEqual(2, invoices.settlement_count) + + def test_unlink_settlement_invoice(self): + settlements = self._create_multi_settlements() + invoices = settlements.make_invoices(self.journal, self.commission_product) + self.assertTrue( + all(state == "invoiced" for state in settlements.mapped("state")) + ) + invoices.unlink() + self.assertTrue( + all(state == "settled" for state in settlements.mapped("state")) + )