Merge pull request #30230 from deepeshgarg007/vat_amount_in_ksa

fix: KSA E-Invoice QR Code showing wrong VAT amount
This commit is contained in:
Deepesh Garg 2022-03-14 21:47:22 +05:30 committed by GitHub
commit 8add8eb058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -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_cached_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)

View File

@ -26,9 +26,12 @@ def update_itemised_tax_data(doc):
elif row.item_code and itemised_tax.get(row.item_code):
tax_rate = sum([tax.get('tax_rate', 0) for d, tax in itemised_tax.get(row.item_code).items()])
row.tax_rate = flt(tax_rate, row.precision("tax_rate"))
row.tax_amount = flt((row.net_amount * tax_rate) / 100, row.precision("net_amount"))
row.total_amount = flt((row.net_amount + row.tax_amount), row.precision("total_amount"))
meta = frappe.get_meta(row.doctype)
if meta.has_field('tax_rate'):
row.tax_rate = flt(tax_rate, row.precision("tax_rate"))
row.tax_amount = flt((row.net_amount * tax_rate) / 100, row.precision("net_amount"))
row.total_amount = flt((row.net_amount + row.tax_amount), row.precision("total_amount"))
def get_account_currency(account):
"""Helper function to get account currency."""