fix: preserve POS payment amounts during draft creation#215
fix: preserve POS payment amounts during draft creation#215my-dev-jour wants to merge 1 commit intoBrainWise-DEV:developfrom
Conversation
|
CI server passed. The remaining failing checks appear to be repo-level workflow/lint issues rather than regressions from this patch: the dependency audit cannot resolve ERPNext in CI, and the linter runs pre-commit with --all-files, which surfaces existing repo-wide formatting and Ruff issues outside this change. |
engahmed1190
left a comment
There was a problem hiding this comment.
Code Review — RECOMMEND CLOSE (Superseded)
Summary
Fixes ERPNext's set_missing_values() wiping payment amounts by using a snapshot/restore pattern: captures payment rows before set_missing_values(), lets it run destructively, then restores the original rows.
Test Results
Both tests pass on nexus.local.
Superseded by commit fbf8e80b
This PR fixes the same bug as commit fbf8e80b on fix/payment-amount-wiped-by-erpnext, which is already merged. Here's the comparison:
| Aspect | fbf8e80b (merged) |
This PR (#215) |
|---|---|---|
| Approach | set_missing_values(for_validate=True) |
Snapshot → let destructive run → restore |
| Lines changed | ~25 (1 line change + comments) | ~100+ (4 helper functions + tests) |
| Complexity | Prevents the problem | Lets it happen then undoes it |
| Risk | Relies on ERPNext's for_validate=True contract |
More defensive, doesn't depend on ERPNext internals |
| Tests | None | 2 passing unit tests |
The for_validate=True approach is simpler and more maintainable. It prevents update_multi_mode_option() from running at all, rather than letting it destroy data and then restoring from a snapshot. The commit message explains why this is safe: POS Next already sets the fields that for_validate=True skips (customer, ignore_pricing_rule, tax_category).
What's Worth Keeping
The test file (test_invoices.py) has useful tests for payment snapshot/restore helpers. If you decide to keep the snapshot approach as a fallback in the future, these tests are valuable.
Code Quality (for the record)
The helper functions are well-structured:
_clean_payment_row— strips parent metadata, handles both dict and object inputs_snapshot_invoice_payments/_restore_invoice_payments— clean capture/restore_sync_invoice_payment_amounts— correctly handles conversion_rate and pre-existing base_amount
Minor concern: _sync_invoice_payment_amounts has flt(payment.get("base_amount") or 0) or flt(...) — if base_amount is explicitly 0, it falls through to the calculation. Unlikely to matter in practice.
Verdict
Recommend closing — the bug is already fixed by a simpler approach. If there are concerns about for_validate=True skipping needed fields, those should be addressed as separate targeted fixes.
|
Closing — superseded by commit fbf8e80 on |
Summary
set_missing_values()inupdate_invoice()paid_amountandbase_paid_amountafter restoring paymentsRoot Cause
ERPNext rebuilds POS payment rows during
set_missing_values()from POS Profile defaults. POSNext was calling that flow during draft creation without restoring the cashier-entered payment rows, so a paid sale could be saved/submitted with zeroed or replaced payments and end up unpaid.Validation
16.11.0staging with a real POS flowoutstanding_amount = 0py_compilein this workspaceNotes