ZeroDivisionError: Float Division by zero

I have been stuck at this error for some time now in the loan module when I try to post repayments. I keep getting this error can anyone help me who can advise on workaround. I have pasted the error below…

App Versions

{
	"drive": "0.0.1",
	"erpnext": "14.0.0-beta.7",
	"frappe": "14.0.0-beta.6",
	"hrms": "1.0.0",
	"payments": "0.0.1"
}

Route

Form/Loan Repayment/LM-REP-4157

Trackeback

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 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 83, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1581, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 20, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 1014, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 993, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 300, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 351, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1089, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 927, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1267, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1249, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 924, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 37, in on_submit
    self.update_repayment_schedule()
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 264, in update_repayment_schedule
    regenerate_repayment_schedule(self.against_loan, cancel)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py", line 587, 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-4157\",\"owner\":\"peckinsk@eduloan.co.za\",\"creation\":\"2022-12-12 01:57:19.366953\",\"modified\":\"2022-12-12 15:25:18.510015\",\"modified_by\":\"peckinsk@eduloan.co.za\",\"docstatus\":0,\"idx\":0,\"against_loan\":\"ACC-LOAN-2022-04360\",\"applicant_type\":\"Customer\",\"applicant\":\"Denboy Mweni\",\"loan_type\":\"Demo Initiation\",\"company\":\"Demo Eduloan\",\"posting_date\":\"2022-01-31 00:00:00\",\"rate_of_interest\":84,\"is_term_loan\":1,\"repay_from_salary\":0,\"pending_principal_amount\":-2805.87,\"interest_payable\":0,\"payable_amount\":0,\"outstanding_balance_amount\":0,\"shortfall_amount\":0,\"payable_principal_amount\":0,\"penalty_amount\":0,\"amount_paid\":3261,\"cost_center\":\"Main - DEMO\",\"reference_number\":\"3262\",\"principal_amount_paid\":3261,\"total_penalty_paid\":0,\"total_interest_paid\":0,\"payment_account\":\"800250 - Institutional Creditors - DEMO\",\"penalty_income_account\":\"100200 - Account Finalisation Adjustment - DEMO\",\"loan_account\":\"630700 - Loan Advances - DEMO\",\"doctype\":\"Loan Repayment\",\"repayment_details\":[],\"__onload\":{\"make_payment_via_journal_entry\":0}}",
		"action": "Submit"
	},
	"btn": {
		"jQuery3600214862094829928681": {
			"events": {
				"click": [
					{
						"type": "click",
						"origType": "click",
						"guid": 911,
						"namespace": ""
					}
				]
			}
		}
	},
	"freeze": true,
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.form.save.savedocs"
}

Response Data

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

Hello @charleyarnold, It’s because of one of the field getting zero instead of some value while dividing balance_amount/len(loan_doc.get(“repayment_schedule”))

Please check these field value manually or put print statement to debug it.

Hi all the fields have a value, I have tripple checked and quad checked am failing to find the cause

Have you done any customisation? Also is this available on server so create one user and share credentials I will check and let you know.

1 Like

So I have created a new loan and went through all the stages again and i discovered when my team was capturing they were skipping the loan disbursement stage and I suspect its the one causing the zero fields. If I still have a challenge I will create a user and through the details