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…

https://github.com/frappe/frappe/blob/develop/frappe/\_\_init\_\_.py#L358

https://github.com/frappe/frappe/blob/develop/frappe/\_\_init\_\_.py#L51

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

Could someone help?
ZeroDivisionError: float division by zero

App Versions

{
	"erpnext": "13.33.0",
	"erpnext_telegram_integration": "1.0.1",
	"frappe": "13.32.1",
	"nextcloud_integration": "0.0.1",
	"pdf_on_submit": "13.2",
	"posawesome": "3.3.0"
}

Route

Form/Loan Repayment/LM-REP-0002

Trackeback

Traceback (most recent call last):
  File "apps/frappe/frappe/desk/form/save.py", line 23, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 1018, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 1007, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 310, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 364, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1088, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 941, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1260, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1242, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 938, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 38, in on_submit
    self.update_repayment_schedule()
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 265, in update_repayment_schedule
    regenerate_repayment_schedule(self.against_loan, cancel)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 584, in regenerate_repayment_schedule
    balance_amount / len(loan_doc.get("repayment_schedule")) - accrued_entries
ZeroDivisionError: float division by zero

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 69, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 38, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 76, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1448, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 23, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 1018, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 1007, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 310, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 364, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1088, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 941, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1260, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1242, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 938, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 38, in on_submit
    self.update_repayment_schedule()
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 265, in update_repayment_schedule
    regenerate_repayment_schedule(self.against_loan, cancel)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 584, in regenerate_repayment_schedule
    balance_amount / len(loan_doc.get("repayment_schedule")) - accrued_entries
ZeroDivisionError: float division by zero

Request Data

{
	"type": "POST",
	"args": {
		"doc": "{\"name\":\"LM-REP-0002\",\"owner\":\"ahmdr2@hotmail.com\",\"creation\":\"2022-08-25 03:39:41.507214\",\"modified\":\"2022-08-25 03:39:41.507214\",\"modified_by\":\"ahmdr2@hotmail.com\",\"idx\":0,\"docstatus\":0,\"against_loan\":\"ACC-LOAN-2022-00004\",\"applicant_type\":\"Employee\",\"applicant\":\"HR-EMP-00008\",\"loan_type\":\"سلفةsd\",\"company\":\"صناعي\",\"posting_date\":\"2022-08-25 07:10:13\",\"rate_of_interest\":0,\"payroll_payable_account\":\"\",\"is_term_loan\":1,\"repay_from_salary\":0,\"pending_principal_amount\":70000,\"interest_payable\":0,\"payable_amount\":0,\"shortfall_amount\":0,\"payable_principal_amount\":0,\"penalty_amount\":0,\"amount_paid\":20000,\"cost_center\":\"Main - MFG\",\"principal_amount_paid\":20000,\"total_penalty_paid\":0,\"total_interest_paid\":0,\"payment_account\":\"1110 - Cash - MFG\",\"penalty_income_account\":\"4120 - Service - MFG\",\"loan_account\":\"1610 - Employee Advances - MFG\",\"doctype\":\"Loan Repayment\",\"repayment_details\":[],\"__onload\":{\"make_payment_via_journal_entry\":0}}",
		"action": "Submit"
	},
	"btn": {
		"jQuery224082196925272133561": {
			"events": {
				"click": [
					{
						"type": "click",
						"origType": "click",
						"guid": 2629,
						"namespace": ""
					}
				]
			}
		}
	},
	"freeze": true,
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.form.save.savedocs"
}

Response Data

{
	"exception": "ZeroDivisionError: float division by zero"
}