fix: calculate wdv depr schedule properly for existing assets [v13] (#35615)
* fix: calculate wdv depr schedule properly for existing assets * fix: calculate wdv depr schedule properly for existing assets properly
This commit is contained in:
@@ -27,6 +27,7 @@ from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
|||||||
from erpnext.assets.doctype.asset.depreciation import (
|
from erpnext.assets.doctype.asset.depreciation import (
|
||||||
get_depreciation_accounts,
|
get_depreciation_accounts,
|
||||||
get_disposal_account_and_cost_center,
|
get_disposal_account_and_cost_center,
|
||||||
|
is_first_day_of_the_month,
|
||||||
is_last_day_of_the_month,
|
is_last_day_of_the_month,
|
||||||
)
|
)
|
||||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||||
@@ -364,8 +365,14 @@ class Asset(AccountsController):
|
|||||||
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(self.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(
|
||||||
|
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(
|
depreciation_amount, days, months = self.get_pro_rata_amt(
|
||||||
finance_book,
|
finance_book,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
@@ -374,10 +381,18 @@ class Asset(AccountsController):
|
|||||||
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(self.available_for_use_date)):
|
||||||
getdate(self.available_for_use_date),
|
from_date = get_last_day(
|
||||||
(self.number_of_depreciations_booked * finance_book.frequency_of_depreciation),
|
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(
|
depreciation_amount, days, months = self.get_pro_rata_amt(
|
||||||
finance_book,
|
finance_book,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from frappe.utils import (
|
|||||||
add_months,
|
add_months,
|
||||||
cint,
|
cint,
|
||||||
flt,
|
flt,
|
||||||
|
get_first_day,
|
||||||
get_last_day,
|
get_last_day,
|
||||||
get_link_to_form,
|
get_link_to_form,
|
||||||
getdate,
|
getdate,
|
||||||
@@ -543,3 +544,9 @@ def is_last_day_of_the_month(date):
|
|||||||
last_day_of_the_month = get_last_day(date)
|
last_day_of_the_month = get_last_day(date)
|
||||||
|
|
||||||
return getdate(last_day_of_the_month) == getdate(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)
|
||||||
|
|||||||
@@ -686,14 +686,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]
|
||||||
|
|||||||
Reference in New Issue
Block a user