Skip to content

Commit 516a325

Browse files
khushi8112mergify[bot]
authored andcommitted
fix: asset field precision check
(cherry picked from commit 92b8768)
1 parent d6001e5 commit 516a325

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

erpnext/assets/doctype/asset/asset.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,14 @@ def validate_finance_books(self):
308308
)
309309

310310
def validate_precision(self):
311-
float_precision = cint(frappe.db.get_default("float_precision")) or 2
312311
if self.gross_purchase_amount:
313-
self.gross_purchase_amount = flt(self.gross_purchase_amount, float_precision)
312+
self.gross_purchase_amount = flt(
313+
self.gross_purchase_amount, self.precision("gross_purchase_amount")
314+
)
315+
314316
if self.opening_accumulated_depreciation:
315317
self.opening_accumulated_depreciation = flt(
316-
self.opening_accumulated_depreciation, float_precision
318+
self.opening_accumulated_depreciation, self.precision("opening_accumulated_depreciation")
317319
)
318320

319321
def validate_asset_values(self):
@@ -487,11 +489,7 @@ def set_total_booked_depreciations(self):
487489

488490
def validate_expected_value_after_useful_life(self):
489491
for row in self.get("finance_books"):
490-
row.expected_value_after_useful_life = flt(
491-
row.expected_value_after_useful_life, self.precision("gross_purchase_amount")
492-
)
493492
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)
494-
495493
if not depr_schedule:
496494
continue
497495

erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def _make_depr_schedule(
430430

431431
if not depreciation_amount:
432432
continue
433+
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
433434
value_after_depreciation = flt(
434435
value_after_depreciation - flt(depreciation_amount),
435436
asset_doc.precision("gross_purchase_amount"),
@@ -443,6 +444,7 @@ def _make_depr_schedule(
443444
depreciation_amount += flt(value_after_depreciation) - flt(
444445
row.expected_value_after_useful_life
445446
)
447+
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
446448
skip_row = True
447449

448450
if flt(depreciation_amount, asset_doc.precision("gross_purchase_amount")) > 0:
@@ -517,10 +519,13 @@ def set_accumulated_depreciation(
517519
i - 1
518520
].accumulated_depreciation_amount
519521
else:
520-
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
522+
accumulated_depreciation = flt(
523+
self.opening_accumulated_depreciation,
524+
asset_doc.precision("opening_accumulated_depreciation"),
525+
)
521526

522-
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
523-
value_after_depreciation -= flt(depreciation_amount)
527+
value_after_depreciation -= flt(d.depreciation_amount)
528+
value_after_depreciation = flt(value_after_depreciation, d.precision("depreciation_amount"))
524529

525530
# for the last row, if depreciation method = Straight Line
526531
if (
@@ -530,12 +535,11 @@ def set_accumulated_depreciation(
530535
and not date_of_return
531536
and not row.shift_based
532537
):
533-
depreciation_amount += flt(
538+
d.depreciation_amount += flt(
534539
value_after_depreciation - flt(row.expected_value_after_useful_life),
535540
d.precision("depreciation_amount"),
536541
)
537542

538-
d.depreciation_amount = depreciation_amount
539543
accumulated_depreciation += d.depreciation_amount
540544
d.accumulated_depreciation_amount = flt(
541545
accumulated_depreciation, d.precision("accumulated_depreciation_amount")

0 commit comments

Comments
 (0)