Wednesday, February 14, 2024
1 change · 17.0
Resolved issues and error corrections
This fix resolves issues where AvaTax rejects invoices due to invalid state transitions, which can occur when system errors or concurrent access problems interrupt normal invoice processing. By switching to AvaTax's more flexible "create or adjust" endpoint, Odoo now treats itself as the source of truth for invoice states, preventing errors that could break automatic subscription renewals and other critical workflows.
Original PR description
Avatax doesn't allow all state transitions. For example, if an invoice is committed it can't be committed again. If an invoice is voided, it can't be committed. These state transitions shouldn't…
Avatax doesn't allow all state transitions. For example, if an invoice is committed it can't be committed again. If an invoice is voided, it can't be committed. These state transitions shouldn't happen in Odoo when things go well, but bugs and concurrent access errors can stop any of our normal flows at any point. For example, a subscription gets automatically charged, does the payment, generates the invoice and commits the invoice in Avatax. However, the transaction fails to commit in Odoo because of a concurrent access error. Next time an invoice with the same Avatax Code is generated the tax calculation will fail with this error: odoo.exceptions.UserError: Odoo could not fetch the taxes related to Draft Invoice (* 123456) (M123456). Please check the status of `Journal Entry 123456` in the AvaTax portal. DocStatus is invalid for this operation. Errors like this can then break the automatic subscription renewal. Since there's many reasons a flow can crash it's better to make Avatax as idempotent as possible. The source of truth for invoice state is Odoo, regardless of what's in Avatax. To achieve this we'll fully switch to the createoradjust [1] endpoint that was previously introduced for test environments [2]. This endpoint allows almost all state transitions and should avoid the majority of blocking errors. [1] https://developer.avalara.com/api-reference/avatax/rest/v2/methods/Transactions/CreateOrAdjustTransaction [2] 12039763a3a8f27a1d69bebb6d661ad20ce3537b cc @tfr-odoo