[fix] Unable to create an asset due to rounding issue
This commit is contained in:
parent
b674d27285
commit
3df7eef6cc
@ -114,8 +114,17 @@ class Asset(Document):
|
|||||||
|
|
||||||
def set_accumulated_depreciation(self):
|
def set_accumulated_depreciation(self):
|
||||||
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
||||||
for d in self.get("schedules"):
|
value_after_depreciation = flt(self.value_after_depreciation)
|
||||||
accumulated_depreciation += flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
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"))
|
d.accumulated_depreciation_amount = flt(accumulated_depreciation, d.precision("accumulated_depreciation_amount"))
|
||||||
|
|
||||||
def get_depreciation_amount(self, depreciable_value):
|
def get_depreciation_amount(self, depreciable_value):
|
||||||
|
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import unittest
|
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.depreciation import post_depreciation_entries, scrap_asset, restore_asset
|
||||||
from erpnext.accounts.doctype.asset.asset import make_sales_invoice, make_purchase_invoice
|
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")
|
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):
|
def tearDown(self):
|
||||||
asset = frappe.get_doc("Asset", "Macbook Pro 1")
|
asset = frappe.get_doc("Asset", "Macbook Pro 1")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user