Error when creating multiline transaction in foreign currency using GraphQL
Hi!
I'm developing a little Google Sheets script to push batches of complex transactions to a client's Wave account. During testing I found a particular issue with multi-line foreign currency transactions that I'm not able to get around.
Preface: I'm using Wave's GraphQL API. Home currency is CAD, and the foreign currency I'm trying is USD. I have zero issues created multiline transactions in the business's home currency. I also have no issues creating simple single line transactions in foreign currencies. But about half of the USD multiline transactions I create fail with the following not-so-helpful error:
{ "data": { "moneyTransactionCreate": { "didSucceed": false, "inputErrors": [ { "message": "This value is invalid. LINE_ITEM_BUSINESS_AMOUNT_UNDERBALANCED", "code": "UNKNOWN", "path": null } ], "transaction": null } } }
Sometimes the error goes the other way, and it's LINE_ITEM_BUSINESS_AMOUNT_OVERBALANCED
This is a basic example of an input that would cause the fault (note that the anchor account is a USD based "Money in Transit" asset account, and the line item accounts are just some default expense accounts).
{ "businessId": "QnVzaW5lc3M6ZjAwYjUyNGEtZTc1YS00MmY1LWJkOTEtNDJkNTQ0MmQ5MDdm", "externalId": "9f67bb63-e85a-486b-b04f-1c1ac70e06b1", "description": "Test Transaction", "date": "2020-03-31", "anchor": { "accountId": "QWNjb3VudDo5Mjc0ODYwOTU4MjkwMjQyNDc7QnVzaW5lc3M6ZjAwYjUyNGEtZTc1YS00MmY1LWJkOTEtNDJkNTQ0MmQ5MDdm", "amount": 1000, "direction": "WITHDRAWAL" }, "lineItems": [ { "accountId": "QWNjb3VudDo4NjY2NzA1Mjg0OTA5NDYzMjA7QnVzaW5lc3M6ZjAwYjUyNGEtZTc1YS00MmY1LWJkOTEtNDJkNTQ0MmQ5MDdm", "amount": 500, "balance": "DEBIT", "taxes": [], "customerId": null, "description": "" }, { "accountId": "QWNjb3VudDo4NjY2NzA1Mjg1OTk5OTgyMjg7QnVzaW5lc3M6ZjAwYjUyNGEtZTc1YS00MmY1LWJkOTEtNDJkNTQ0MmQ5MDdm", "amount": 500, "balance": "DEBIT", "taxes": [], "customerId": null, "description": "" } ] }
If I simply change the date to 2020-04-01, this otherwise identical transaction successfully posts to accounting. From what I know about how Wave handles foreign currencies, combined with what I can guess the error message means (that the sum of the line items doesn't match the transaction amount), I'm assuming that the GraphQL API is rounding each converted line item before summing them for comparison to the converted anchor amount, or nothing is being rounded properly and there's a floating-point discrepancy causing a false negative. I would expect the GraphQL API to handle this gracefully though. This particular bug is holding me back from completing this tool so I'm hoping you can fix it or suggest a workaround.
Thanks so much for your help!
Seb.
Comments
Hi @SBenoit,
Your assumption about the cause of this issue is entirely correct.
There is some ongoing project work around the internal, back-end accounting APIs that the public GQL sits over which will resolve this issue. Unfortunately, I can't give you a specific timeline, but this is actively being worked on.
There is no real work-around to this issue; for example you cannot create an 'unbalanced' foreign currency transaction in the hope that this will become 'balanced' after conversion, as this would fail validation at the outer layer of the API.
I have a note to let you know when then underlying issue is resolved through our back-end API changes.
Hope that helps, Paul
Thank you @PaulC! I'm really looking forward to the nitty-gritty improvements you guys have planned. Always fun to watch your journey unfold