fix(payment_djomy): auto-cancel zombie draft/pending transactions on retry#1
Open
founet wants to merge 1 commit into
Open
fix(payment_djomy): auto-cancel zombie draft/pending transactions on retry#1founet wants to merge 1 commit into
founet wants to merge 1 commit into
Conversation
…retry
When a customer abandons a payment (browser closed, network timeout, IPN
lost on Djomy side), the previous transaction stays attached to the sale
order / invoice in `draft` or `pending` state. This blocks the portal UX:
the customer cannot retry from the portal because the orphan draft
transaction remains visible and active.
This change overrides `payment.transaction.create()` to auto-cancel
previous Djomy `draft`/`pending` transactions attached to the same SO /
invoice when a new one is created. Strict guards:
- Final states (done, cancel, error) are preserved.
- Other providers' transactions are untouched (provider_code='djomy'
scope is enforced).
- Stale draft `account.payment` records linked to the cancelled tx are
also cancelled (so the invoice doesn't keep a polluting orphan draft).
An audit note is posted on the sale order / invoice chatter — not in the
transaction `state_message`, which would be rendered on the customer
portal and surface internal cleanup details to the end user.
8 TransactionCase tests cover the nominal cases, the guards (done /
cancel / error / other provider / other SO untouched), and the
account.payment cleanup.
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
When a customer abandons a payment (browser closed, network timeout, IPN lost on Djomy side), the previous transaction stays attached to the sale order / invoice in
draftorpendingstate. This blocks the portal UX: the customer cannot retry from the portal because the orphan draft transaction remains visible and active.Without manual cleanup of the draft
payment.transactionand the draftaccount.paymentlinked to it, the portal keeps showing the abandoned attempt and a newPayclick can fail or chain on top of the dead one.Fix
Override
payment.transaction.create()to auto-cancel previous Djomydraft/pendingtransactions attached to the same sale order / invoice as the new one. Strict guards:done,cancel,error) are preserved.provider_code='djomy'scope).account.paymentrecords linked to a cancelled tx are also cancelled (so the invoice doesn't keep a polluting orphan draft).state_message, which is rendered on the customer portal (payment/views/payment_templates.xml) and would surface internal cleanup details to the end user.Tests
8
TransactionCasetests inpayment_djomy/tests/test_zombie_cleanup.py:test_new_tx_cancels_previous_draft_on_same_so— nominal: draft supersededtest_new_tx_cancels_previous_pending_on_same_so— nominal: pending supersededtest_done_tx_is_never_cancelled— guard: final states preservedtest_already_cancelled_tx_is_left_alone— guardtest_error_tx_is_left_alone— guardtest_tx_on_other_so_is_not_touched— isolation by SOtest_non_djomy_tx_is_not_touched— isolation by provider (usespayment.payment_provider_transfer)test_stale_account_payment_is_cancelled—account.paymentdraft is also cancelled (search mocked to avoid full accounting setup)Run:
Result: 8/8 green on Odoo 19.0.
Backwards compatibility
sale_order_ids/invoice_idsare checked via_fieldsbefore use — works whetherpayment_sale/account_paymentare installed or not.create()time; existing transactions are not affected by the module upgrade itself.Files changed
payment_djomy/models/payment_transaction.py—create()override +_djomy_cancel_stale_siblings()helper.payment_djomy/tests/__init__.py— new (declares the test module).payment_djomy/tests/test_zombie_cleanup.py— new (8 test cases).