Skip to content

Commit

Permalink
fix: calculate wdv depr schedule properly for existing assets [v13] (#…
Browse files Browse the repository at this point in the history
…35615)

* fix: calculate wdv depr schedule properly for existing assets

* fix: calculate wdv depr schedule properly for existing assets properly
  • Loading branch information
anandbaburajan committed Jun 8, 2023
1 parent 9d5b500 commit 97f4af8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
27 changes: 21 additions & 6 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from erpnext.assets.doctype.asset.depreciation import (
get_depreciation_accounts,
get_disposal_account_and_cost_center,
is_first_day_of_the_month,
is_last_day_of_the_month,
)
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
Expand Down Expand Up @@ -364,8 +365,14 @@ def make_depreciation_schedule(self, date_of_disposal):
break

# For first row
if n == 0 and has_pro_rata and not self.opening_accumulated_depreciation:
from_date = add_days(self.available_for_use_date, -1)
if (
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(
self.available_for_use_date, -1
) # needed to calc depr amount for available_for_use_date too
depreciation_amount, days, months = self.get_pro_rata_amt(
finance_book,
depreciation_amount,
Expand All @@ -374,10 +381,18 @@ def make_depreciation_schedule(self, date_of_disposal):
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:
from_date = add_months(
getdate(self.available_for_use_date),
(self.number_of_depreciations_booked * finance_book.frequency_of_depreciation),
)
if not is_first_day_of_the_month(getdate(self.available_for_use_date)):
from_date = get_last_day(
add_months(
getdate(self.available_for_use_date),
((self.number_of_depreciations_booked - 1) * finance_book.frequency_of_depreciation),
)
)
else:
from_date = add_months(
getdate(add_days(self.available_for_use_date, -1)),
(self.number_of_depreciations_booked * finance_book.frequency_of_depreciation),
)
depreciation_amount, days, months = self.get_pro_rata_amt(
finance_book,
depreciation_amount,
Expand Down
7 changes: 7 additions & 0 deletions erpnext/assets/doctype/asset/depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
add_months,
cint,
flt,
get_first_day,
get_last_day,
get_link_to_form,
getdate,
Expand Down Expand Up @@ -543,3 +544,9 @@ def is_last_day_of_the_month(date):
last_day_of_the_month = get_last_day(date)

return getdate(last_day_of_the_month) == getdate(date)


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)
4 changes: 2 additions & 2 deletions erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,14 @@ def test_schedule_for_double_declining_method_for_existing_asset(self):
number_of_depreciations_booked=1,
opening_accumulated_depreciation=50000,
expected_value_after_useful_life=10000,
depreciation_start_date="2030-12-31",
depreciation_start_date="2031-12-31",
total_number_of_depreciations=3,
frequency_of_depreciation=12,
)

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 = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
Expand Down

0 comments on commit 97f4af8

Please sign in to comment.