Skip to content

Make export() idempotent instead of duplicating payments - #83

Open
VaibhavRaina wants to merge 1 commit into
raphaelm:masterfrom
VaibhavRaina:fix/repeated-export-payment-totals
Open

Make export() idempotent instead of duplicating payments#83
VaibhavRaina wants to merge 1 commit into
raphaelm:masterfrom
VaibhavRaina:fix/repeated-export-payment-totals

Conversation

@VaibhavRaina

Copy link
Copy Markdown

Problem

Calling export() more than once on the same SepaTransfer / SepaDD duplicates the payments. _finalize_batch() appends the batch PmtInf nodes to the live document on every call, so the second export reports twice the transaction count and control sum, and the third export three times. This bites the common flow of exporting once to validate or preview and once more to write the file.

doc.add_payment(p1); doc.add_payment(p2)
doc.export()  # NbOfTxs=2, CtrlSum=60.12
doc.export()  # NbOfTxs=4, CtrlSum=120.24

Fix

export() now finalizes a copy of the document and serializes that, leaving the original untouched. Repeated exports return the same output, and payments added between exports are included exactly once. Single-export behaviour and output are unchanged (the existing fixture tests still pass byte-for-byte).

Tests

  • Added tests/test_repeated_export.py, parametrized over SepaTransfer/SepaDD and batch/non-batch, checking the group header totals, per-PmtInf totals and transaction count across three consecutive exports and after adding a payment.
  • pytest (64 passed), flake8 and isort -c are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PtpcFAThUxrGAyCyxiiEC5

Calling export() twice on the same SepaTransfer or SepaDD doubled the
transaction count and control sums, because _finalize_batch() appended
the batch nodes to the live document on every call. This bites anyone
who exports once to validate or preview and again to write the file.

Finalize a copy of the document instead, so repeated exports (including
after adding more payments) always reflect exactly the payments that were
added.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PtpcFAThUxrGAyCyxiiEC5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant