Skip to content

Commit

Permalink
Merge pull request frappe#44854 from khushi8112/asset-fields-precisio…
Browse files Browse the repository at this point in the history
…n-check

fix: asset fields precision check
  • Loading branch information
khushi8112 authored Dec 23, 2024
2 parents 948556d + 2f7e623 commit 0b1c320
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
12 changes: 5 additions & 7 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,14 @@ def validate_finance_books(self):
)

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)
self.gross_purchase_amount = flt(
self.gross_purchase_amount, self.precision("gross_purchase_amount")
)

if self.opening_accumulated_depreciation:
self.opening_accumulated_depreciation = flt(
self.opening_accumulated_depreciation, float_precision
self.opening_accumulated_depreciation, self.precision("opening_accumulated_depreciation")
)

def validate_asset_values(self):
Expand Down Expand Up @@ -488,11 +490,7 @@ 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:
continue

Expand Down
2 changes: 1 addition & 1 deletion erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def test_pro_rata_depreciation_entry_for_wdv(self):
["2030-12-31", 28630.14, 28630.14],
["2031-12-31", 35684.93, 64315.07],
["2032-12-31", 17842.46, 82157.53],
["2033-06-06", 5342.46, 87499.99],
["2033-06-06", 5342.47, 87500.00],
]

schedules = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _make_depr_schedule(
date_of_disposal,
original_schedule_date=schedule_date,
)

depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
if depreciation_amount > 0:
self.add_depr_schedule_row(date_of_disposal, depreciation_amount, n)

Expand Down Expand Up @@ -430,6 +430,7 @@ def _make_depr_schedule(

if not depreciation_amount:
continue
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
value_after_depreciation = flt(
value_after_depreciation - flt(depreciation_amount),
asset_doc.precision("gross_purchase_amount"),
Expand All @@ -443,6 +444,7 @@ def _make_depr_schedule(
depreciation_amount += flt(value_after_depreciation) - flt(
row.expected_value_after_useful_life
)
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
skip_row = True

if flt(depreciation_amount, asset_doc.precision("gross_purchase_amount")) > 0:
Expand Down Expand Up @@ -517,10 +519,13 @@ def set_accumulated_depreciation(
i - 1
].accumulated_depreciation_amount
else:
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
accumulated_depreciation = flt(
self.opening_accumulated_depreciation,
asset_doc.precision("opening_accumulated_depreciation"),
)

depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
value_after_depreciation -= flt(depreciation_amount)
value_after_depreciation -= flt(d.depreciation_amount)
value_after_depreciation = flt(value_after_depreciation, d.precision("depreciation_amount"))

# for the last row, if depreciation method = Straight Line
if (
Expand All @@ -530,12 +535,11 @@ def set_accumulated_depreciation(
and not date_of_return
and not row.shift_based
):
depreciation_amount += flt(
d.depreciation_amount += flt(
value_after_depreciation - flt(row.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")
Expand Down

0 comments on commit 0b1c320

Please sign in to comment.