fix: Divide by zero exception handling

This commit is contained in:
deepeshgarg007 2019-04-03 09:11:03 +05:30
parent b035bf7f39
commit 5ad7b655cf

View File

@ -54,8 +54,10 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum
delivery_note, d.income_account, d.cost_center, d.stock_qty, d.stock_uom delivery_note, d.income_account, d.cost_center, d.stock_qty, d.stock_uom
] ]
row += [(d.base_net_rate * d.qty)/d.stock_qty, d.base_net_amount] \ if d.stock_uom != d.uom and d.stock_qty:
if d.stock_uom != d.uom and d.stock_qty != 0 else [d.base_net_rate, d.base_net_amount] row += [(d.base_net_rate * d.qty)/d.stock_qty, d.base_net_amount]
else:
row += [d.base_net_rate, d.base_net_amount]
total_tax = 0 total_tax = 0
for tax in tax_columns: for tax in tax_columns:
@ -108,13 +110,13 @@ def get_conditions(filters):
conditions += """ and exists(select name from `tabSales Invoice Payment` conditions += """ and exists(select name from `tabSales Invoice Payment`
where parent=`tabSales Invoice`.name where parent=`tabSales Invoice`.name
and ifnull(`tabSales Invoice Payment`.mode_of_payment, '') = %(mode_of_payment)s)""" and ifnull(`tabSales Invoice Payment`.mode_of_payment, '') = %(mode_of_payment)s)"""
if filters.get("warehouse"): if filters.get("warehouse"):
conditions += """ and exists(select name from `tabSales Invoice Item` conditions += """ and exists(select name from `tabSales Invoice Item`
where parent=`tabSales Invoice`.name where parent=`tabSales Invoice`.name
and ifnull(`tabSales Invoice Item`.warehouse, '') = %(warehouse)s)""" and ifnull(`tabSales Invoice Item`.warehouse, '') = %(warehouse)s)"""
if filters.get("brand"): if filters.get("brand"):
conditions += """ and exists(select name from `tabSales Invoice Item` conditions += """ and exists(select name from `tabSales Invoice Item`
where parent=`tabSales Invoice`.name where parent=`tabSales Invoice`.name
@ -131,10 +133,10 @@ def get_conditions(filters):
def get_items(filters, additional_query_columns): def get_items(filters, additional_query_columns):
conditions = get_conditions(filters) conditions = get_conditions(filters)
match_conditions = frappe.build_match_conditions("Sales Invoice") match_conditions = frappe.build_match_conditions("Sales Invoice")
if match_conditions: if match_conditions:
match_conditions = " and {0} ".format(match_conditions) match_conditions = " and {0} ".format(match_conditions)
if additional_query_columns: if additional_query_columns:
additional_query_columns = ', ' + ', '.join(additional_query_columns) additional_query_columns = ', ' + ', '.join(additional_query_columns)