fix: send correct VAT amount to e-taxes instead of total with VAT
vat_18_percent_with_amount stores the total INCLUDING VAT (e.g. 118), but the e-taxes API vat18 field expects just the tax amount (e.g. 18). Also calculates net cost/pricePerUnit for VAT-inclusive pricing (ƏDV daxil 18%). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d3775786a3
commit
1121908352
|
|
@ -486,8 +486,23 @@ def build_invoice_payload(doc, serial_number):
|
||||||
for item in doc.items:
|
for item in doc.items:
|
||||||
item_master = frappe.get_doc("Item", item.item_code)
|
item_master = frappe.get_doc("Item", item.item_code)
|
||||||
|
|
||||||
|
# Get the pure VAT tax amount (not total with VAT)
|
||||||
|
vat_amount = item.vat_amount if hasattr(item, 'vat_amount') and item.vat_amount else 0
|
||||||
|
|
||||||
|
# Calculate net amount (without VAT) for cost field
|
||||||
|
# vat_18_percent_with_amount = total WITH VAT (e.g. 118 for net 100)
|
||||||
|
# For "ƏDV daxil 18%": item.amount already includes VAT, need to subtract
|
||||||
|
# For "ƏDV 18%": item.amount is net, formula still works (118 - 18 = 100)
|
||||||
|
if hasattr(item, 'vat_18_percent_with_amount') and item.vat_18_percent_with_amount:
|
||||||
|
net_amount = item.vat_18_percent_with_amount - vat_amount
|
||||||
|
else:
|
||||||
|
net_amount = item.amount
|
||||||
|
|
||||||
|
price_per_unit = net_amount / item.qty if item.qty else item.rate
|
||||||
|
|
||||||
# Map VAT fields to E-Taxes format
|
# Map VAT fields to E-Taxes format
|
||||||
vat18 = item.vat_18_percent_with_amount if hasattr(item, 'vat_18_percent_with_amount') and item.vat_18_percent_with_amount else None
|
# vat18 must be the VAT tax amount only (e.g. 18), NOT total with VAT (e.g. 118)
|
||||||
|
vat18 = vat_amount if vat_amount > 0 else None
|
||||||
vat0 = item.vat_0_percent_with_amount if hasattr(item, 'vat_0_percent_with_amount') and item.vat_0_percent_with_amount else None
|
vat0 = item.vat_0_percent_with_amount if hasattr(item, 'vat_0_percent_with_amount') and item.vat_0_percent_with_amount else None
|
||||||
vat_free = item.vat_free_amount if hasattr(item, 'vat_free_amount') and item.vat_free_amount else None
|
vat_free = item.vat_free_amount if hasattr(item, 'vat_free_amount') and item.vat_free_amount else None
|
||||||
exempt = item.amount_without_vat if hasattr(item, 'amount_without_vat') and item.amount_without_vat else None
|
exempt = item.amount_without_vat if hasattr(item, 'amount_without_vat') and item.amount_without_vat else None
|
||||||
|
|
@ -499,8 +514,8 @@ def build_invoice_payload(doc, serial_number):
|
||||||
"unit": item.uom, # Use UOM name as text
|
"unit": item.uom, # Use UOM name as text
|
||||||
"unitCode": None, # Not required per user confirmation
|
"unitCode": None, # Not required per user confirmation
|
||||||
"quantity": item.qty,
|
"quantity": item.qty,
|
||||||
"pricePerUnit": item.rate,
|
"pricePerUnit": price_per_unit,
|
||||||
"cost": item.amount,
|
"cost": net_amount,
|
||||||
"exciseRate": None,
|
"exciseRate": None,
|
||||||
"excise": None,
|
"excise": None,
|
||||||
"vat18": vat18,
|
"vat18": vat18,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue