fix: pro rata based depreciation with opening accumulated depreciation

(cherry picked from commit c0c8c1bb02)
This commit is contained in:
Khushi Rawat
2024-05-07 11:15:49 +05:30
committed by Mergify
parent 12f383f252
commit 72f3fb2a2c
2 changed files with 58 additions and 50 deletions

View File

@@ -352,13 +352,6 @@ class AssetDepreciationSchedule(Document):
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
and not self.opening_accumulated_depreciation
and not self.flags.wdv_it_act_applied
and (
row.depreciation_method in ("Straight Line", "Manual")
or (
row.depreciation_method in ("Written Down Value", "Double Declining Balance")
and not row.daily_prorata_based
)
)
):
from_date = add_days(
asset_doc.available_for_use_date, -1
@@ -842,11 +835,7 @@ def _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
):
if cint(fb_row.frequency_of_depreciation) == 12:
if schedule_idx == 0:
per_day_depr = get_per_day_depr(fb_row, depreciable_value, fb_row.depreciation_start_date)
from_date = asset.available_for_use_date
to_date = add_days(fb_row.depreciation_start_date, -1)
total_days = date_diff(to_date, from_date) + 1
return (per_day_depr * total_days), per_day_depr
return flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100), None
else:
from_date, days_in_month = _get_total_days(
fb_row.depreciation_start_date, schedule_idx, cint(fb_row.frequency_of_depreciation)
@@ -855,11 +844,7 @@ def _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
if has_wdv_or_dd_non_yearly_pro_rata:
if schedule_idx == 0:
per_day_depr = get_per_day_depr(fb_row, depreciable_value, fb_row.depreciation_start_date)
from_date = asset.available_for_use_date
to_date = add_days(fb_row.depreciation_start_date, -1)
total_days = date_diff(to_date, from_date) + 1
return (per_day_depr * total_days), per_day_depr
return flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100), None
elif schedule_idx % (12 / cint(fb_row.frequency_of_depreciation)) == 1:
from_date, days_in_month = _get_total_days(
@@ -892,7 +877,7 @@ def get_per_day_depr(
depreciable_value,
from_date,
):
to_date = add_years(from_date, 1)
to_date = add_days(add_years(from_date, 1), -1)
total_days = date_diff(to_date, from_date) + 1
per_day_depr = (flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100)) / total_days
return per_day_depr

View File

@@ -72,8 +72,8 @@ class TestAssetDepreciationSchedule(FrappeTestCase):
]
self.assertEqual(schedules, expected_schedules)
# Test for Written Down Value Method
def test_daily_prorata_based_depreciation_for_wdv_method(self):
# Frequency of deprciation = 3
# Frequency of deprciation = 3
def test_for_daily_prorata_based_depreciation_wdv_method_frequency_3_months(self):
asset = create_asset(
item_code="Macbook Pro",
calculate_depreciation=1,
@@ -82,57 +82,80 @@ class TestAssetDepreciationSchedule(FrappeTestCase):
available_for_use_date="2021-02-20",
depreciation_start_date="2021-03-31",
frequency_of_depreciation=3,
total_number_of_depreciations=18,
total_number_of_depreciations=6,
rate_of_depreciation=40,
submit=1,
)
asset_depr_schedule = frappe.get_last_doc("Asset Depreciation Schedule", {"asset": asset.name})
self.assertEqual(asset_depr_schedule.depreciation_schedule[1].depreciation_amount, 9521.45)
# Frequency of deprciation = 6
expected_schedules = [
["2021-03-31", 4383.56, 4383.56],
["2021-06-30", 9535.45, 13919.01],
["2021-09-30", 9640.23, 23559.24],
["2021-12-31", 9640.23, 33199.47],
["2022-03-31", 9430.66, 42630.13],
["2022-06-30", 5721.27, 48351.4],
["2022-08-20", 51648.6, 100000.0],
]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in get_depr_schedule(asset.name, "Draft")
]
self.assertEqual(schedules, expected_schedules)
# Frequency of deprciation = 6
def test_for_daily_prorata_based_depreciation_wdv_method_frequency_6_months(self):
asset = create_asset(
item_code="Macbook Pro",
calculate_depreciation=1,
depreciation_method="Written Down Value",
daily_prorata_based=1,
available_for_use_date="2020-02-20",
depreciation_start_date="2020-03-01",
depreciation_start_date="2020-02-29",
frequency_of_depreciation=6,
total_number_of_depreciations=18,
total_number_of_depreciations=6,
rate_of_depreciation=40,
submit=1,
)
asset_depr_schedule = frappe.get_last_doc("Asset Depreciation Schedule", {"asset": asset.name})
self.assertEqual(asset_depr_schedule.depreciation_schedule[1].depreciation_amount, 19889.52)
# Frequency of deprciation = 12
expected_schedules = [
["2020-02-29", 1092.90, 1092.90],
["2020-08-31", 19944.01, 21036.91],
["2021-02-28", 19618.83, 40655.74],
["2021-08-31", 11966.4, 52622.14],
["2022-02-28", 11771.3, 64393.44],
["2022-08-31", 7179.84, 71573.28],
["2023-02-20", 28426.72, 100000.0],
]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in get_depr_schedule(asset.name, "Draft")
]
self.assertEqual(schedules, expected_schedules)
# Frequency of deprciation = 12
def test_for_daily_prorata_based_depreciation_wdv_method_frequency_12_months(self):
asset = create_asset(
item_code="Macbook Pro",
calculate_depreciation=1,
depreciation_method="Written Down Value",
daily_prorata_based=1,
available_for_use_date="2020-02-20",
depreciation_start_date="2020-03-01",
depreciation_start_date="2020-03-31",
frequency_of_depreciation=12,
total_number_of_depreciations=4,
rate_of_depreciation=40,
submit=1,
)
asset_depr_schedule = frappe.get_last_doc("Asset Depreciation Schedule", {"asset": asset.name})
self.assertEqual(asset_depr_schedule.depreciation_schedule[0].depreciation_amount, 1092.90)
# Test for Straight Line Method
def test_daily_prorata_based_depreciation_for_straight_line_method(self):
asset = create_asset(
item_code="Macbook Pro",
calculate_depreciation=1,
depreciation_method="Straight Line",
daily_prorata_based=0,
available_for_use_date="2020-02-20",
depreciation_start_date="2020-03-01",
frequency_of_depreciation=12,
total_number_of_depreciations=4,
submit=1,
)
asset_depr_schedule = frappe.get_last_doc("Asset Depreciation Schedule", {"asset": asset.name})
self.assertEqual(asset_depr_schedule.depreciation_schedule[0].depreciation_amount, 751.37)
expected_schedules = [
["2020-03-31", 4480.87, 4480.87],
["2021-03-31", 38207.65, 42688.52],
["2022-03-31", 22924.59, 65613.11],
["2023-03-31", 13754.76, 79367.87],
["2024-02-20", 20632.13, 100000],
]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in get_depr_schedule(asset.name, "Draft")
]
self.assertEqual(schedules, expected_schedules)