From 1c9f098cef405fccee79f6ac17365be722d36c11 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Thu, 15 Feb 2024 14:52:59 +0100 Subject: [PATCH] [FIX] account_cutoff_accrual_order_base Fix when is_cutoff_accrual_excluded is removed --- .../models/order_line_mixin.py | 3 +- .../tests/test_cutoff_expense.py | 76 +++++++++++++++++++ .../tests/test_cutoff_revenue.py | 76 +++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) diff --git a/account_cutoff_accrual_order_base/models/order_line_mixin.py b/account_cutoff_accrual_order_base/models/order_line_mixin.py index c410c264557..323abaa469e 100644 --- a/account_cutoff_accrual_order_base/models/order_line_mixin.py +++ b/account_cutoff_accrual_order_base/models/order_line_mixin.py @@ -260,6 +260,7 @@ def _update_cutoff_accrual(self, date=False): self.env["account.cutoff.line"].create(values) def write(self, vals): + res = super().write(vals) if "is_cutoff_accrual_excluded" in vals: if vals["is_cutoff_accrual_excluded"]: self.account_cutoff_line_ids.filtered( @@ -268,4 +269,4 @@ def write(self, vals): else: for rec in self: rec._update_cutoff_accrual() - return super().write(vals) + return res diff --git a/account_cutoff_accrual_purchase_stock/tests/test_cutoff_expense.py b/account_cutoff_accrual_purchase_stock/tests/test_cutoff_expense.py index 7051b4b878b..073901f810d 100644 --- a/account_cutoff_accrual_purchase_stock/tests/test_cutoff_expense.py +++ b/account_cutoff_accrual_purchase_stock/tests/test_cutoff_expense.py @@ -251,3 +251,79 @@ def test_accrued_expense_on_po_all_invoiced_after_cutoff(self): self.assertEqual( line.cutoff_amount, -100 * 2 * 2, "PO line cutoff amount incorrect" ) + + def test_accrued_expense_on_po_force_invoiced_after(self): + """Test cutoff when PO is force invoiced after cutoff""" + cutoff = self.expense_cutoff + self._confirm_po_and_do_picking(2) + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + # Force invoiced after cutoff lines generated, lines should be deleted + self.po.force_invoiced = True + self.assertEqual(len(cutoff.line_ids), 0, "cutoff line should deleted") + # Remove Force invoiced, lines should be recreated + self.po.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + + def test_accrued_expense_on_po_force_invoiced_before(self): + """Test cutoff when PO is force invoiced before cutoff""" + cutoff = self.expense_cutoff + self._confirm_po_and_do_picking(2) + # Force invoiced before cutoff lines generated, lines should be deleted + self.po.force_invoiced = True + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated") + # Remove Force invoiced, lines should be created + self.po.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + + def test_accrued_expense_on_po_force_invoiced_after_but_posted(self): + """Test cutoff when PO is force invoiced after closed cutoff""" + cutoff = self.expense_cutoff + self._confirm_po_and_do_picking(2) + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + cutoff.state = "done" + # Force invoiced after cutoff lines generated, cutoff is posted + self.po.force_invoiced = True + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + # Remove Force invoiced, nothing changes + self.po.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, -100 * 2, "PO line cutoff amount incorrect" + ) + + def test_accrued_expense_on_po_force_invoiced_before_but_posted(self): + """Test cutoff when PO is force invoiced before closed cutoff""" + cutoff = self.expense_cutoff + self._confirm_po_and_do_picking(2) + # Force invoiced before cutoff lines generated, lines should be deleted + self.po.force_invoiced = True + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated") + cutoff.state = "done" + # Remove Force invoiced, lines should be created + self.po.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated") diff --git a/account_cutoff_accrual_sale_stock/tests/test_cutoff_revenue.py b/account_cutoff_accrual_sale_stock/tests/test_cutoff_revenue.py index 43d90241c75..504e4603279 100644 --- a/account_cutoff_accrual_sale_stock/tests/test_cutoff_revenue.py +++ b/account_cutoff_accrual_sale_stock/tests/test_cutoff_revenue.py @@ -176,3 +176,79 @@ def test_accrued_revenue_on_so_all_invoiced_after_cutoff(self): self.assertEqual( line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" ) + + def test_accrued_revenue_on_so_force_invoiced_after(self): + """Test cutoff when SO is force invoiced after cutoff""" + cutoff = self.revenue_cutoff + self._confirm_so_and_do_picking(2) + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + # Force invoiced after cutoff lines generated, lines should be deleted + self.so.force_invoiced = True + self.assertEqual(len(cutoff.line_ids), 0, "cutoff line should deleted") + # Remove Force invoiced, lines should be recreated + self.so.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + + def test_accrued_revenue_on_so_force_invoiced_before(self): + """Test cutoff when SO is force invoiced before cutoff""" + cutoff = self.revenue_cutoff + self._confirm_so_and_do_picking(2) + # Force invoiced before cutoff lines generated, lines should be deleted + self.so.force_invoiced = True + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated") + # Remove Force invoiced, lines should be created + self.so.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + + def test_accrued_revenue_on_so_force_invoiced_after_but_posted(self): + """Test cutoff when SO is force invoiced after closed cutoff""" + cutoff = self.revenue_cutoff + self._confirm_so_and_do_picking(2) + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + cutoff.state = "done" + # Force invoiced after cutoff lines generated, cutoff is posted + self.so.force_invoiced = True + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + # Remove Force invoiced, nothing changes + self.so.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 2, "2 cutoff lines should be found") + for line in cutoff.line_ids: + self.assertEqual( + line.cutoff_amount, 100 * 2, "SO line cutoff amount incorrect" + ) + + def test_accrued_revenue_on_so_force_invoiced_before_but_posted(self): + """Test cutoff when SO is force invoiced before closed cutoff""" + cutoff = self.revenue_cutoff + self._confirm_so_and_do_picking(2) + # Force invoiced before cutoff lines generated, lines should be deleted + self.so.force_invoiced = True + cutoff.get_lines() + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated") + cutoff.state = "done" + # Remove Force invoiced, lines should be created + self.so.force_invoiced = False + self.assertEqual(len(cutoff.line_ids), 0, "no cutoff line should be generated")