Skip to content

Commit

Permalink
fix: recalculate WDV rate after asset repair [v14] (#34571)
Browse files Browse the repository at this point in the history
fix: recalculate wdv rate after asset repair
  • Loading branch information
anandbaburajan authored Mar 23, 2023
1 parent db01bf5 commit d2ca6f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
32 changes: 18 additions & 14 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,12 @@ def _make_depreciation_schedule(self, finance_book, start, date_of_disposal):
value_after_depreciation -= flt(depreciation_amount, self.precision("gross_purchase_amount"))

# Adjust depreciation amount in the last period based on the expected value after useful life
if (
finance_book.expected_value_after_useful_life
and (
(
n == cint(number_of_pending_depreciations) - 1
and value_after_depreciation != finance_book.expected_value_after_useful_life
)
or value_after_depreciation < finance_book.expected_value_after_useful_life
)
and (
not self.flags.increase_in_asset_value_due_to_repair
or not finance_book.depreciation_method in ("Written Down Value", "Double Declining Balance")
if finance_book.expected_value_after_useful_life and (
(
n == cint(number_of_pending_depreciations) - 1
and value_after_depreciation != finance_book.expected_value_after_useful_life
)
or value_after_depreciation < finance_book.expected_value_after_useful_life
):
depreciation_amount += value_after_depreciation - finance_book.expected_value_after_useful_life
skip_row = True
Expand Down Expand Up @@ -913,11 +906,22 @@ def get_depreciation_rate(self, args, on_validate=False):
return 200.0 / args.get("total_number_of_depreciations")

if args.get("depreciation_method") == "Written Down Value":
if args.get("rate_of_depreciation") and on_validate:
if (
args.get("rate_of_depreciation")
and on_validate
and not self.flags.increase_in_asset_value_due_to_repair
):
return args.get("rate_of_depreciation")

value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount)
if self.flags.increase_in_asset_value_due_to_repair:
value = flt(args.get("expected_value_after_useful_life")) / flt(
args.get("value_after_depreciation")
)
else:
value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount)

depreciation_rate = math.pow(value, 1.0 / flt(args.get("total_number_of_depreciations"), 2))

return flt((100 * (1 - depreciation_rate)), float_precision)

def get_pro_rata_amt(self, row, depreciation_amount, from_date, to_date):
Expand Down
24 changes: 0 additions & 24 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def before_submit(self):

self.asset_doc.flags.ignore_validate_update_after_submit = True
self.asset_doc.prepare_depreciation_data()
if self.asset_doc.calculate_depreciation:
self.update_asset_expected_value_after_useful_life()
self.asset_doc.save()

def before_cancel(self):
Expand All @@ -81,8 +79,6 @@ def before_cancel(self):

self.asset_doc.flags.ignore_validate_update_after_submit = True
self.asset_doc.prepare_depreciation_data()
if self.asset_doc.calculate_depreciation:
self.update_asset_expected_value_after_useful_life()
self.asset_doc.save()

def after_delete(self):
Expand All @@ -103,26 +99,6 @@ def check_for_stock_items_and_warehouse(self):
title=_("Missing Warehouse"),
)

def update_asset_expected_value_after_useful_life(self):
for row in self.asset_doc.get("finance_books"):
if row.depreciation_method in ("Written Down Value", "Double Declining Balance"):
accumulated_depreciation_after_full_schedule = [
d.accumulated_depreciation_amount
for d in self.asset_doc.get("schedules")
if cint(d.finance_book_id) == row.idx
]

accumulated_depreciation_after_full_schedule = max(
accumulated_depreciation_after_full_schedule
)

asset_value_after_full_schedule = flt(
flt(row.value_after_depreciation) - flt(accumulated_depreciation_after_full_schedule),
row.precision("expected_value_after_useful_life"),
)

row.expected_value_after_useful_life = asset_value_after_full_schedule

def increase_asset_value(self):
total_value_of_stock_consumed = self.get_total_value_of_stock_consumed()

Expand Down

0 comments on commit d2ca6f8

Please sign in to comment.