feat(Asset Repair): Modify depreciation schedule when increase_in_asset_life is not a multiple of frequency_of_depreciation
This commit is contained in:
parent
4277877883
commit
4b543de329
@ -54,6 +54,8 @@
|
|||||||
"next_depreciation_date",
|
"next_depreciation_date",
|
||||||
"section_break_14",
|
"section_break_14",
|
||||||
"schedules",
|
"schedules",
|
||||||
|
"to_date",
|
||||||
|
"edit_dates",
|
||||||
"insurance_details",
|
"insurance_details",
|
||||||
"policy_number",
|
"policy_number",
|
||||||
"insurer",
|
"insurer",
|
||||||
@ -487,6 +489,18 @@
|
|||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Asset Value",
|
"label": "Asset Value",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "to_date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "To Date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "edit_dates",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Edit Dates"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 72,
|
"idx": 72,
|
||||||
@ -509,7 +523,7 @@
|
|||||||
"link_fieldname": "asset"
|
"link_fieldname": "asset"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-11 23:47:15.831720",
|
"modified": "2021-05-21 12:05:29.424083",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@ -228,11 +228,12 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
# For last row
|
# For last row
|
||||||
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
|
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
|
||||||
to_date = add_months(self.available_for_use_date,
|
if not self.edit_dates:
|
||||||
|
self.to_date = add_months(self.available_for_use_date,
|
||||||
n * cint(d.frequency_of_depreciation))
|
n * cint(d.frequency_of_depreciation))
|
||||||
|
|
||||||
depreciation_amount, days, months = get_pro_rata_amt(d,
|
depreciation_amount, days, months = get_pro_rata_amt(d,
|
||||||
depreciation_amount, schedule_date, to_date)
|
depreciation_amount, schedule_date, self.to_date)
|
||||||
|
|
||||||
monthly_schedule_date = add_months(schedule_date, 1)
|
monthly_schedule_date = add_months(schedule_date, 1)
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import time_diff_in_hours, getdate
|
from frappe.utils import time_diff_in_hours, getdate, add_days, date_diff, add_months, flt, cint
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import flt
|
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
|
|
||||||
class AssetRepair(Document):
|
class AssetRepair(Document):
|
||||||
@ -148,9 +147,30 @@ class AssetRepair(Document):
|
|||||||
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 = ""
|
||||||
|
extra_months = self.increase_in_asset_life % row.frequency_of_depreciation
|
||||||
|
if extra_months != 0:
|
||||||
|
self.calculate_last_schedule_date(asset, row, extra_months)
|
||||||
|
# fix depreciation amount
|
||||||
|
|
||||||
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
|
||||||
|
def calculate_last_schedule_date(self, asset, row, extra_months):
|
||||||
|
asset.edit_dates = "Don't Edit"
|
||||||
|
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - \
|
||||||
|
cint(asset.number_of_depreciations_booked)
|
||||||
|
last_schedule_date = asset.schedules[len(asset.schedules)-1].schedule_date
|
||||||
|
asset.to_date = add_months(last_schedule_date, extra_months)
|
||||||
|
schedule_date = add_months(row.depreciation_start_date,
|
||||||
|
number_of_pending_depreciations * cint(row.frequency_of_depreciation))
|
||||||
|
|
||||||
|
if asset.to_date > schedule_date:
|
||||||
|
row.total_number_of_depreciations += 1
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_downtime(failure_date, completion_date):
|
def get_downtime(failure_date, completion_date):
|
||||||
downtime = time_diff_in_hours(completion_date, failure_date)
|
downtime = time_diff_in_hours(completion_date, failure_date)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user