mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 21:19:19 +00:00
Merge pull request #44871 from frappe/mergify/bp/version-15-hotfix/pr-44854
fix: asset fields precision check (backport #44854)
This commit is contained in:
@@ -308,12 +308,14 @@ class Asset(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def validate_precision(self):
|
def validate_precision(self):
|
||||||
float_precision = cint(frappe.db.get_default("float_precision")) or 2
|
|
||||||
if self.gross_purchase_amount:
|
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:
|
if self.opening_accumulated_depreciation:
|
||||||
self.opening_accumulated_depreciation = flt(
|
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):
|
def validate_asset_values(self):
|
||||||
@@ -487,11 +489,7 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
def validate_expected_value_after_useful_life(self):
|
def validate_expected_value_after_useful_life(self):
|
||||||
for row in self.get("finance_books"):
|
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)
|
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)
|
||||||
|
|
||||||
if not depr_schedule:
|
if not depr_schedule:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -889,7 +889,7 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
["2030-12-31", 28630.14, 28630.14],
|
["2030-12-31", 28630.14, 28630.14],
|
||||||
["2031-12-31", 35684.93, 64315.07],
|
["2031-12-31", 35684.93, 64315.07],
|
||||||
["2032-12-31", 17842.46, 82157.53],
|
["2032-12-31", 17842.46, 82157.53],
|
||||||
["2033-06-06", 5342.46, 87499.99],
|
["2033-06-06", 5342.47, 87500.00],
|
||||||
]
|
]
|
||||||
|
|
||||||
schedules = [
|
schedules = [
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
date_of_disposal,
|
date_of_disposal,
|
||||||
original_schedule_date=schedule_date,
|
original_schedule_date=schedule_date,
|
||||||
)
|
)
|
||||||
|
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
|
||||||
if depreciation_amount > 0:
|
if depreciation_amount > 0:
|
||||||
self.add_depr_schedule_row(date_of_disposal, depreciation_amount, n)
|
self.add_depr_schedule_row(date_of_disposal, depreciation_amount, n)
|
||||||
|
|
||||||
@@ -430,6 +430,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
|
|
||||||
if not depreciation_amount:
|
if not depreciation_amount:
|
||||||
continue
|
continue
|
||||||
|
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
|
||||||
value_after_depreciation = flt(
|
value_after_depreciation = flt(
|
||||||
value_after_depreciation - flt(depreciation_amount),
|
value_after_depreciation - flt(depreciation_amount),
|
||||||
asset_doc.precision("gross_purchase_amount"),
|
asset_doc.precision("gross_purchase_amount"),
|
||||||
@@ -443,6 +444,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
depreciation_amount += flt(value_after_depreciation) - flt(
|
depreciation_amount += flt(value_after_depreciation) - flt(
|
||||||
row.expected_value_after_useful_life
|
row.expected_value_after_useful_life
|
||||||
)
|
)
|
||||||
|
depreciation_amount = flt(depreciation_amount, asset_doc.precision("gross_purchase_amount"))
|
||||||
skip_row = True
|
skip_row = True
|
||||||
|
|
||||||
if flt(depreciation_amount, asset_doc.precision("gross_purchase_amount")) > 0:
|
if flt(depreciation_amount, asset_doc.precision("gross_purchase_amount")) > 0:
|
||||||
@@ -517,10 +519,13 @@ class AssetDepreciationSchedule(Document):
|
|||||||
i - 1
|
i - 1
|
||||||
].accumulated_depreciation_amount
|
].accumulated_depreciation_amount
|
||||||
else:
|
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(d.depreciation_amount)
|
||||||
value_after_depreciation -= flt(depreciation_amount)
|
value_after_depreciation = flt(value_after_depreciation, d.precision("depreciation_amount"))
|
||||||
|
|
||||||
# for the last row, if depreciation method = Straight Line
|
# for the last row, if depreciation method = Straight Line
|
||||||
if (
|
if (
|
||||||
@@ -530,12 +535,11 @@ class AssetDepreciationSchedule(Document):
|
|||||||
and not date_of_return
|
and not date_of_return
|
||||||
and not row.shift_based
|
and not row.shift_based
|
||||||
):
|
):
|
||||||
depreciation_amount += flt(
|
d.depreciation_amount += flt(
|
||||||
value_after_depreciation - flt(row.expected_value_after_useful_life),
|
value_after_depreciation - flt(row.expected_value_after_useful_life),
|
||||||
d.precision("depreciation_amount"),
|
d.precision("depreciation_amount"),
|
||||||
)
|
)
|
||||||
|
|
||||||
d.depreciation_amount = depreciation_amount
|
|
||||||
accumulated_depreciation += d.depreciation_amount
|
accumulated_depreciation += d.depreciation_amount
|
||||||
d.accumulated_depreciation_amount = flt(
|
d.accumulated_depreciation_amount = flt(
|
||||||
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
||||||
|
|||||||
Reference in New Issue
Block a user