feat(Asset Repair): Modify depreciation schedule when increase_in_asset_life is not a multiple of frequency_of_depreciation
diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json
index 4960c7e..8a0e3ad 100644
--- a/erpnext/assets/doctype/asset/asset.json
+++ b/erpnext/assets/doctype/asset/asset.json
@@ -54,6 +54,8 @@
"next_depreciation_date",
"section_break_14",
"schedules",
+ "to_date",
+ "edit_dates",
"insurance_details",
"policy_number",
"insurer",
@@ -487,6 +489,18 @@
"fieldtype": "Currency",
"label": "Asset Value",
"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,
@@ -509,7 +523,7 @@
"link_fieldname": "asset"
}
],
- "modified": "2021-05-11 23:47:15.831720",
+ "modified": "2021-05-21 12:05:29.424083",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index f837c5e..2d012d6 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -228,11 +228,12 @@
# For last row
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
- to_date = add_months(self.available_for_use_date,
- n * cint(d.frequency_of_depreciation))
+ if not self.edit_dates:
+ self.to_date = add_months(self.available_for_use_date,
+ n * cint(d.frequency_of_depreciation))
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)
diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py
index 95abbd3..8fd019f 100644
--- a/erpnext/assets/doctype/asset_repair/asset_repair.py
+++ b/erpnext/assets/doctype/asset_repair/asset_repair.py
@@ -5,9 +5,8 @@
from __future__ import unicode_literals
import frappe
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.utils import flt
from erpnext.accounts.general_ledger import make_gl_entries
class AssetRepair(Document):
@@ -148,8 +147,29 @@
asset.flags.ignore_validate_update_after_submit = True
for row in asset.finance_books:
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.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()
def get_downtime(failure_date, completion_date):