mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
Merge pull request #31629 from maharshivpatel/fix-einvoice-discounts
fix: (india) (e-invoice) convert discount to absolute value
This commit is contained in:
@@ -274,45 +274,43 @@ def get_item_list(invoice):
|
|||||||
item.description = sanitize_for_json(d.item_name)
|
item.description = sanitize_for_json(d.item_name)
|
||||||
|
|
||||||
item.qty = abs(item.qty)
|
item.qty = abs(item.qty)
|
||||||
|
item_qty = item.qty
|
||||||
|
|
||||||
|
item.discount_amount = abs(item.discount_amount)
|
||||||
|
item.taxable_value = abs(item.taxable_value)
|
||||||
|
|
||||||
|
if invoice.get("is_return") or invoice.get("is_debit_note"):
|
||||||
|
item_qty = item_qty or 1
|
||||||
|
|
||||||
hide_discount_in_einvoice = cint(
|
hide_discount_in_einvoice = cint(
|
||||||
frappe.db.get_single_value("E Invoice Settings", "dont_show_discounts_in_e_invoice")
|
frappe.db.get_single_value("E Invoice Settings", "dont_show_discounts_in_e_invoice")
|
||||||
)
|
)
|
||||||
|
|
||||||
if hide_discount_in_einvoice:
|
if hide_discount_in_einvoice:
|
||||||
if flt(item.qty) != 0.0:
|
item.unit_rate = item.taxable_value / item_qty
|
||||||
item.unit_rate = abs(item.taxable_value / item.qty)
|
item.gross_amount = item.taxable_value
|
||||||
else:
|
|
||||||
item.unit_rate = abs(item.taxable_value)
|
|
||||||
item.gross_amount = abs(item.taxable_value)
|
|
||||||
item.taxable_value = abs(item.taxable_value)
|
|
||||||
item.discount_amount = 0
|
item.discount_amount = 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if invoice.get("apply_discount_on") and (abs(invoice.get("base_discount_amount") or 0.0) > 0.0):
|
if invoice.get("apply_discount_on") and (abs(invoice.get("base_discount_amount") or 0.0) > 0.0):
|
||||||
# TODO: need to handle case when tax included in basic rate is checked.
|
# TODO: need to handle case when tax included in basic rate is checked.
|
||||||
item.discount_amount = (item.discount_amount * item.qty) + (
|
item.discount_amount = (item.discount_amount * item_qty) + (
|
||||||
abs(item.base_amount) - abs(item.base_net_amount)
|
abs(item.base_amount) - abs(item.base_net_amount)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
item.discount_amount = item.discount_amount * item.qty
|
item.discount_amount = item.discount_amount * item_qty
|
||||||
|
|
||||||
if invoice.get("is_return") or invoice.get("is_debit_note"):
|
try:
|
||||||
item.unit_rate = (abs(item.taxable_value) + item.discount_amount) / (
|
item.unit_rate = (item.taxable_value + item.discount_amount) / item_qty
|
||||||
1 if (item.qty == 0) else item.qty
|
except ZeroDivisionError:
|
||||||
|
# This will never run but added as safety measure
|
||||||
|
frappe.throw(
|
||||||
|
title=_("Error: Qty is Zero"),
|
||||||
|
msg=_("Quantity can't be zero unless it's Credit/Debit Note."),
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
try:
|
|
||||||
item.unit_rate = abs(item.taxable_value + item.discount_amount) / item.qty
|
|
||||||
except ZeroDivisionError:
|
|
||||||
# This will never run but added as safety measure
|
|
||||||
frappe.throw(
|
|
||||||
title=_("Error: Qty is Zero"),
|
|
||||||
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 = item.taxable_value + item.discount_amount
|
||||||
item.taxable_value = abs(item.taxable_value)
|
item.taxable_value = item.taxable_value
|
||||||
item.is_service_item = "Y" if item.gst_hsn_code and item.gst_hsn_code[:2] == "99" else "N"
|
item.is_service_item = "Y" if item.gst_hsn_code and item.gst_hsn_code[:2] == "99" else "N"
|
||||||
item.serial_no = ""
|
item.serial_no = ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user