mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-14 07:47:12 +00:00
fix: Update depreciation schedule via asset repair (#41344)
* fix: Update depreciation schedule via asset repair * fix: test cases related to modified depreciation schedule
This commit is contained in:
@@ -2979,10 +2979,8 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
["2021-06-30", 20000.0, 21366.12, True],
|
||||
["2022-06-30", 20000.0, 41366.12, False],
|
||||
["2023-06-30", 20000.0, 61366.12, False],
|
||||
["2024-06-30", 20000.0, 81366.12, False],
|
||||
["2025-06-06", 18633.88, 100000.0, False],
|
||||
["2024-06-06", 38633.88, 100000.0, False],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
|
||||
@@ -12,6 +12,7 @@ from frappe.utils import (
|
||||
add_months,
|
||||
add_years,
|
||||
cint,
|
||||
cstr,
|
||||
date_diff,
|
||||
flt,
|
||||
get_datetime,
|
||||
@@ -361,9 +362,11 @@ class Asset(AccountsController):
|
||||
final_number_of_depreciations = cint(finance_book.total_number_of_depreciations) - cint(
|
||||
self.number_of_depreciations_booked
|
||||
)
|
||||
|
||||
has_pro_rata = self.check_is_pro_rata(finance_book)
|
||||
if has_pro_rata:
|
||||
depr_already_booked = any(
|
||||
[d.journal_entry for d in self.get("schedules") if d.finance_book == finance_book.finance_book]
|
||||
)
|
||||
if has_pro_rata and not depr_already_booked:
|
||||
final_number_of_depreciations += 1
|
||||
|
||||
has_wdv_or_dd_non_yearly_pro_rata = False
|
||||
@@ -543,7 +546,7 @@ class Asset(AccountsController):
|
||||
"depreciation_amount": depreciation_amount,
|
||||
"depreciation_method": finance_book.depreciation_method,
|
||||
"finance_book": finance_book.finance_book,
|
||||
"finance_book_id": finance_book.idx,
|
||||
"finance_book_id": cstr(finance_book.idx),
|
||||
"shift": shift,
|
||||
},
|
||||
)
|
||||
@@ -749,7 +752,6 @@ class Asset(AccountsController):
|
||||
):
|
||||
straight_line_idx = []
|
||||
finance_books = []
|
||||
|
||||
for i, d in enumerate(self.get("schedules")):
|
||||
if ignore_booked_entry and d.journal_entry:
|
||||
continue
|
||||
@@ -771,7 +773,10 @@ class Asset(AccountsController):
|
||||
finance_books.append(int(d.finance_book_id))
|
||||
|
||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||
value_after_depreciation -= flt(depreciation_amount)
|
||||
if not d.journal_entry:
|
||||
value_after_depreciation = flt(
|
||||
flt(value_after_depreciation) - depreciation_amount, d.precision("depreciation_amount")
|
||||
)
|
||||
|
||||
# for the last row, if depreciation method = Straight Line
|
||||
if (
|
||||
@@ -783,10 +788,13 @@ class Asset(AccountsController):
|
||||
book = self.get("finance_books")[cint(d.finance_book_id) - 1]
|
||||
|
||||
if not book.shift_based:
|
||||
depreciation_amount += flt(
|
||||
adjustment_amount = flt(
|
||||
value_after_depreciation - flt(book.expected_value_after_useful_life),
|
||||
d.precision("depreciation_amount"),
|
||||
)
|
||||
depreciation_amount = flt(
|
||||
depreciation_amount + adjustment_amount, d.precision("depreciation_amount")
|
||||
)
|
||||
|
||||
d.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += d.depreciation_amount
|
||||
@@ -1433,7 +1441,7 @@ def get_straight_line_or_manual_depr_amount(asset, row, schedule_idx, number_of_
|
||||
# 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:
|
||||
return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / flt(
|
||||
row.total_number_of_depreciations
|
||||
number_of_pending_depreciations
|
||||
)
|
||||
# if the Depreciation Schedule is being modified after Asset Value Adjustment due to decrease in asset value
|
||||
elif asset.flags.decrease_in_asset_value_due_to_value_adjustment:
|
||||
|
||||
@@ -1355,9 +1355,9 @@ class TestDepreciationBasics(AssetSetup):
|
||||
|
||||
for schedule in asset.schedules:
|
||||
if schedule.idx <= 3:
|
||||
self.assertEqual(schedule.finance_book_id, 1)
|
||||
self.assertEqual(schedule.finance_book_id, "1")
|
||||
else:
|
||||
self.assertEqual(schedule.finance_book_id, 2)
|
||||
self.assertEqual(schedule.finance_book_id, "2")
|
||||
|
||||
def test_depreciation_entry_cancellation(self):
|
||||
asset = create_asset(
|
||||
|
||||
@@ -103,12 +103,11 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
||||
["2023-05-31", 9983.33, 45408.05],
|
||||
["2023-06-30", 9983.33, 55391.38],
|
||||
["2023-07-31", 9983.33, 65374.71],
|
||||
["2023-08-31", 8300.0, 73674.71],
|
||||
["2023-09-30", 8300.0, 81974.71],
|
||||
["2023-10-31", 8300.0, 90274.71],
|
||||
["2023-11-30", 8300.0, 98574.71],
|
||||
["2023-12-31", 8300.0, 106874.71],
|
||||
["2024-01-15", 8300.0, 115174.71],
|
||||
["2023-08-31", 9960.0, 75334.71],
|
||||
["2023-09-30", 9960.0, 85294.71],
|
||||
["2023-10-31", 9960.0, 95254.71],
|
||||
["2023-11-30", 9960.0, 105214.71],
|
||||
["2023-12-15", 9960.0, 115174.71],
|
||||
]
|
||||
|
||||
schedules = [
|
||||
|
||||
Reference in New Issue
Block a user