fix: Adjust initial month's depreciation to end of depreciation period

(cherry picked from commit cbb749a3a5)
This commit is contained in:
Khushi Rawat
2024-07-29 23:50:57 +05:30
committed by Mergify
parent 6840f6cb26
commit 9d2ef4d3e8
2 changed files with 25 additions and 17 deletions

View File

@@ -740,7 +740,7 @@ class TestDepreciationMethods(AssetSetup):
available_for_use_date="2030-06-06", available_for_use_date="2030-06-06",
is_existing_asset=1, is_existing_asset=1,
opening_number_of_booked_depreciations=2, opening_number_of_booked_depreciations=2,
opening_accumulated_depreciation=47095.89, opening_accumulated_depreciation=47178.08,
expected_value_after_useful_life=10000, expected_value_after_useful_life=10000,
depreciation_start_date="2032-12-31", depreciation_start_date="2032-12-31",
total_number_of_depreciations=3, total_number_of_depreciations=3,
@@ -748,7 +748,7 @@ class TestDepreciationMethods(AssetSetup):
) )
self.assertEqual(asset.status, "Draft") self.assertEqual(asset.status, "Draft")
expected_schedules = [["2032-12-31", 42904.11, 90000.0]] expected_schedules = [["2032-12-31", 30000.0, 77178.08], ["2033-06-06", 12821.92, 90000.0]]
schedules = [ schedules = [
[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] [cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount]
for d in get_depr_schedule(asset.name, "Draft") for d in get_depr_schedule(asset.name, "Draft")

View File

@@ -552,9 +552,18 @@ def _check_is_pro_rata(asset_doc, row, wdv_or_dd_non_yearly=False):
# if not existing asset, from_date = available_for_use_date # if not existing asset, from_date = available_for_use_date
# otherwise, if opening_number_of_booked_depreciations = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12 # otherwise, if opening_number_of_booked_depreciations = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12
# from_date = 01/01/2022 # from_date = 01/01/2022
from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly=False) if row.depreciation_method in ("Straight Line", "Manual"):
days = date_diff(row.depreciation_start_date, from_date) + 1 prev_depreciation_start_date = add_months(
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation) row.depreciation_start_date,
(row.frequency_of_depreciation * -1) * asset_doc.opening_number_of_booked_depreciations,
)
from_date = asset_doc.available_for_use_date
days = date_diff(prev_depreciation_start_date, from_date) + 1
total_days = get_total_days(prev_depreciation_start_date, row.frequency_of_depreciation)
else:
from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly=False)
days = date_diff(row.depreciation_start_date, from_date) + 1
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation)
if days <= 0: if days <= 0:
frappe.throw( frappe.throw(
_( _(
@@ -682,20 +691,15 @@ def get_straight_line_or_manual_depr_amount(
# if the Depreciation Schedule is being prepared for the first time # if the Depreciation Schedule is being prepared for the first time
else: else:
if row.daily_prorata_based: if row.daily_prorata_based:
amount = ( amount = flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
flt(asset.gross_purchase_amount)
- flt(asset.opening_accumulated_depreciation)
- flt(row.expected_value_after_useful_life)
)
return get_daily_prorata_based_straight_line_depr( return get_daily_prorata_based_straight_line_depr(
asset, row, schedule_idx, number_of_pending_depreciations, amount asset, row, schedule_idx, number_of_pending_depreciations, amount
) )
else: else:
return ( depreciation_amount = (
flt(asset.gross_purchase_amount) flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
- flt(asset.opening_accumulated_depreciation) ) / flt(row.total_number_of_depreciations)
- flt(row.expected_value_after_useful_life) return depreciation_amount
) / flt(row.total_number_of_depreciations - asset.opening_number_of_booked_depreciations)
def get_daily_prorata_based_straight_line_depr( def get_daily_prorata_based_straight_line_depr(
@@ -725,7 +729,11 @@ def get_daily_depr_amount(asset, row, schedule_idx, amount):
) )
), ),
add_days( add_days(
get_last_day(add_months(row.depreciation_start_date, -1 * row.frequency_of_depreciation)), add_months(
row.depreciation_start_date,
(row.frequency_of_depreciation * (asset.opening_number_of_booked_depreciations + 1))
* -1,
),
1, 1,
), ),
) )
@@ -904,7 +912,7 @@ def _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
def get_monthly_depr_amount(fb_row, schedule_idx, depreciable_value): def get_monthly_depr_amount(fb_row, schedule_idx, depreciable_value):
""" " """
Returns monthly depreciation amount when year changes Returns monthly depreciation amount when year changes
1. Calculate per day depr based on new year 1. Calculate per day depr based on new year
2. Calculate monthly amount based on new per day amount 2. Calculate monthly amount based on new per day amount