Skip to content

Commit

Permalink
Merge pull request #43979 from khushi8112/correct-precision-for-asset…
Browse files Browse the repository at this point in the history
…-values

fix: added precision validation
  • Loading branch information
khushi8112 authored Nov 5, 2024
2 parents 29a1fe8 + 7daadcf commit f5a8e72
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Asset(AccountsController):
# end: auto-generated types

def validate(self):
self.validate_precision()
self.validate_asset_values()
self.validate_asset_and_reference()
self.validate_item()
Expand Down Expand Up @@ -307,6 +308,15 @@ def validate_finance_books(self):
title=_("Missing Finance Book"),
)

def validate_precision(self):
float_precision = cint(frappe.db.get_default("float_precision")) or 2
if self.gross_purchase_amount:
self.gross_purchase_amount = flt(self.gross_purchase_amount, float_precision)
if self.opening_accumulated_depreciation:
self.opening_accumulated_depreciation = flt(
self.opening_accumulated_depreciation, float_precision
)

def validate_asset_values(self):
if not self.asset_category:
self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category")
Expand Down Expand Up @@ -472,6 +482,9 @@ def set_total_booked_depreciations(self):

def validate_expected_value_after_useful_life(self):
for row in self.get("finance_books"):
row.expected_value_after_useful_life = flt(
row.expected_value_after_useful_life, self.precision("gross_purchase_amount")
)
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)

if not depr_schedule:
Expand Down

0 comments on commit f5a8e72

Please sign in to comment.