fix: (india) (e-invoice) discount calculation
I have added fixes for discount in e-inovice.
This commit is contained in:
@@ -273,21 +273,26 @@ def get_item_list(invoice):
|
|||||||
|
|
||||||
item.qty = abs(item.qty)
|
item.qty = abs(item.qty)
|
||||||
|
|
||||||
if invoice.get("apply_discount_on"):
|
if invoice.get("apply_discount_on") and (invoice.get("base_discount_amount") > 0.00):
|
||||||
item.discount_amount = item.base_amount - item.base_net_amount
|
# TODO: need to handle case when tax included in basic rate is checked.
|
||||||
|
item.discount_amount = (item.discount_amount * item.qty) + (
|
||||||
|
item.base_amount - item.base_net_amount
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
item.discount_amount = item.discount_amount * item.qty
|
||||||
|
|
||||||
if invoice.get("is_return") or invoice.get("is_debit_note"):
|
if invoice.get("is_return") or invoice.get("is_debit_note"):
|
||||||
item.unit_rate = abs(item.taxable_value - item.discount_amount) / (
|
item.unit_rate = abs(item.taxable_value + item.discount_amount) / (
|
||||||
1 if (item.qty == 0) else item.qty
|
1 if (item.qty == 0) else item.qty
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
item.unit_rate = abs(item.taxable_value - item.discount_amount) / item.qty
|
item.unit_rate = abs(item.taxable_value + item.discount_amount) / item.qty
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
# This will never run but added as safety measure
|
# This will never run but added as safety measure
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
title="Error: Qty is Zero",
|
title=_("Error: Qty is Zero"),
|
||||||
msg="Quantity can't be zero unless it's Credit/Debit Note.",
|
msg=_("Quantity can't be zero unless it's Credit/Debit Note."),
|
||||||
)
|
)
|
||||||
|
|
||||||
item.gross_amount = abs(item.taxable_value) + item.discount_amount
|
item.gross_amount = abs(item.taxable_value) + item.discount_amount
|
||||||
|
|||||||
Reference in New Issue
Block a user