mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 21:49:18 +00:00
feat(Asset): Modify depreciation schedule
This commit is contained in:
@@ -171,15 +171,23 @@ class Asset(AccountsController):
|
|||||||
d.precision("rate_of_depreciation"))
|
d.precision("rate_of_depreciation"))
|
||||||
|
|
||||||
def make_depreciation_schedule(self):
|
def make_depreciation_schedule(self):
|
||||||
if 'Manual' not in [d.depreciation_method for d in self.finance_books]:
|
if 'Manual' not in [d.depreciation_method for d in self.finance_books] and not self.schedules:
|
||||||
self.schedules = []
|
self.schedules = []
|
||||||
|
|
||||||
if self.get("schedules") or not self.available_for_use_date:
|
if not self.available_for_use_date:
|
||||||
return
|
return
|
||||||
|
|
||||||
for d in self.get('finance_books'):
|
for d in self.get('finance_books'):
|
||||||
self.validate_asset_finance_books(d)
|
self.validate_asset_finance_books(d)
|
||||||
|
|
||||||
|
start = 0
|
||||||
|
for n in range (len(self.schedules)):
|
||||||
|
if not self.schedules[n].journal_entry:
|
||||||
|
print("*"*100)
|
||||||
|
del self.schedules[n:]
|
||||||
|
start = n
|
||||||
|
break
|
||||||
|
|
||||||
value_after_depreciation = (flt(self.gross_purchase_amount) -
|
value_after_depreciation = (flt(self.gross_purchase_amount) -
|
||||||
flt(self.opening_accumulated_depreciation))
|
flt(self.opening_accumulated_depreciation))
|
||||||
|
|
||||||
@@ -192,9 +200,9 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
if has_pro_rata:
|
if has_pro_rata:
|
||||||
number_of_pending_depreciations += 1
|
number_of_pending_depreciations += 1
|
||||||
|
|
||||||
skip_row = False
|
skip_row = False
|
||||||
for n in range(number_of_pending_depreciations):
|
for n in range(start, number_of_pending_depreciations):
|
||||||
# If depreciation is already completed (for double declining balance)
|
# If depreciation is already completed (for double declining balance)
|
||||||
if skip_row: continue
|
if skip_row: continue
|
||||||
|
|
||||||
@@ -350,11 +358,12 @@ class Asset(AccountsController):
|
|||||||
if d.finance_book_id not in finance_books:
|
if d.finance_book_id not in finance_books:
|
||||||
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
||||||
value_after_depreciation = flt(self.get_value_after_depreciation(d.finance_book_id))
|
value_after_depreciation = flt(self.get_value_after_depreciation(d.finance_book_id))
|
||||||
finance_books.append(d.finance_book_id)
|
finance_books.append(int(d.finance_book_id))
|
||||||
|
|
||||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||||
value_after_depreciation -= flt(depreciation_amount)
|
value_after_depreciation -= flt(depreciation_amount)
|
||||||
|
|
||||||
|
# for the last row, if depreciation method = Straight Line
|
||||||
if straight_line_idx and i == max(straight_line_idx) - 1:
|
if straight_line_idx and i == max(straight_line_idx) - 1:
|
||||||
book = self.get('finance_books')[cint(d.finance_book_id) - 1]
|
book = self.get('finance_books')[cint(d.finance_book_id) - 1]
|
||||||
depreciation_amount += flt(value_after_depreciation -
|
depreciation_amount += flt(value_after_depreciation -
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ frappe.ui.form.on('Asset Repair', {
|
|||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frm.toggle_display(['completion_date', 'repair_status', 'accounting_details', 'accounting_dimensions_section'], !(frm.doc.__islocal));
|
frm.toggle_display(['completion_date', 'repair_status', 'accounting_details', 'accounting_dimensions_section'], !(frm.doc.__islocal));
|
||||||
frm.toggle_display(['stock_consumption_details_section', 'total_repair_cost'], frm.doc.stock_consumption)
|
frm.toggle_display(['stock_consumption_details_section', 'total_repair_cost'], frm.doc.stock_consumption);
|
||||||
|
frm.toggle_display('asset_depreciation_details_section', frm.doc.capitalize_repair_cost);
|
||||||
|
|
||||||
if (frm.doc.docstatus) {
|
if (frm.doc.docstatus) {
|
||||||
frm.add_custom_button("View General Ledger", function() {
|
frm.add_custom_button("View General Ledger", function() {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class AssetRepair(Document):
|
|||||||
if self.capitalize_repair_cost:
|
if self.capitalize_repair_cost:
|
||||||
self.check_for_purchase_invoice()
|
self.check_for_purchase_invoice()
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
|
self.modify_depreciation_schedule()
|
||||||
|
|
||||||
def check_repair_status(self):
|
def check_repair_status(self):
|
||||||
if self.repair_status == "Pending":
|
if self.repair_status == "Pending":
|
||||||
@@ -140,8 +141,16 @@ class AssetRepair(Document):
|
|||||||
for account in asset_category.accounts:
|
for account in asset_category.accounts:
|
||||||
if account.company_name == company:
|
if account.company_name == company:
|
||||||
return account.fixed_asset_account
|
return account.fixed_asset_account
|
||||||
|
|
||||||
|
def modify_depreciation_schedule(self):
|
||||||
|
if self.increase_in_asset_life:
|
||||||
|
asset = frappe.get_doc('Asset', self.asset)
|
||||||
|
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.prepare_depreciation_data()
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
Reference in New Issue
Block a user