Fix update-bank-transaction 400 when editing line items#190
Open
pedromachados wants to merge 1 commit into
Open
Fix update-bank-transaction 400 when editing line items#190pedromachados wants to merge 1 commit into
pedromachados wants to merge 1 commit into
Conversation
updateBankTransaction spread the entire fetched BankTransaction into the update payload, carrying Xero's read-only computed fields (subTotal, total, totalTax). When lineItems are replaced, Xero recomputes line totals but the stale subTotal/total from the spread no longer match, so the API rejects the update with HTTP 400 "The document sub total does not equal the sub total of the lines" — even when only a line description changes. Build a minimal payload with only editable fields plus the attributes Xero needs on update (bankAccount, lineAmountTypes, status, currencyCode preserved from the existing transaction), and omit the computed totals so Xero recomputes them. Per Xero's BankTransactions API docs, subTotal/total/totalTax are "calculated by Xero and cannot be overridden," and lineAmountTypes defaults to Exclusive if omitted — so preserving it avoids silently changing the tax treatment. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Problem
Calling
update-bank-transactionto edit an existing bank transaction's line items fails with:This happens even when only a line description changes and the monetary amount is identical.
Root cause
updateBankTransactioninsrc/handlers/update-xero-bank-transaction.handler.tsbuilds the update payload by spreading the entire fetched transaction:The spread carries Xero's read-only computed fields —
subTotal,total,totalTax. WhenlineItemsare replaced, Xero recomputes the line totals server-side, but the stalesubTotal/totalcopied from the fetched object no longer reconcile, so the API rejects the update.Per the Xero BankTransactions API docs,
SubTotal,Total, andTotalTaxare each "calculated by Xero and cannot be overridden."Fix
Build a minimal payload containing only the editable fields plus the attributes Xero needs on update, and omit the computed totals so Xero recomputes them:
lineAmountTypesis preserved from the existing transaction rather than omitted: it defaults to Exclusive when absent, so dropping it could silently change the tax treatment (and therefore the recomputed totals) on inclusive-tax transactions.Verification
npm run build— clean.npm test— 14/14 pass.