From b37559c535ce5cc4589a08a1af95311b360ce810 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 14 Mar 2022 16:13:35 +0530 Subject: [PATCH] fix: KSA E-Invoice QR Code showing wrong VAT amount --- erpnext/regional/saudi_arabia/utils.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/erpnext/regional/saudi_arabia/utils.py b/erpnext/regional/saudi_arabia/utils.py index a03c3f0994..edcc3ef203 100644 --- a/erpnext/regional/saudi_arabia/utils.py +++ b/erpnext/regional/saudi_arabia/utils.py @@ -90,7 +90,7 @@ def create_qr_code(doc, method=None): tlv_array.append(''.join([tag, length, value])) # VAT Amount - vat_amount = str(doc.total_taxes_and_charges) + vat_amount = str(get_vat_amount(doc)) tag = bytes([5]).hex() length = bytes([len(vat_amount)]).hex() @@ -127,6 +127,22 @@ def create_qr_code(doc, method=None): doc.db_set('ksa_einv_qr', _file.file_url) doc.notify_update() +def get_vat_amount(doc): + vat_settings = frappe.db.get_value('KSA VAT Setting', {'company': doc.company}) + vat_accounts = [] + vat_amount = 0 + + if vat_settings: + vat_settings_doc = frappe.get_doc('KSA VAT Setting', vat_settings) + + for row in vat_settings_doc.get('ksa_vat_sales_accounts'): + vat_accounts.append(row.account) + + for tax in doc.get('taxes'): + if tax.account_head in vat_accounts: + vat_amount += tax.tax_amount + + return vat_amount def delete_qr_code_file(doc, method=None): region = get_region(doc.company)