Merge pull request #6817 from nabinhait/hotfix
[fix] float division by zero
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 0c75d15..f3905de 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -298,6 +298,7 @@
execute:frappe.delete_doc_if_exists("DocType", "Payment Tool Detail")
erpnext.patches.v7_0.setup_account_table_for_expense_claim_type_if_exists
erpnext.patches.v7_0.migrate_schools_to_erpnext
+erpnext.patches.v7_1.update_lead_source
erpnext.patches.v6_20x.remove_customer_supplier_roles
erpnext.patches.v7_0.remove_administrator_role_in_doctypes
erpnext.patches.v7_0.rename_fee_amount_to_fee_component
@@ -324,7 +325,6 @@
erpnext.patches.v7_0.update_conversion_factor_in_supplier_quotation_item
erpnext.patches.v7_1.move_sales_invoice_from_parent_to_child_timesheet
execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null")
-erpnext.patches.v7_1.update_lead_source
erpnext.patches.v7_1.fix_link_for_customer_from_lead
execute:frappe.db.sql("delete from `tabTimesheet Detail` where NOT EXISTS (select name from `tabTimesheet` where name = `tabTimesheet Detail`.parent)")
erpnext.patches.v7_0.update_mode_of_payment_type
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 1a3c26c..65b9d26 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -297,7 +297,7 @@
def set_basic_rate_for_finished_goods(self, raw_material_cost, scrap_material_cost):
if self.purpose in ["Manufacture", "Repack"]:
for d in self.get("items"):
- if (d.bom_no or d.t_warehouse) and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse):
+ if d.transfer_qty and (d.bom_no or d.t_warehouse) and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse):
d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate"))
d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount"))
@@ -316,11 +316,10 @@
def update_valuation_rate(self):
for d in self.get("items"):
- d.amount = flt(flt(d.basic_amount) + flt(d.additional_cost), d.precision("amount"))
- d.valuation_rate = flt(
- flt(d.basic_rate)
- + (flt(d.additional_cost) / flt(d.transfer_qty)),
- d.precision("valuation_rate"))
+ if d.transfer_qty:
+ d.amount = flt(flt(d.basic_amount) + flt(d.additional_cost), d.precision("amount"))
+ d.valuation_rate = flt(flt(d.basic_rate) + (flt(d.additional_cost) / flt(d.transfer_qty)),
+ d.precision("valuation_rate"))
def set_total_incoming_outgoing_value(self):
self.total_incoming_value = self.total_outgoing_value = 0.0
@@ -681,7 +680,7 @@
for item in transferred_materials:
qty= item.qty
- if manufacturing_qty > (produced_qty + flt(self.fg_completed_qty)):
+ if trans_qty and manufacturing_qty > (produced_qty + flt(self.fg_completed_qty)):
qty = (qty/trans_qty) * flt(self.fg_completed_qty)
elif backflushed_materials.get(item.item_code):
@@ -819,7 +818,7 @@
"amount": operating_cost_per_unit * flt(fg_qty)
})
- if production_order and production_order.additional_operating_cost:
+ if production_order and production_order.additional_operating_cost and production_order.qty:
additional_operating_cost_per_unit = \
flt(production_order.additional_operating_cost) / flt(production_order.qty)
@@ -839,13 +838,14 @@
for d in production_order.get("operations"):
if flt(d.completed_qty):
operating_cost_per_unit += flt(d.actual_operating_cost) / flt(d.completed_qty)
- else:
+ elif production_order.qty:
operating_cost_per_unit += flt(d.planned_operating_cost) / flt(production_order.qty)
# Get operating cost from BOM if not found in production_order.
if not operating_cost_per_unit and bom_no:
bom = frappe.db.get_value("BOM", bom_no, ["operating_cost", "quantity"], as_dict=1)
- operating_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
+ if bom.quantity:
+ operating_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
return operating_cost_per_unit