fix: (india) (e-invoice) qty should not be changed to 1
Qty of 0 is allowed so can't change item.qty to 1 instead created item_qty and used it.
This commit is contained in:
@@ -273,39 +273,41 @@ def get_item_list(invoice):
|
||||
item.sr_no = d.idx
|
||||
item.description = sanitize_for_json(d.item_name)
|
||||
|
||||
item.qty = abs(item.qty) or 1
|
||||
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(
|
||||
frappe.db.get_single_value("E Invoice Settings", "dont_show_discounts_in_e_invoice")
|
||||
)
|
||||
|
||||
if hide_discount_in_einvoice:
|
||||
item.unit_rate = item.taxable_value / item.qty
|
||||
item.unit_rate = item.taxable_value / item_qty
|
||||
item.gross_amount = item.taxable_value
|
||||
item.discount_amount = 0
|
||||
|
||||
else:
|
||||
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.
|
||||
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)
|
||||
)
|
||||
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"):
|
||||
item.unit_rate = (item.taxable_value + item.discount_amount) / item.qty
|
||||
else:
|
||||
try:
|
||||
item.unit_rate = (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."),
|
||||
)
|
||||
try:
|
||||
item.unit_rate = (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 = item.taxable_value + item.discount_amount
|
||||
item.taxable_value = item.taxable_value
|
||||
|
||||
Reference in New Issue
Block a user