From 3df7eef6cc607f7707e287fc6cff450ca069e23a Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 1 May 2017 18:52:11 +0530 Subject: [PATCH] [fix] Unable to create an asset due to rounding issue --- erpnext/accounts/doctype/asset/asset.py | 13 +++++++++++-- erpnext/accounts/doctype/asset/test_asset.py | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/asset/asset.py b/erpnext/accounts/doctype/asset/asset.py index aa2768b879..070461eb91 100644 --- a/erpnext/accounts/doctype/asset/asset.py +++ b/erpnext/accounts/doctype/asset/asset.py @@ -114,8 +114,17 @@ class Asset(Document): def set_accumulated_depreciation(self): accumulated_depreciation = flt(self.opening_accumulated_depreciation) - for d in self.get("schedules"): - accumulated_depreciation += flt(d.depreciation_amount, d.precision("depreciation_amount")) + value_after_depreciation = flt(self.value_after_depreciation) + for i, d in enumerate(self.get("schedules")): + depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount")) + value_after_depreciation -= flt(depreciation_amount) + + if i==len(self.get("schedules"))-1 and self.depreciation_method == "Straight Line": + depreciation_amount += flt(value_after_depreciation - flt(self.expected_value_after_useful_life), + d.precision("depreciation_amount")) + + d.depreciation_amount = depreciation_amount + accumulated_depreciation += d.depreciation_amount d.accumulated_depreciation_amount = flt(accumulated_depreciation, d.precision("accumulated_depreciation_amount")) def get_depreciation_amount(self, depreciable_value): diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py index 000bc5ccd2..a45cdcea91 100644 --- a/erpnext/accounts/doctype/asset/test_asset.py +++ b/erpnext/accounts/doctype/asset/test_asset.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe import unittest -from frappe.utils import cstr, nowdate, getdate +from frappe.utils import cstr, nowdate, getdate, flt from erpnext.accounts.doctype.asset.depreciation import post_depreciation_entries, scrap_asset, restore_asset from erpnext.accounts.doctype.asset.asset import make_sales_invoice, make_purchase_invoice @@ -243,6 +243,23 @@ class TestAsset(unittest.TestCase): self.assertEqual(frappe.db.get_value("Asset", "Macbook Pro 1", "status"), "Partially Depreciated") + def test_asset_expected_value_after_useful_life(self): + asset = frappe.get_doc("Asset", "Macbook Pro 1") + asset.depreciation_method = "Straight Line" + asset.is_existing_asset = 1 + asset.total_number_of_depreciations = 400 + asset.gross_purchase_amount = 16866177.00 + asset.expected_value_after_useful_life = 500000 + asset.save() + + accumulated_depreciation_after_full_schedule = \ + max([d.accumulated_depreciation_amount for d in asset.get("schedules")]) + + asset_value_after_full_schedule = (flt(asset.gross_purchase_amount) - + flt(accumulated_depreciation_after_full_schedule)) + + self.assertTrue(asset.expected_value_after_useful_life >= asset_value_after_full_schedule) + def tearDown(self): asset = frappe.get_doc("Asset", "Macbook Pro 1")