From af0ad179847ba55c76c2afac11e8a07acc3d0de6 Mon Sep 17 00:00:00 2001 From: sayanthns Date: Fri, 26 Jun 2026 22:50:39 +0300 Subject: [PATCH] fix(dn-consolidation): re-derive DN status on billing revert unmark_consolidated_dns_billed called update_billing_status (recomputes per_billed) but not set_status, so a clubbed DN stayed "Completed" after the consolidated SI was cancelled/deleted instead of reverting to "To Bill". Add dn.set_status(update=True) after the recompute. Caught by the UAT regression test test_clubbed_dn_billing_status_flips_on_submit_and_reverts. Co-Authored-By: Claude Opus 4.8 --- rmax_custom/api/delivery_note.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rmax_custom/api/delivery_note.py b/rmax_custom/api/delivery_note.py index 3026678..248c230 100644 --- a/rmax_custom/api/delivery_note.py +++ b/rmax_custom/api/delivery_note.py @@ -730,7 +730,11 @@ def unmark_consolidated_dns_billed(si_name): ): try: dn = frappe.get_doc("Delivery Note", dn_name) + # update_billing_status recomputes per_billed (→ 0 for a pure net-off + # DN) but does NOT re-derive the status field; set_status must run + # after it or the DN stays stuck on "Completed". dn.update_billing_status(update_modified=False) + dn.set_status(update=True, update_modified=False) except Exception: frappe.db.set_value( "Delivery Note", dn_name,