fix: clear custom_consolidated_si on SI on_trash (draft consolidated SI delete)#24
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_sistamps each DN withcustom_consolidated_si(Link → Sales Invoice). Frappe'scheck_if_doc_is_linkedscans all Link fields and blocks delete. The clear logic was only on SIon_cancel(submitted path); draft delete had no handler. Consolidation omits the standardSI Item.delivery_note(net-off), so the dashboard shows nothing.Fix
clear_consolidated_si_links(si)helper +sales_invoice_on_trash_clear_consolidatedwired to SIon_trash(runs before the link check indelete_doc).