fix: refactor reverse_depreciation_entry_made_after_disposal and fix fb bug
diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js
index f937993..aa73a22 100644
--- a/erpnext/assets/doctype/asset/asset.js
+++ b/erpnext/assets/doctype/asset/asset.js
@@ -281,17 +281,6 @@
// frm.toggle_reqd("next_depreciation_date", (!frm.doc.is_existing_asset && frm.doc.calculate_depreciation));
},
- make_schedules_editable: function(frm) {
- if (frm.doc.finance_books) {
- var is_editable = frm.doc.finance_books.filter(d => d.depreciation_method == "Manual").length > 0
- ? true : false;
-
- frm.toggle_enable("schedules", is_editable);
- frm.fields_dict["schedules"].grid.toggle_enable("schedule_date", is_editable);
- frm.fields_dict["schedules"].grid.toggle_enable("depreciation_amount", is_editable);
- }
- },
-
make_sales_invoice: function(frm) {
frappe.call({
args: {
@@ -487,7 +476,6 @@
depreciation_method: function(frm, cdt, cdn) {
const row = locals[cdt][cdn];
frm.events.set_depreciation_rate(frm, row);
- frm.events.make_schedules_editable(frm);
},
expected_value_after_useful_life: function(frm, cdt, cdn) {
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index ba4c7b0..9bc3a48 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -12,6 +12,7 @@
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
get_asset_depr_schedule_name,
+ get_depr_schedule_from_asset_depr_schedule_of_asset,
get_temp_asset_depr_schedule_doc,
make_new_active_asset_depr_schedules_and_cancel_current_ones,
)
@@ -287,31 +288,26 @@
def reverse_depreciation_entry_made_after_disposal(asset, date):
- row = -1
- finance_book = asset.get("schedules")[0].get("finance_book")
- for schedule in asset.get("schedules"):
- if schedule.finance_book != finance_book:
- row = 0
- finance_book = schedule.finance_book
- else:
- row += 1
+ for row in asset.get("finance_books"):
+ depr_schedule = get_depr_schedule_from_asset_depr_schedule_of_asset(asset, row.finance_book)
- if schedule.schedule_date == date:
- if not disposal_was_made_on_original_schedule_date(
- asset, schedule, row, date
- ) or disposal_happens_in_the_future(date):
+ for schedule_idx, schedule in enumerate(depr_schedule):
+ if schedule.schedule_date == date:
+ if not disposal_was_made_on_original_schedule_date(
+ asset, schedule, schedule_idx, date
+ ) or disposal_happens_in_the_future(date):
- reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
- reverse_journal_entry.posting_date = nowdate()
- frappe.flags.is_reverse_depr_entry = True
- reverse_journal_entry.submit()
+ reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
+ reverse_journal_entry.posting_date = nowdate()
+ frappe.flags.is_reverse_depr_entry = True
+ reverse_journal_entry.submit()
- frappe.flags.is_reverse_depr_entry = False
- asset.flags.ignore_validate_update_after_submit = True
- schedule.journal_entry = None
- depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
- asset.finance_books[0].value_after_depreciation += depreciation_amount
- asset.save()
+ frappe.flags.is_reverse_depr_entry = False
+ asset.flags.ignore_validate_update_after_submit = True
+ schedule.journal_entry = None
+ depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
+ row.value_after_depreciation += depreciation_amount
+ asset.save()
def get_depreciation_amount_in_je(journal_entry):