fix: calculate wdv depr schedule properly for existing assets [dev] (#35614)
* fix: calculate wdv depr schedule properly for existing assets * fix: calculate wdv depr schedule properly for existing assets properly * chore: properly call _get_pro_rata_amt
This commit is contained in:
parent
9a819103a7
commit
7bd369c49b
@ -812,14 +812,14 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
number_of_depreciations_booked=1,
|
number_of_depreciations_booked=1,
|
||||||
opening_accumulated_depreciation=50000,
|
opening_accumulated_depreciation=50000,
|
||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2030-12-31",
|
depreciation_start_date="2031-12-31",
|
||||||
total_number_of_depreciations=3,
|
total_number_of_depreciations=3,
|
||||||
frequency_of_depreciation=12,
|
frequency_of_depreciation=12,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(asset.status, "Draft")
|
self.assertEqual(asset.status, "Draft")
|
||||||
|
|
||||||
expected_schedules = [["2030-12-31", 33333.50, 83333.50], ["2031-12-31", 6666.50, 90000.0]]
|
expected_schedules = [["2031-12-31", 33333.50, 83333.50], ["2032-12-31", 6666.50, 90000.0]]
|
||||||
|
|
||||||
schedules = [
|
schedules = [
|
||||||
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
||||||
|
@ -10,6 +10,7 @@ from frappe.utils import (
|
|||||||
cint,
|
cint,
|
||||||
date_diff,
|
date_diff,
|
||||||
flt,
|
flt,
|
||||||
|
get_first_day,
|
||||||
get_last_day,
|
get_last_day,
|
||||||
getdate,
|
getdate,
|
||||||
is_last_day_of_the_month,
|
is_last_day_of_the_month,
|
||||||
@ -271,8 +272,14 @@ class AssetDepreciationSchedule(Document):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# For first row
|
# For first row
|
||||||
if n == 0 and has_pro_rata and not self.opening_accumulated_depreciation:
|
if (
|
||||||
from_date = add_days(asset_doc.available_for_use_date, -1)
|
n == 0
|
||||||
|
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
|
||||||
|
and not self.opening_accumulated_depreciation
|
||||||
|
):
|
||||||
|
from_date = add_days(
|
||||||
|
asset_doc.available_for_use_date, -1
|
||||||
|
) # needed to calc depr amount for available_for_use_date too
|
||||||
depreciation_amount, days, months = _get_pro_rata_amt(
|
depreciation_amount, days, months = _get_pro_rata_amt(
|
||||||
row,
|
row,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
@ -281,10 +288,18 @@ class AssetDepreciationSchedule(Document):
|
|||||||
has_wdv_or_dd_non_yearly_pro_rata,
|
has_wdv_or_dd_non_yearly_pro_rata,
|
||||||
)
|
)
|
||||||
elif n == 0 and has_wdv_or_dd_non_yearly_pro_rata and self.opening_accumulated_depreciation:
|
elif n == 0 and has_wdv_or_dd_non_yearly_pro_rata and self.opening_accumulated_depreciation:
|
||||||
from_date = add_months(
|
if not is_first_day_of_the_month(getdate(asset_doc.available_for_use_date)):
|
||||||
getdate(asset_doc.available_for_use_date),
|
from_date = get_last_day(
|
||||||
(self.number_of_depreciations_booked * row.frequency_of_depreciation),
|
add_months(
|
||||||
)
|
getdate(asset_doc.available_for_use_date),
|
||||||
|
((self.number_of_depreciations_booked - 1) * row.frequency_of_depreciation),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
from_date = add_months(
|
||||||
|
getdate(add_days(asset_doc.available_for_use_date, -1)),
|
||||||
|
(self.number_of_depreciations_booked * row.frequency_of_depreciation),
|
||||||
|
)
|
||||||
depreciation_amount, days, months = _get_pro_rata_amt(
|
depreciation_amount, days, months = _get_pro_rata_amt(
|
||||||
row,
|
row,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
@ -702,3 +717,9 @@ def get_asset_depr_schedule_name(asset_name, status, finance_book=None):
|
|||||||
["status", "=", status],
|
["status", "=", status],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_first_day_of_the_month(date):
|
||||||
|
first_day_of_the_month = get_first_day(date)
|
||||||
|
|
||||||
|
return getdate(first_day_of_the_month) == getdate(date)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user