fix: use vat_amount instead of vat_18_percent_with_amount for e-taxes vat18 field
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1121908352
commit
731f020d6d
|
|
@ -486,23 +486,9 @@ def build_invoice_payload(doc, serial_number):
|
|||
for item in doc.items:
|
||||
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
|
||||
# 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
|
||||
# vat18 = pure VAT tax amount (vat_amount), NOT total with VAT (vat_18_percent_with_amount)
|
||||
vat18 = item.vat_amount if hasattr(item, 'vat_amount') and item.vat_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
|
||||
exempt = item.amount_without_vat if hasattr(item, 'amount_without_vat') and item.amount_without_vat else None
|
||||
|
|
@ -514,8 +500,8 @@ def build_invoice_payload(doc, serial_number):
|
|||
"unit": item.uom, # Use UOM name as text
|
||||
"unitCode": None, # Not required per user confirmation
|
||||
"quantity": item.qty,
|
||||
"pricePerUnit": price_per_unit,
|
||||
"cost": net_amount,
|
||||
"pricePerUnit": item.rate,
|
||||
"cost": item.amount,
|
||||
"exciseRate": None,
|
||||
"excise": None,
|
||||
"vat18": vat18,
|
||||
|
|
|
|||
Loading…
Reference in New Issue