From 5ad7b655cf296e5306554bd7bc7189a695430b48 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Wed, 3 Apr 2019 09:11:03 +0530 Subject: [PATCH] fix: Divide by zero exception handling --- .../item_wise_sales_register.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py index 88c612e7f6..e8b19b4024 100644 --- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py @@ -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 ] - row += [(d.base_net_rate * d.qty)/d.stock_qty, d.base_net_amount] \ - if d.stock_uom != d.uom and d.stock_qty != 0 else [d.base_net_rate, d.base_net_amount] + if d.stock_uom != d.uom and d.stock_qty: + 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 for tax in tax_columns: @@ -108,13 +110,13 @@ def get_conditions(filters): conditions += """ and exists(select name from `tabSales Invoice Payment` where parent=`tabSales Invoice`.name and ifnull(`tabSales Invoice Payment`.mode_of_payment, '') = %(mode_of_payment)s)""" - + if filters.get("warehouse"): conditions += """ and exists(select name from `tabSales Invoice Item` where parent=`tabSales Invoice`.name and ifnull(`tabSales Invoice Item`.warehouse, '') = %(warehouse)s)""" - + if filters.get("brand"): conditions += """ and exists(select name from `tabSales Invoice Item` where parent=`tabSales Invoice`.name @@ -131,10 +133,10 @@ def get_conditions(filters): def get_items(filters, additional_query_columns): conditions = get_conditions(filters) match_conditions = frappe.build_match_conditions("Sales Invoice") - + if match_conditions: match_conditions = " and {0} ".format(match_conditions) - + if additional_query_columns: additional_query_columns = ', ' + ', '.join(additional_query_columns)