intent: a deleted payment gives its allocation back (#7061) - #7064
Merged
Conversation
A settlement bound its allocation to the payment's create, correction and re-key moments but not to its DELETE, and nothing else could take the junction rows with the payment: the FK to it never becomes a database constraint on this platform, so there is no cascade, and when the payment is cross-model its owner knows nothing of this settlement and does not own the rows. Deleting a CustomerPayment therefore left its SalesInvoiceCustomerPayment rows behind as orphans pointing at an id that no longer existed, and the invoice stayed PAID with a zero balance forever - the path a user actually takes to reverse a payment. #7016 / #7022 fixed the relinquish for a deleted ALLOCATION row; this binds the moment that reaches it. The settlements generator now emits a cleanup handler per settlement, <Name>OnPaymentDeleted, on the payment's -deleted topic. It deletes every junction row of that payment through the generated junction repository, so each row's delete event fires and the paid roll-up recomputes the invoice's paid / balance / status exactly as for a hand-deleted allocation. Unlike the re-key handler it needs no payment repository - only the key off the delete payload - so it is emitted for a cross-model payment too. The payment-side roll-ups are unaffected: their parent is gone, and the handler returns on a null parent. Fixes #7061 Co-Authored-By: Claude Opus 5 <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.
The defect
A
settlements:block bound the allocation to the payment's create, correction and re-key moments - but not to its delete. Nothing else takes the junction rows with the payment: the junction's FK to it never becomes a database constraint on this platform (referential integrity is a business-layer check), so there is no cascade, and when the payment is cross-model its owner model knows nothing of this settlement and does not own the rows.So deleting a
CustomerPayment(the path a user actually takes to reverse one) left itsSalesInvoiceCustomerPaymentrows behind as orphans pointing at an id that no longer existed, the invoice stayed PAID with a zero balance forever, and the payments panel rendered the orphan as a bare id. #7016 / #7022 modelled the same QA scenario as deleting the allocation and fixed that path; the moment that reaches it was never bound.The fix
buildSettlementCleanupsemits one handler per settlement -<Name>OnPaymentDeleted, rendered from a newSettlementCleanup.java.templateon thesettlementCleanupsglue collection - bound to the payment's-deletedtopic. It deletes every junction row of that payment through the generated junction repository, so each row's delete event fires and thepaidroll-up recomputes the invoice's paid / balance / status exactly as for a hand-deleted allocation, relinquishing PAID / PARTIAL via the #7022 path.Notes on the shape:
-updatedre-fire and no re-allocation.settlements:generates byte-identically.Tests
GlueSettlementRekeyTest- the cleanup entry exists on-deletedwith the expected class name, and still exists for a cross-model payment (unlike the re-key listener).IntentEngineIT#settlement_generates_on_payment_listener_and_on_invoice_delegate- the renderedAutoSettleOnPaymentDeleted.javabinds<project>-Payment-Payment-deletedand deletes the payment's rows through the junction repository. Run locally: green.mvn testonengine-intent+ide-template: 1071 tests, 0 failures.formatter:validateand therelease-profile javadoc pass on both modules.Docs: the
settlementssection of the DSL reference on dirigible.io (companion PR).Fixes #7061