Skip to content

fix: make partial payments transactional and use core currency setup#216

Open
my-dev-jour wants to merge 1 commit intoBrainWise-DEV:developfrom
my-dev-jour:fix/197-199-partial-payments
Open

fix: make partial payments transactional and use core currency setup#216
my-dev-jour wants to merge 1 commit intoBrainWise-DEV:developfrom
my-dev-jour:fix/197-199-partial-payments

Conversation

@my-dev-jour
Copy link
Copy Markdown
Contributor

Summary

  • replace manual Payment Entry construction with ERPNext's get_payment_entry(...)
  • remove helper-level commits from partial payment creation
  • rollback the full payment batch to a savepoint if any payment in the request fails

Why

add_payment_to_partial_invoice() currently claims rollback-safe behavior, but create_payment_entry() commits each submitted Payment Entry immediately. If a later payment in the same batch fails, the API returns an error after already creating accounting side effects and then tries to clean up with compensating cancels.

The current code also hardcodes both paid_from_account_currency and paid_to_account_currency from invoice.currency, which diverges from ERPNext's standard Payment Entry setup and is wrong for multi-currency sites.

What changed

  • use ERPNext core get_payment_entry(...) so account currencies and references come from the standard path
  • keep POSNext-specific fields like mode_of_payment, reference_no, remarks, and explicit payment account selection
  • wrap the batch in a database savepoint and roll back to that savepoint on failure
  • remove the misleading compensating-cancel flow and helper-level frappe.db.commit()

Validation

  • reproduced the non-atomic behavior on ERPNext 16.11.0 staging before the fix: a failed batch still created a submitted Payment Entry and then cancelled it
  • applied this patch on the same staging bench and re-tested a failed mixed-valid/invalid payment batch
  • after the fix, no Payment Entry Reference rows remained for the invoice after the failed request
  • local verification was limited to py_compile in this workspace

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant