Skip to content

Commit

Permalink
[FIX] account_cutoff_accrual_order_base
Browse files Browse the repository at this point in the history
Fix when is_cutoff_accrual_excluded is removed
  • Loading branch information
jbaudoux committed Feb 15, 2024
1 parent 23e3c60 commit 1c9f098
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
3 changes: 2 additions & 1 deletion account_cutoff_accrual_order_base/models/order_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -268,4 +269,4 @@ def write(self, vals):
else:
for rec in self:
rec._update_cutoff_accrual()
return super().write(vals)
return res
76 changes: 76 additions & 0 deletions account_cutoff_accrual_purchase_stock/tests/test_cutoff_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
76 changes: 76 additions & 0 deletions account_cutoff_accrual_sale_stock/tests/test_cutoff_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 1c9f098

Please sign in to comment.