-
Notifications
You must be signed in to change notification settings - Fork 54
Fix: ZATCA validation BR-CO-15 by adding custom_grand_total_without_rounding #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Ensure that BT-112 (total with VAT) equals BT-109 (total without VAT) plus BT-110 (VAT amount), as required by ZATCA UBL validation rules. Adjusted computation logic to comply.
Hello, and thank you for your contribution. Before I review it from a technical standpoint, I'd like @omarashrafsarhan to discuss the business side of things. Am I correct in understanding that this new custom grand total field is used in both printed invoices and reporting to ZATCA? That is, it is considered the actual amount that customers actually pay. Or is that still the regular grand total? |
@alaalsalam The rounding issue may occur in several scenarios, such as with the 'Total taxes and charges' and sum of "Invoice line tax amounts. Could you clarify how this fix addresses those cases? Additionally, will this workaround be suitable for instances involving tax rates of 15% and 0% in the same invoice. |
I have set up a test instance containing frappe, erpnext, and ksa_compliance from Ala's fork and branch.
I onboarded the sandbox environment and tried an example invoice without any rounding involved (10000 SAR, 11500 with VAT), but it failed validation for me with BR-CO-15: |
Hi @mhaggag @omarashrafsarhan 👋 I'd like to first clarify the core issue this PR addresses.
|
Hi @mhaggag 👋 After reviewing the test XML, I found that the issue was not with the underlying calculation — it was due to the fact that the XML template still used As discussed earlier, ERPNext applies internal rounding to ✅ The Fix ❌ ✅ |
…Amount) in UBL XML - Replaced invoice.grand_total with custom_grand_total_without_rounding in the XML template - Prevents BR-CO-15 validation error by ensuring BT-112 = BT-109 + BT-110 exactly - This ensures compatibility with mixed tax rates (15%, 0%) and avoids ERPNext's internal rounding - Does not affect ERP logic or printed values — this is strictly for ZATCA compliance
… to avoid rounding mismatch
Is this ready for review/testing, or are you still working on further fixes? |
Summary
This pull request resolves the ZATCA validation error:
Problem
ERPNext/Frappe by default applies rounding to the grand total amount (
grand_total
), which can lead to mismatch with ZATCA's expected precise values in the XML (UBL 2.1), especially in fields BT-109 + BT-110 ≠ BT-112.Solution
A new custom field was added to
Sales Invoice
:custom_grand_total_without_rounding
Grand Total (Without Rounding)
Impact
✅ Fixes the BR-CO-15 error
✅ Ensures mathematical consistency in reported invoices
✅ Does not affect standard UI behavior or printed totals
✅ Transparent to end users