Skip to content

Commit

Permalink
fix: list index out of range (#37880)
Browse files Browse the repository at this point in the history
* fix: list index out of range

* fix: changes in error message

* fix: change error message and date comparision

* fix: change a return a value when disposal date is equal to available for use date

* fix: changes to fix linter test failing
  • Loading branch information
viralpatel15 authored Nov 5, 2023
1 parent eb3630b commit 05fed9e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions erpnext/assets/doctype/asset/depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,15 @@ def get_disposal_account_and_cost_center(company):
def get_value_after_depreciation_on_disposal_date(asset, disposal_date, finance_book=None):
asset_doc = frappe.get_doc("Asset", asset)

if asset_doc.available_for_use_date > getdate(disposal_date):
frappe.throw(
"Disposal date {0} cannot be before available for use date {1} of the asset.".format(
disposal_date, asset_doc.available_for_use_date
)
)
elif asset_doc.available_for_use_date == getdate(disposal_date):
return flt(asset_doc.gross_purchase_amount - asset_doc.opening_accumulated_depreciation)

if asset_doc.calculate_depreciation:
asset_doc.prepare_depreciation_data(getdate(disposal_date))

Expand Down

0 comments on commit 05fed9e

Please sign in to comment.