Merge pull request #39385 from nabinhait/wdv-as-per-income-tax-act
fix: WDV as per IT Act: calculate yearly amount first and then split it based on months
diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
index 74d2aa7..ffb50eb 100644
--- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
+++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
@@ -7,6 +7,7 @@
from frappe.utils import (
add_days,
add_months,
+ add_years,
cint,
date_diff,
flt,
@@ -18,6 +19,7 @@
)
import erpnext
+from erpnext.accounts.utils import get_fiscal_year
class AssetDepreciationSchedule(Document):
@@ -283,12 +285,20 @@
depreciation_amount = 0
number_of_pending_depreciations = final_number_of_depreciations - start
-
+ yearly_opening_wdv = value_after_depreciation
+ current_fiscal_year_end_date = None
for n in range(start, final_number_of_depreciations):
# If depreciation is already completed (for double declining balance)
if skip_row:
continue
+ schedule_date = add_months(row.depreciation_start_date, n * cint(row.frequency_of_depreciation))
+ if not current_fiscal_year_end_date:
+ current_fiscal_year_end_date = get_fiscal_year(row.depreciation_start_date)[2]
+ elif getdate(schedule_date) > getdate(current_fiscal_year_end_date):
+ current_fiscal_year_end_date = add_years(current_fiscal_year_end_date, 1)
+ yearly_opening_wdv = value_after_depreciation
+
if n > 0 and len(self.get("depreciation_schedule")) > n - 1:
prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount
else:
@@ -298,6 +308,7 @@
self,
asset_doc,
value_after_depreciation,
+ yearly_opening_wdv,
row,
n,
prev_depreciation_amount,
@@ -401,8 +412,9 @@
if not depreciation_amount:
continue
- value_after_depreciation -= flt(
- depreciation_amount, asset_doc.precision("gross_purchase_amount")
+ value_after_depreciation = flt(
+ value_after_depreciation - flt(depreciation_amount),
+ asset_doc.precision("gross_purchase_amount"),
)
# Adjust depreciation amount in the last period based on the expected value after useful life
@@ -582,6 +594,7 @@
asset_depr_schedule,
asset,
depreciable_value,
+ yearly_opening_wdv,
fb_row,
schedule_idx=0,
prev_depreciation_amount=0,
@@ -597,6 +610,7 @@
asset,
fb_row,
depreciable_value,
+ yearly_opening_wdv,
schedule_idx,
prev_depreciation_amount,
has_wdv_or_dd_non_yearly_pro_rata,
@@ -744,19 +758,23 @@
asset,
fb_row,
depreciable_value,
+ yearly_opening_wdv,
schedule_idx,
prev_depreciation_amount,
has_wdv_or_dd_non_yearly_pro_rata,
asset_depr_schedule,
):
- 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,
+ 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,
)