fix: WDV as per IT Act: calculate yearly amount first and then split it based on months
(cherry picked from commit 22bd6a54b24129403e0b399938bddcaa9d630cae)
This commit is contained in:
parent
53f61f1ad1
commit
e3cd35b959
@ -7,6 +7,7 @@ from frappe.model.document import Document
|
|||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
|
add_years,
|
||||||
cint,
|
cint,
|
||||||
date_diff,
|
date_diff,
|
||||||
flt,
|
flt,
|
||||||
@ -18,6 +19,7 @@ from frappe.utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
|
|
||||||
class AssetDepreciationSchedule(Document):
|
class AssetDepreciationSchedule(Document):
|
||||||
@ -283,12 +285,20 @@ class AssetDepreciationSchedule(Document):
|
|||||||
depreciation_amount = 0
|
depreciation_amount = 0
|
||||||
|
|
||||||
number_of_pending_depreciations = final_number_of_depreciations - start
|
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):
|
for n in range(start, final_number_of_depreciations):
|
||||||
# If depreciation is already completed (for double declining balance)
|
# If depreciation is already completed (for double declining balance)
|
||||||
if skip_row:
|
if skip_row:
|
||||||
continue
|
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:
|
if n > 0 and len(self.get("depreciation_schedule")) > n - 1:
|
||||||
prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount
|
prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount
|
||||||
else:
|
else:
|
||||||
@ -298,6 +308,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
self,
|
self,
|
||||||
asset_doc,
|
asset_doc,
|
||||||
value_after_depreciation,
|
value_after_depreciation,
|
||||||
|
yearly_opening_wdv,
|
||||||
row,
|
row,
|
||||||
n,
|
n,
|
||||||
prev_depreciation_amount,
|
prev_depreciation_amount,
|
||||||
@ -401,8 +412,9 @@ class AssetDepreciationSchedule(Document):
|
|||||||
|
|
||||||
if not depreciation_amount:
|
if not depreciation_amount:
|
||||||
continue
|
continue
|
||||||
value_after_depreciation -= flt(
|
value_after_depreciation = flt(
|
||||||
depreciation_amount, asset_doc.precision("gross_purchase_amount")
|
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
|
# Adjust depreciation amount in the last period based on the expected value after useful life
|
||||||
@ -582,6 +594,7 @@ def get_depreciation_amount(
|
|||||||
asset_depr_schedule,
|
asset_depr_schedule,
|
||||||
asset,
|
asset,
|
||||||
depreciable_value,
|
depreciable_value,
|
||||||
|
yearly_opening_wdv,
|
||||||
fb_row,
|
fb_row,
|
||||||
schedule_idx=0,
|
schedule_idx=0,
|
||||||
prev_depreciation_amount=0,
|
prev_depreciation_amount=0,
|
||||||
@ -597,6 +610,7 @@ def get_depreciation_amount(
|
|||||||
asset,
|
asset,
|
||||||
fb_row,
|
fb_row,
|
||||||
depreciable_value,
|
depreciable_value,
|
||||||
|
yearly_opening_wdv,
|
||||||
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,
|
||||||
@ -744,19 +758,23 @@ def get_wdv_or_dd_depr_amount(
|
|||||||
asset,
|
asset,
|
||||||
fb_row,
|
fb_row,
|
||||||
depreciable_value,
|
depreciable_value,
|
||||||
|
yearly_opening_wdv,
|
||||||
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,
|
||||||
):
|
):
|
||||||
return get_default_wdv_or_dd_depr_amount(
|
return (
|
||||||
asset,
|
get_default_wdv_or_dd_depr_amount(
|
||||||
fb_row,
|
asset,
|
||||||
depreciable_value,
|
fb_row,
|
||||||
schedule_idx,
|
depreciable_value,
|
||||||
prev_depreciation_amount,
|
schedule_idx,
|
||||||
has_wdv_or_dd_non_yearly_pro_rata,
|
prev_depreciation_amount,
|
||||||
asset_depr_schedule,
|
has_wdv_or_dd_non_yearly_pro_rata,
|
||||||
|
asset_depr_schedule,
|
||||||
|
),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user