From 210317c0b5e8cb50d7226fc9a796adfe9ec3be5e Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Fri, 23 Aug 2019 00:21:26 +0530 Subject: [PATCH] fix: division by zero in asset Depereciation (#18637) * fix: division by zero in asset Depereciation * fix: requested changes --- erpnext/assets/doctype/asset/asset.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 45d2ec2c51..ab37e91538 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -255,9 +255,15 @@ class Asset(AccountsController): precision = self.precision("gross_purchase_amount") if row.depreciation_method in ("Straight Line", "Manual"): + depreciation_left = (cint(row.total_number_of_depreciations) - cint(self.number_of_depreciations_booked)) + + if not depreciation_left: + frappe.msgprint(_("All the depreciations has been booked")) + depreciation_amount = flt(row.expected_value_after_useful_life) + return depreciation_amount + depreciation_amount = (flt(row.value_after_depreciation) - - flt(row.expected_value_after_useful_life)) / (cint(row.total_number_of_depreciations) - - cint(self.number_of_depreciations_booked)) + flt(row.expected_value_after_useful_life)) / depreciation_left else: depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100), precision) @@ -275,7 +281,7 @@ class Asset(AccountsController): flt(accumulated_depreciation_after_full_schedule), self.precision('gross_purchase_amount')) - if (row.expected_value_after_useful_life and + if (row.expected_value_after_useful_life and row.expected_value_after_useful_life < asset_value_after_full_schedule): frappe.throw(_("Depreciation Row {0}: Expected value after useful life must be greater than or equal to {1}") .format(row.idx, asset_value_after_full_schedule))