Skip to content

Commit

Permalink
fix: recalculate WDV rate after asset repair [v13] (#34567)
Browse files Browse the repository at this point in the history
fix: recalculate wdv rate after asset repair
  • Loading branch information
anandbaburajan committed Mar 23, 2023
1 parent 7f83d15 commit c8bde39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
30 changes: 16 additions & 14 deletions erpnext/assets/doctype/asset/asset.py
Expand Up @@ -380,19 +380,12 @@ def make_depreciation_schedule(self, 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
Expand Down Expand Up @@ -903,10 +896,19 @@ 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))

Expand Down
24 changes: 0 additions & 24 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Expand Up @@ -58,8 +58,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 @@ -84,8 +82,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 @@ -106,26 +102,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 c8bde39

Please sign in to comment.