Friday, July 26, 2024
1 change
Resolved issues and error corrections
This fix resolves a critical issue where successfully processed Mexican invoices were being rolled back when errors occurred during batch processing. Previously, transaction commits only happened at the end of the entire batch, causing successfully sent invoices to be reverted if any invoice in the batch failed. Now, each invoice is committed immediately after successful processing, preventing duplicate signatures and data loss.
Original PR description
- Create 4 invoices: A, B, C, D with a correct MX setup - Make sure C will fail by removing the SAT code on the product for example - Run the send and print wizard on all invoices and check…
- Create 4 invoices: A, B, C, D with a correct MX setup
- Make sure C will fail by removing the SAT code on the product for example
- Run the send and print wizard on all invoices and check 'Download' (to force a synchronous run).
After each call to the web-service, the code does:
```
# Check for success.
if invoice.l10n_mx_edi_cfdi_state == 'sent':
continue
```
However, the `cr.commit` is at the end of the loop. So the transaction is not committed except in case of error!
When running the send and print synchronously, the error is raised to the user that will rollback the whole
transaction.
In case of the setup above, A, B and C are well commit but D is sent and has been rollback.
Then, the user will sign again D making the invoice signed twice.
To solve the issue, let's commit right after each web-service call.
That way, whatever the way we use to call the web-services, the transaction is commit immediately.
opw-4003043
opw-3985376
opw-4059666
opw-3955553
...and many others!