fix: incorrect depr schedules after asset repair [v13] (#34520)
* fix: incorrect schedule after repair for WDV and DD * chore: only fix schedules for assets with calc_depr true * fix: incorrect schedule after repair for straight line and manual
This commit is contained in:
@@ -387,10 +387,14 @@ class Asset(AccountsController):
|
|||||||
)
|
)
|
||||||
or value_after_depreciation < finance_book.expected_value_after_useful_life
|
or value_after_depreciation < finance_book.expected_value_after_useful_life
|
||||||
):
|
):
|
||||||
depreciation_amount += (
|
if (
|
||||||
value_after_depreciation - finance_book.expected_value_after_useful_life
|
not self.flags.increase_in_asset_value_due_to_repair
|
||||||
)
|
or not finance_book.depreciation_method in ("Written Down Value", "Double Declining Balance")
|
||||||
skip_row = True
|
):
|
||||||
|
depreciation_amount += (
|
||||||
|
value_after_depreciation - finance_book.expected_value_after_useful_life
|
||||||
|
)
|
||||||
|
skip_row = True
|
||||||
|
|
||||||
if depreciation_amount > 0:
|
if depreciation_amount > 0:
|
||||||
self.append(
|
self.append(
|
||||||
@@ -1171,17 +1175,21 @@ def get_total_days(date, frequency):
|
|||||||
@erpnext.allow_regional
|
@erpnext.allow_regional
|
||||||
def get_depreciation_amount(asset, depreciable_value, row):
|
def get_depreciation_amount(asset, depreciable_value, row):
|
||||||
if row.depreciation_method in ("Straight Line", "Manual"):
|
if row.depreciation_method in ("Straight Line", "Manual"):
|
||||||
# if the Depreciation Schedule is being prepared for the first time
|
# if the Depreciation Schedule is being modified after Asset Repair due to increase in asset life and value
|
||||||
if not asset.flags.increase_in_asset_life:
|
if asset.flags.increase_in_asset_life:
|
||||||
depreciation_amount = (
|
|
||||||
flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
|
||||||
) / flt(row.total_number_of_depreciations)
|
|
||||||
|
|
||||||
# if the Depreciation Schedule is being modified after Asset Repair
|
|
||||||
else:
|
|
||||||
depreciation_amount = (
|
depreciation_amount = (
|
||||||
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||||
) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
||||||
|
# if the Depreciation Schedule is being modified after Asset Repair due to increase in asset value
|
||||||
|
elif asset.flags.increase_in_asset_value_due_to_repair:
|
||||||
|
depreciation_amount = (
|
||||||
|
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||||
|
) / flt(row.total_number_of_depreciations)
|
||||||
|
# if the Depreciation Schedule is being prepared for the first time
|
||||||
|
else:
|
||||||
|
depreciation_amount = (
|
||||||
|
flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
||||||
|
) / flt(row.total_number_of_depreciations)
|
||||||
else:
|
else:
|
||||||
depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100))
|
depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100))
|
||||||
|
|
||||||
|
|||||||
@@ -39,47 +39,61 @@ class AssetRepair(AccountsController):
|
|||||||
def before_submit(self):
|
def before_submit(self):
|
||||||
self.check_repair_status()
|
self.check_repair_status()
|
||||||
|
|
||||||
|
self.asset_doc.flags.increase_in_asset_value_due_to_repair = False
|
||||||
|
|
||||||
if self.get("stock_consumption") or self.get("capitalize_repair_cost"):
|
if self.get("stock_consumption") or self.get("capitalize_repair_cost"):
|
||||||
|
self.asset_doc.flags.increase_in_asset_value_due_to_repair = True
|
||||||
|
|
||||||
self.increase_asset_value()
|
self.increase_asset_value()
|
||||||
|
|
||||||
if self.get("stock_consumption"):
|
if self.get("stock_consumption"):
|
||||||
self.check_for_stock_items_and_warehouse()
|
self.check_for_stock_items_and_warehouse()
|
||||||
self.decrease_stock_quantity()
|
self.decrease_stock_quantity()
|
||||||
|
|
||||||
|
calculate_asset_depreciation = frappe.db.get_value(
|
||||||
|
"Asset", self.asset, "calculate_depreciation"
|
||||||
|
)
|
||||||
|
|
||||||
if self.get("capitalize_repair_cost"):
|
if self.get("capitalize_repair_cost"):
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
|
|
||||||
if (
|
if calculate_asset_depreciation and self.increase_in_asset_life:
|
||||||
frappe.db.get_value("Asset", self.asset, "calculate_depreciation")
|
|
||||||
and self.increase_in_asset_life
|
|
||||||
):
|
|
||||||
self.modify_depreciation_schedule()
|
self.modify_depreciation_schedule()
|
||||||
|
|
||||||
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
||||||
self.asset_doc.prepare_depreciation_data()
|
self.asset_doc.prepare_depreciation_data()
|
||||||
|
if calculate_asset_depreciation:
|
||||||
|
self.update_asset_expected_value_after_useful_life()
|
||||||
self.asset_doc.save()
|
self.asset_doc.save()
|
||||||
|
|
||||||
def before_cancel(self):
|
def before_cancel(self):
|
||||||
self.asset_doc = frappe.get_doc("Asset", self.asset)
|
self.asset_doc = frappe.get_doc("Asset", self.asset)
|
||||||
|
|
||||||
|
self.asset_doc.flags.increase_in_asset_value_due_to_repair = False
|
||||||
|
|
||||||
if self.get("stock_consumption") or self.get("capitalize_repair_cost"):
|
if self.get("stock_consumption") or self.get("capitalize_repair_cost"):
|
||||||
|
self.asset_doc.flags.increase_in_asset_value_due_to_repair = True
|
||||||
|
|
||||||
self.decrease_asset_value()
|
self.decrease_asset_value()
|
||||||
|
|
||||||
if self.get("stock_consumption"):
|
if self.get("stock_consumption"):
|
||||||
self.increase_stock_quantity()
|
self.increase_stock_quantity()
|
||||||
|
|
||||||
|
calculate_asset_depreciation = frappe.db.get_value(
|
||||||
|
"Asset", self.asset, "calculate_depreciation"
|
||||||
|
)
|
||||||
|
|
||||||
if self.get("capitalize_repair_cost"):
|
if self.get("capitalize_repair_cost"):
|
||||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
||||||
self.make_gl_entries(cancel=True)
|
self.make_gl_entries(cancel=True)
|
||||||
|
|
||||||
if (
|
if calculate_asset_depreciation and self.increase_in_asset_life:
|
||||||
frappe.db.get_value("Asset", self.asset, "calculate_depreciation")
|
|
||||||
and self.increase_in_asset_life
|
|
||||||
):
|
|
||||||
self.revert_depreciation_schedule_on_cancellation()
|
self.revert_depreciation_schedule_on_cancellation()
|
||||||
|
|
||||||
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
||||||
self.asset_doc.prepare_depreciation_data()
|
self.asset_doc.prepare_depreciation_data()
|
||||||
|
if calculate_asset_depreciation:
|
||||||
|
self.update_asset_expected_value_after_useful_life()
|
||||||
self.asset_doc.save()
|
self.asset_doc.save()
|
||||||
|
|
||||||
def after_delete(self):
|
def after_delete(self):
|
||||||
@@ -100,6 +114,26 @@ class AssetRepair(AccountsController):
|
|||||||
title=_("Missing Warehouse"),
|
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):
|
def increase_asset_value(self):
|
||||||
total_value_of_stock_consumed = self.get_total_value_of_stock_consumed()
|
total_value_of_stock_consumed = self.get_total_value_of_stock_consumed()
|
||||||
|
|
||||||
|
|||||||
@@ -1101,18 +1101,21 @@ def update_taxable_values(doc, method):
|
|||||||
|
|
||||||
def get_depreciation_amount(asset, depreciable_value, row):
|
def get_depreciation_amount(asset, depreciable_value, row):
|
||||||
if row.depreciation_method in ("Straight Line", "Manual"):
|
if row.depreciation_method in ("Straight Line", "Manual"):
|
||||||
# if the Depreciation Schedule is being prepared for the first time
|
# if the Depreciation Schedule is being modified after Asset Repair due to increase in asset life and value
|
||||||
if not asset.flags.increase_in_asset_life:
|
if asset.flags.increase_in_asset_life:
|
||||||
depreciation_amount = (
|
|
||||||
flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
|
||||||
) / flt(row.total_number_of_depreciations)
|
|
||||||
|
|
||||||
# if the Depreciation Schedule is being modified after Asset Repair
|
|
||||||
else:
|
|
||||||
depreciation_amount = (
|
depreciation_amount = (
|
||||||
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||||
) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
||||||
|
# if the Depreciation Schedule is being modified after Asset Repair due to increase in asset value
|
||||||
|
elif asset.flags.increase_in_asset_value_due_to_repair:
|
||||||
|
depreciation_amount = (
|
||||||
|
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||||
|
) / flt(row.total_number_of_depreciations)
|
||||||
|
# if the Depreciation Schedule is being prepared for the first time
|
||||||
|
else:
|
||||||
|
depreciation_amount = (
|
||||||
|
flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
||||||
|
) / flt(row.total_number_of_depreciations)
|
||||||
else:
|
else:
|
||||||
rate_of_depreciation = row.rate_of_depreciation
|
rate_of_depreciation = row.rate_of_depreciation
|
||||||
# if its the first depreciation
|
# if its the first depreciation
|
||||||
|
|||||||
Reference in New Issue
Block a user