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"


Form/Loan Repayment/LM-REP-4157


Traceback (most recent call last):
  File "apps/frappe/frappe/", line 69, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/", line 83, in execute_cmd
    return, **frappe.form_dict)
  File "apps/frappe/frappe/", line 1581, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/", line 20, in savedocs
  File "apps/frappe/frappe/model/", line 1014, in submit
    return self._submit()
  File "apps/frappe/frappe/model/", line 993, in _submit
  File "apps/frappe/frappe/model/", line 300, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/", line 351, in _save
  File "apps/frappe/frappe/model/", line 1089, in run_post_save_methods
  File "apps/frappe/frappe/model/", line 927, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/", line 1267, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/", line 1249, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/", line 924, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/", line 37, in on_submit
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/", line 264, in update_repayment_schedule
    regenerate_repayment_schedule(self.against_loan, cancel)
  File "apps/erpnext/erpnext/loan_management/doctype/loan_repayment/", 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\":\"\",\"creation\":\"2022-12-12 01:57:19.366953\",\"modified\":\"2022-12-12 15:25:18.510015\",\"modified_by\":\"\",\"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/"

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