Skip to content

fix: clear custom_consolidated_si on SI on_trash (draft consolidated SI delete)#24

Merged
sayanthns merged 1 commit into
mainfrom
fix/consolidated-si-on-trash
Jun 26, 2026
Merged

fix: clear custom_consolidated_si on SI on_trash (draft consolidated SI delete)#24
sayanthns merged 1 commit into
mainfrom
fix/consolidated-si-on-trash

Conversation

@sayanthns

Copy link
Copy Markdown
Contributor

Problem

A DRAFT consolidated Sales Invoice cannot be deleted — Cannot delete or cancel ... is linked with Delivery Note ... — even though Connections shows no link.

Cause

consolidate_dns_to_si stamps each DN with custom_consolidated_si (Link → Sales Invoice). Frappe's check_if_doc_is_linked scans all Link fields and blocks delete. The clear logic was only on SI on_cancel (submitted path); draft delete had no handler. Consolidation omits the standard SI Item.delivery_note (net-off), so the dashboard shows nothing.

Fix

  • New clear_consolidated_si_links(si) helper + sales_invoice_on_trash_clear_consolidated wired to SI on_trash (runs before the link check in delete_doc).
  • on_cancel refactored to reuse the helper (DRY).
  • No-op for non-consolidated SIs. No schema change → no migrate. Regression test added.

A consolidated Sales Invoice (consolidate_dns_to_si) stamps each source
Delivery Note with custom_consolidated_si = <SI>. That Link field makes
Frappe's link-integrity check block delete/cancel of the SI.

The clearing logic was wired only to Sales Invoice on_cancel (submitted →
cancelled). A DRAFT consolidated SI is *deleted*, not cancelled, so nothing
cleared the stamp → "Cannot delete or cancel ... is linked with Delivery
Note ...", even though the standard Connections dashboard shows no link
(consolidation deliberately omits SI Item.delivery_note for net-off).

Fix: add Sales Invoice on_trash → clear_consolidated_si_links(). on_trash runs
before check_if_doc_is_linked in frappe.delete_doc (v15), so the link check
then passes. Extracted the clear loop into a shared helper and reused it from
the existing on_cancel path (DRY). No-op for non-consolidated SIs. No schema
change. Adds a draft-delete regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sayanthns sayanthns merged commit a7729d5 into main Jun 26, 2026
1 of 3 checks passed
@sayanthns sayanthns deleted the fix/consolidated-si-on-trash branch June 26, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant