Skip to content

Commit

Permalink
Merge pull request #42689 from khushi8112/depreciation-amount-correction
Browse files Browse the repository at this point in the history
fix: fetch month's last date to avoid miscalculation
  • Loading branch information
khushi8112 authored Aug 13, 2024
2 parents af11480 + 70ff4e7 commit 616ce2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
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 @@ -234,7 +234,7 @@ def test_scrap_asset(self):
pro_rata_amount, _, _ = _get_pro_rata_amt(
asset.finance_books[0],
9000,
get_last_day(add_months(purchase_date, 1)),
add_days(get_last_day(add_months(purchase_date, 1)), 1),
date,
original_schedule_date=get_last_day(nowdate()),
)
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_gle_made_by_asset_sale(self):
pro_rata_amount, _, _ = _get_pro_rata_amt(
asset.finance_books[0],
9000,
get_last_day(add_months(purchase_date, 1)),
add_days(get_last_day(add_months(purchase_date, 1)), 1),
date,
original_schedule_date=get_last_day(nowdate()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ def _make_depr_schedule(
if skip_row:
continue

schedule_date = add_months(row.depreciation_start_date, n * cint(row.frequency_of_depreciation))
schedule_date = get_last_day(
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):
Expand Down Expand Up @@ -330,8 +332,10 @@ def _make_depr_schedule(
getdate(asset_doc.available_for_use_date),
(asset_doc.opening_number_of_booked_depreciations * row.frequency_of_depreciation),
)
if is_last_day_of_the_month(getdate(asset_doc.available_for_use_date)):
from_date = get_last_day(from_date)
if self.depreciation_schedule:
from_date = self.depreciation_schedule[-1].schedule_date
from_date = add_days(self.depreciation_schedule[-1].schedule_date, 1)

depreciation_amount, days, months = _get_pro_rata_amt(
row,
Expand All @@ -353,9 +357,8 @@ def _make_depr_schedule(
and not self.opening_accumulated_depreciation
and not self.flags.wdv_it_act_applied
):
from_date = add_days(
asset_doc.available_for_use_date, -1
) # needed to calc depr amount for available_for_use_date too
from_date = asset_doc.available_for_use_date
# needed to calc depr amount for available_for_use_date too
depreciation_amount, days, months = _get_pro_rata_amt(
row,
depreciation_amount,
Expand Down Expand Up @@ -406,6 +409,8 @@ def _make_depr_schedule(
(n + self.opening_number_of_booked_depreciations)
* cint(row.frequency_of_depreciation),
)
if is_last_day_of_the_month(getdate(asset_doc.available_for_use_date)):
asset_doc.to_date = get_last_day(asset_doc.to_date)

depreciation_amount_without_pro_rata = depreciation_amount

Expand All @@ -421,7 +426,7 @@ def _make_depr_schedule(
depreciation_amount_without_pro_rata, depreciation_amount
)

schedule_date = add_days(schedule_date, days)
schedule_date = add_days(schedule_date, days - 1)

if not depreciation_amount:
continue
Expand Down Expand Up @@ -553,9 +558,11 @@ def _check_is_pro_rata(asset_doc, row, wdv_or_dd_non_yearly=False):
# otherwise, if opening_number_of_booked_depreciations = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12
# from_date = 01/01/2022
if row.depreciation_method in ("Straight Line", "Manual"):
prev_depreciation_start_date = add_months(
row.depreciation_start_date,
(row.frequency_of_depreciation * -1) * asset_doc.opening_number_of_booked_depreciations,
prev_depreciation_start_date = get_last_day(
add_months(
row.depreciation_start_date,
(row.frequency_of_depreciation * -1) * asset_doc.opening_number_of_booked_depreciations,
)
)
from_date = asset_doc.available_for_use_date
days = date_diff(prev_depreciation_start_date, from_date) + 1
Expand Down Expand Up @@ -610,7 +617,7 @@ def _get_pro_rata_amt(
has_wdv_or_dd_non_yearly_pro_rata=False,
original_schedule_date=None,
):
days = date_diff(to_date, from_date)
days = date_diff(to_date, from_date) + 1
months = month_diff(to_date, from_date)
if has_wdv_or_dd_non_yearly_pro_rata:
total_days = get_total_days(original_schedule_date or to_date, 12)
Expand Down

0 comments on commit 616ce2d

Please sign in to comment.