Try ERPNext Buy Support Partners Foundation

Stock Entry: Manufacture - ZeroDivisionError: float division by zero

ERPNext: v12.2.2
Frappe Framework: v12.0.20

This refers to a failed validation check

Please post the full traceback in text form to best define the problem context thanks!

edit: How frappe.throw(_("Increment for Attribute {0} cannot be 0").format(attribute)) recognizes this as ZeroDivisionError and omits the error message here beats me - pointers to how this Python ‘syntactic sugar’ underscore “_” works or doesn’t would help please!

The missing exception message looks like a language translation issue?

Note to self: Run this in a debugger to learn what is amiss here…

Any update on this?
I am getting same error since updating to
ERPNext: v12.4.2 (version-12)
Frappe Framework: v12.2.1 (version-12)

Welcome to ERPNext!

Thanks for reporting this - this may be due to a missed validation or a parameter value with a zero default that needs to be set.

Please copy and paste the complete error traceback here to look into where the problem lies.

If you have access to the server, the traceback can be found in the logs/ directory.

Hello!
I have the same problem since updating.

here is the error log:

[ERROR] 2020-01-29 11:23:08,384 | /home/frappe/frappe-bench/apps/frappe/frappe/app.py:
Site: fmc.test
Form Dict: {
“cmd”: “erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry”,
“purpose”: “Manufacture”,
“qty”: “5”,
“work_order_id”: “MFG-WO-2020-00001”
}
Request Error
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1042, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py”, line 675, in make_stock_entry
stock_entry.get_items()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 887, in get_items
self.calculate_rate_and_amount(raise_error_if_no_rate=False)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 419, in calculate_rate_and_amount
self.set_basic_rate(force, update_finished_item_rate, raise_error_if_no_rate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 462, in set_basic_rate
self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 490, in set_basic_rate_for_finished_goods
d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision(“basic_rate”))
ZeroDivisionError: float division by zero
[ERROR] 2020-01-29 17:17:46,666 | /home/frappe/frappe-bench/apps/frappe/frappe/app.py:
Site: site1.local
Form Dict: {
“cmd”: “erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry”,
“purpose”: “Manufacture”,
“qty”: “10”,
“work_order_id”: “MFG-WO-2020-00001”
}
Request Error
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1042, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py”, line 675, in make_stock_entry
stock_entry.get_items()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 887, in get_items
self.calculate_rate_and_amount(raise_error_if_no_rate=False)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 419, in calculate_rate_and_amount
self.set_basic_rate(force, update_finished_item_rate, raise_error_if_no_rate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 462, in set_basic_rate
self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 490, in set_basic_rate_for_finished_goods
d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision(“basic_rate”))
ZeroDivisionError: float division by zero

Thanks for posting!

Here for review is this change committed a week ago

Hello!
I think the problem is with “flt(d.transfer_qty)”
The error appears when I’m trying to finish the manufacturing order. it opens the form which select the quantity manufactured, but when you press create, the error pops up.
Probably it is not fetching the value.

I am not at all familiar with this use case or workflow process -

Whether users can say toggle off update_finished_item_rate, or transfer_qty can be 0 is legal in this context, and so on.

This code here may help inform users with ideas or clues:

I have two instances of Erpnext. The one with the problem is “production”, the other one is “develop”, and works well.
The workflow for manufacturing is : work order -> material transfer to WIP -> material consumption -> manufacture(stock entry - transfer of finished goods to warehouse). first two stock entries works fine, the last one not. The difference that I found between develop and production is that in develop, Item section has finished goods on the table, and in production has the raw materials used for manufacturing the goods. Probably the items are fetched from the wrong source.

in version12 code is:
if self.work_order
and frappe.db.get_single_value(“Manufacturing Settings”, “material_consumption”):
bom_items = self.get_bom_raw_materials(d.transfer_qty)
raw_material_cost = sum([flt(d.qty)*flt(d.rate) for d in bom_items.values()])

in develop code is:
if self.work_order
and frappe.db.get_single_value(“Manufacturing Settings”, “material_consumption”):
bom_items = self.get_bom_raw_materials(d.transfer_qty)
raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()])

from line 485 to line 488
raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()]) # in develop
vs
raw_material_cost = sum([flt(d.qty)*flt(d.rate) for d in bom_items.values()]) # in V12