mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-20 07:22:13 +00:00
fix: daily prorata based depreciation bug in wdv method
(cherry picked from commit b8a98a273b)
This commit is contained in:
@@ -1000,7 +1000,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
|
|
||||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, "Active")
|
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||||
|
|
||||||
depreciation_amount = get_depreciation_amount(
|
depreciation_amount, prev_per_day_depr = get_depreciation_amount(
|
||||||
asset_depr_schedule_doc, asset, 100000, 100000, asset.finance_books[0]
|
asset_depr_schedule_doc, asset, 100000, 100000, asset.finance_books[0]
|
||||||
)
|
)
|
||||||
self.assertEqual(depreciation_amount, 30000)
|
self.assertEqual(depreciation_amount, 30000)
|
||||||
@@ -1723,6 +1723,7 @@ def create_asset(**args):
|
|||||||
"depreciation_start_date": args.depreciation_start_date,
|
"depreciation_start_date": args.depreciation_start_date,
|
||||||
"daily_prorata_based": args.daily_prorata_based or 0,
|
"daily_prorata_based": args.daily_prorata_based or 0,
|
||||||
"shift_based": args.shift_based or 0,
|
"shift_based": args.shift_based or 0,
|
||||||
|
"rate_of_depreciation": args.rate_of_depreciation or 40,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -302,7 +302,6 @@ class AssetDepreciationSchedule(Document):
|
|||||||
prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount
|
prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount
|
||||||
else:
|
else:
|
||||||
prev_depreciation_amount = 0
|
prev_depreciation_amount = 0
|
||||||
|
|
||||||
depreciation_amount, prev_per_day_depr = get_depreciation_amount(
|
depreciation_amount, prev_per_day_depr = get_depreciation_amount(
|
||||||
self,
|
self,
|
||||||
asset_doc,
|
asset_doc,
|
||||||
@@ -353,7 +352,13 @@ class AssetDepreciationSchedule(Document):
|
|||||||
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
|
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
|
||||||
and not self.opening_accumulated_depreciation
|
and not self.opening_accumulated_depreciation
|
||||||
and not self.flags.wdv_it_act_applied
|
and not self.flags.wdv_it_act_applied
|
||||||
and not self.daily_prorata_based
|
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(
|
from_date = add_days(
|
||||||
asset_doc.available_for_use_date, -1
|
asset_doc.available_for_use_date, -1
|
||||||
@@ -768,30 +773,27 @@ def get_default_wdv_or_dd_depr_amount(
|
|||||||
asset_depr_schedule,
|
asset_depr_schedule,
|
||||||
prev_per_day_depr,
|
prev_per_day_depr,
|
||||||
):
|
):
|
||||||
if cint(fb_row.frequency_of_depreciation) == 12:
|
if not fb_row.daily_prorata_based:
|
||||||
return flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100)
|
return _get_default_wdv_or_dd_depr_amount(
|
||||||
|
asset,
|
||||||
|
fb_row,
|
||||||
|
depreciable_value,
|
||||||
|
schedule_idx,
|
||||||
|
prev_depreciation_amount,
|
||||||
|
has_wdv_or_dd_non_yearly_pro_rata,
|
||||||
|
asset_depr_schedule,
|
||||||
|
), None
|
||||||
else:
|
else:
|
||||||
if not fb_row.daily_prorata_based:
|
return _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
|
||||||
return _get_default_wdv_or_dd_depr_amount(
|
asset,
|
||||||
asset,
|
fb_row,
|
||||||
fb_row,
|
depreciable_value,
|
||||||
depreciable_value,
|
schedule_idx,
|
||||||
schedule_idx,
|
prev_depreciation_amount,
|
||||||
prev_depreciation_amount,
|
has_wdv_or_dd_non_yearly_pro_rata,
|
||||||
has_wdv_or_dd_non_yearly_pro_rata,
|
asset_depr_schedule,
|
||||||
asset_depr_schedule,
|
prev_per_day_depr,
|
||||||
), None
|
)
|
||||||
else:
|
|
||||||
return _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
|
|
||||||
asset,
|
|
||||||
fb_row,
|
|
||||||
depreciable_value,
|
|
||||||
schedule_idx,
|
|
||||||
prev_depreciation_amount,
|
|
||||||
has_wdv_or_dd_non_yearly_pro_rata,
|
|
||||||
asset_depr_schedule,
|
|
||||||
prev_per_day_depr,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_default_wdv_or_dd_depr_amount(
|
def _get_default_wdv_or_dd_depr_amount(
|
||||||
@@ -838,14 +840,27 @@ def _get_daily_prorata_based_default_wdv_or_dd_depr_amount(
|
|||||||
asset_depr_schedule,
|
asset_depr_schedule,
|
||||||
prev_per_day_depr,
|
prev_per_day_depr,
|
||||||
):
|
):
|
||||||
if has_wdv_or_dd_non_yearly_pro_rata:
|
if cint(fb_row.frequency_of_depreciation) == 12:
|
||||||
if schedule_idx == 0:
|
if schedule_idx == 0:
|
||||||
print(">>>>>", depreciable_value)
|
|
||||||
per_day_depr = get_per_day_depr(fb_row, depreciable_value, fb_row.depreciation_start_date)
|
per_day_depr = get_per_day_depr(fb_row, depreciable_value, fb_row.depreciation_start_date)
|
||||||
from_date = asset.available_for_use_date
|
from_date = asset.available_for_use_date
|
||||||
to_date = add_days(fb_row.depreciation_start_date, -1)
|
to_date = add_days(fb_row.depreciation_start_date, -1)
|
||||||
total_days = date_diff(to_date, from_date) + 1
|
total_days = date_diff(to_date, from_date) + 1
|
||||||
print("892", per_day_depr, from_date, to_date, total_days)
|
return (per_day_depr * total_days), per_day_depr
|
||||||
|
else:
|
||||||
|
from_date, to_date = get_dates(
|
||||||
|
fb_row.depreciation_start_date, schedule_idx, cint(fb_row.frequency_of_depreciation)
|
||||||
|
)
|
||||||
|
days_in_month = date_diff(to_date, from_date) + 1
|
||||||
|
return (prev_per_day_depr * days_in_month), prev_per_day_depr
|
||||||
|
|
||||||
|
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 (per_day_depr * total_days), per_day_depr
|
||||||
|
|
||||||
elif schedule_idx % (12 / cint(fb_row.frequency_of_depreciation)) == 1:
|
elif schedule_idx % (12 / cint(fb_row.frequency_of_depreciation)) == 1:
|
||||||
|
|||||||
@@ -71,3 +71,68 @@ class TestAssetDepreciationSchedule(FrappeTestCase):
|
|||||||
for d in get_depr_schedule(asset.name, "Draft")
|
for d in get_depr_schedule(asset.name, "Draft")
|
||||||
]
|
]
|
||||||
self.assertEqual(schedules, expected_schedules)
|
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
|
||||||
|
asset = create_asset(
|
||||||
|
item_code="Macbook Pro",
|
||||||
|
calculate_depreciation=1,
|
||||||
|
depreciation_method="Written Down Value",
|
||||||
|
daily_prorata_based=1,
|
||||||
|
available_for_use_date="2021-02-20",
|
||||||
|
depreciation_start_date="2021-03-31",
|
||||||
|
frequency_of_depreciation=3,
|
||||||
|
total_number_of_depreciations=18,
|
||||||
|
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
|
||||||
|
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",
|
||||||
|
frequency_of_depreciation=6,
|
||||||
|
total_number_of_depreciations=18,
|
||||||
|
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
|
||||||
|
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",
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user