Skip to content

Commit

Permalink
[FIX] account_commission: revert settlement in invoiced state to sett…
Browse files Browse the repository at this point in the history
…led when deleting settlement invoice

- fix bug when deleting a draft settlement invoice, the settlement is stuck on "invoiced" state
  • Loading branch information
jguenat authored and aleuffre committed Nov 12, 2024
1 parent 99972ba commit 9519e96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sale_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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 = [
Expand Down
16 changes: 16 additions & 0 deletions sale_commission/tests/test_sale_commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,19 @@ def test_payment_date_settlement(self):
)
self.assertEqual(1, len(settlements))
self.assertEqual(1, len(settlements.line_ids))

def test_unlink_settlement_invoice(self):
self._create_order_and_invoice_and_settle(
self.agent_quaterly,
self.env.ref("sale_commission.demo_commission"),
1,
)
settlements = self.settle_model.search([("state", "=", "settled")])
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"))
)

0 comments on commit 9519e96

Please sign in to comment.