Validate expected value after useful life

This commit is contained in:
Nabin Hait 2016-07-05 15:36:11 +05:30
parent e3e1b80fcc
commit cea353a638

View File

@ -18,6 +18,7 @@ class Asset(Document):
self.validate_asset_values() self.validate_asset_values()
self.set_depreciation_settings() self.set_depreciation_settings()
self.make_depreciation_schedule() self.make_depreciation_schedule()
self.validate_expected_value_after_useful_life()
# Validate depreciation related accounts # Validate depreciation related accounts
get_depreciation_accounts(self) get_depreciation_accounts(self)
@ -125,6 +126,18 @@ class Asset(Document):
return depreciation_amount return depreciation_amount
def validate_expected_value_after_useful_life(self):
if self.depreciation_method == "Double Declining Balance":
accumulated_depreciation_after_full_schedule = \
max([d.accumulated_depreciation_amount for d in self.get("schedules")])
asset_value_after_full_schedule = (flt(self.gross_purchase_amount) -
flt(accumulated_depreciation_after_full_schedule))
if self.expected_value_after_useful_life < asset_value_after_full_schedule:
frappe.throw(_("Expected value after useful life must be greater than or equal to {0}")
.format(asset_value_after_full_schedule))
def validate_cancellation(self): def validate_cancellation(self):
if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"): if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"):
frappe.throw(_("Asset cannot be cancelled, as it is already {0}").format(self.status)) frappe.throw(_("Asset cannot be cancelled, as it is already {0}").format(self.status))