fix: Add comments
This commit is contained in:
parent
94dfd0e318
commit
93b9752771
@ -179,6 +179,7 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
start = self.clear_depreciation_schedule()
|
start = self.clear_depreciation_schedule()
|
||||||
|
|
||||||
|
# value_after_depreciation - current Asset value
|
||||||
if d.value_after_depreciation:
|
if d.value_after_depreciation:
|
||||||
value_after_depreciation = (flt(d.value_after_depreciation) -
|
value_after_depreciation = (flt(d.value_after_depreciation) -
|
||||||
flt(self.opening_accumulated_depreciation)) - flt(d.expected_value_after_useful_life)
|
flt(self.opening_accumulated_depreciation)) - flt(d.expected_value_after_useful_life)
|
||||||
@ -291,6 +292,7 @@ class Asset(AccountsController):
|
|||||||
"finance_book_id": d.idx
|
"finance_book_id": d.idx
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# used when depreciation schedule needs to be modified due to increase in asset life
|
||||||
def clear_depreciation_schedule(self):
|
def clear_depreciation_schedule(self):
|
||||||
start = 0
|
start = 0
|
||||||
for n in range(len(self.schedules)):
|
for n in range(len(self.schedules)):
|
||||||
@ -300,10 +302,13 @@ class Asset(AccountsController):
|
|||||||
break
|
break
|
||||||
return start
|
return start
|
||||||
|
|
||||||
|
|
||||||
|
# if it returns True, depreciation_amount will not be equal for the first and last rows
|
||||||
def check_is_pro_rata(self, row):
|
def check_is_pro_rata(self, row):
|
||||||
has_pro_rata = False
|
has_pro_rata = False
|
||||||
|
|
||||||
days = date_diff(row.depreciation_start_date, self.available_for_use_date) + 1
|
days = date_diff(row.depreciation_start_date, self.available_for_use_date) + 1
|
||||||
|
|
||||||
|
# if frequency_of_depreciation is 12 months, total_days = 365
|
||||||
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation)
|
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation)
|
||||||
|
|
||||||
if days < total_days:
|
if days < total_days:
|
||||||
@ -783,9 +788,12 @@ def get_depreciation_amount(asset, depreciable_value, row):
|
|||||||
depreciation_left = flt(row.total_number_of_depreciations) - flt(asset.number_of_depreciations_booked)
|
depreciation_left = flt(row.total_number_of_depreciations) - flt(asset.number_of_depreciations_booked)
|
||||||
|
|
||||||
if row.depreciation_method in ("Straight Line", "Manual"):
|
if row.depreciation_method in ("Straight Line", "Manual"):
|
||||||
|
# if the Depreciation Schedule is being prepared for the first time
|
||||||
if not asset.to_date:
|
if not asset.to_date:
|
||||||
depreciation_amount = (flt(row.value_after_depreciation) -
|
depreciation_amount = (flt(row.value_after_depreciation) -
|
||||||
flt(row.expected_value_after_useful_life)) / depreciation_left
|
flt(row.expected_value_after_useful_life)) / depreciation_left
|
||||||
|
|
||||||
|
# if the Depreciation Schedule is being modified after Asset Repair
|
||||||
else:
|
else:
|
||||||
depreciation_amount = (flt(row.value_after_depreciation) -
|
depreciation_amount = (flt(row.value_after_depreciation) -
|
||||||
flt(row.expected_value_after_useful_life)) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
flt(row.expected_value_after_useful_life)) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
||||||
|
@ -46,7 +46,7 @@ class AssetRepair(AccountsController):
|
|||||||
self.decrease_stock_quantity()
|
self.decrease_stock_quantity()
|
||||||
if self.capitalize_repair_cost:
|
if self.capitalize_repair_cost:
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
if frappe.db.get_value('Asset', self.asset, 'calculate_depreciation'):
|
if frappe.db.get_value('Asset', self.asset, 'calculate_depreciation') and self.increase_in_asset_life:
|
||||||
self.modify_depreciation_schedule()
|
self.modify_depreciation_schedule()
|
||||||
|
|
||||||
def check_repair_status(self):
|
def check_repair_status(self):
|
||||||
@ -156,27 +156,33 @@ class AssetRepair(AccountsController):
|
|||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
def modify_depreciation_schedule(self):
|
def modify_depreciation_schedule(self):
|
||||||
if self.increase_in_asset_life:
|
asset = frappe.get_doc('Asset', self.asset)
|
||||||
asset = frappe.get_doc('Asset', self.asset)
|
asset.flags.ignore_validate_update_after_submit = True
|
||||||
asset.flags.ignore_validate_update_after_submit = True
|
for row in asset.finance_books:
|
||||||
for row in asset.finance_books:
|
row.total_number_of_depreciations += self.increase_in_asset_life/row.frequency_of_depreciation
|
||||||
row.total_number_of_depreciations += self.increase_in_asset_life/row.frequency_of_depreciation
|
|
||||||
|
|
||||||
asset.edit_dates = ""
|
asset.edit_dates = ""
|
||||||
extra_months = self.increase_in_asset_life % row.frequency_of_depreciation
|
extra_months = self.increase_in_asset_life % row.frequency_of_depreciation
|
||||||
if extra_months != 0:
|
if extra_months != 0:
|
||||||
self.calculate_last_schedule_date(asset, row, extra_months)
|
self.calculate_last_schedule_date(asset, row, extra_months)
|
||||||
|
|
||||||
asset.prepare_depreciation_data()
|
asset.prepare_depreciation_data()
|
||||||
asset.save()
|
asset.save()
|
||||||
|
|
||||||
# to help modify depreciation schedule when increase_in_asset_life is not a multiple of frequency_of_depreciation
|
# to help modify depreciation schedule when increase_in_asset_life is not a multiple of frequency_of_depreciation
|
||||||
def calculate_last_schedule_date(self, asset, row, extra_months):
|
def calculate_last_schedule_date(self, asset, row, extra_months):
|
||||||
asset.edit_dates = "Don't Edit"
|
asset.edit_dates = "Don't Edit"
|
||||||
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - \
|
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - \
|
||||||
cint(asset.number_of_depreciations_booked)
|
cint(asset.number_of_depreciations_booked)
|
||||||
|
|
||||||
|
# the Schedule Date in the final row of the old Depreciation Schedule
|
||||||
last_schedule_date = asset.schedules[len(asset.schedules)-1].schedule_date
|
last_schedule_date = asset.schedules[len(asset.schedules)-1].schedule_date
|
||||||
|
|
||||||
|
# the Schedule Date in the final row of the new Depreciation Schedule
|
||||||
asset.to_date = add_months(last_schedule_date, extra_months)
|
asset.to_date = add_months(last_schedule_date, extra_months)
|
||||||
|
|
||||||
|
# the latest possible date at which the depreciation can occur, without increasing the Total Number of Depreciations
|
||||||
|
# if depreciations happen yearly and the Depreciation Posting Date is 01-01-2020, this could be 01-01-2021, 01-01-2022...
|
||||||
schedule_date = add_months(row.depreciation_start_date,
|
schedule_date = add_months(row.depreciation_start_date,
|
||||||
number_of_pending_depreciations * cint(row.frequency_of_depreciation))
|
number_of_pending_depreciations * cint(row.frequency_of_depreciation))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user