Skip to content

Commit

Permalink
fix: manual depr schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
anandbaburajan committed Feb 24, 2023
1 parent 74a3588 commit 971c072
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
18 changes: 11 additions & 7 deletions erpnext/assets/doctype/asset/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,19 +567,23 @@ frappe.ui.form.on('Depreciation Schedule', {
},

depreciation_amount: function(frm, cdt, cdn) {
erpnext.asset.set_accumulated_depreciation(frm);
erpnext.asset.set_accumulated_depreciation(frm, locals[cdt][cdn].finance_book_id);
}

})
});

erpnext.asset.set_accumulated_depreciation = function(frm, finance_book_id) {
var depreciation_method = frm.doc.finance_books[Number(finance_book_id) - 1].depreciation_method;

erpnext.asset.set_accumulated_depreciation = function(frm) {
if(frm.doc.depreciation_method != "Manual") return;
if(depreciation_method != "Manual") return;

var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation);

$.each(frm.doc.schedules || [], function(i, row) {
accumulated_depreciation += flt(row.depreciation_amount);
frappe.model.set_value(row.doctype, row.name,
"accumulated_depreciation_amount", accumulated_depreciation);
if (row.finance_book_id === finance_book_id) {
accumulated_depreciation += flt(row.depreciation_amount);
frappe.model.set_value(row.doctype, row.name, "accumulated_depreciation_amount", accumulated_depreciation);
};
})
};

Expand Down
15 changes: 9 additions & 6 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def prepare_depreciation_data(self, date_of_disposal=None, date_of_return=None):
if self.calculate_depreciation:
self.value_after_depreciation = 0
self.set_depreciation_rate()
self.make_depreciation_schedule(date_of_disposal)
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
if not (
self.get("schedules") and "Manual" in [d.depreciation_method for d in self.finance_books]
):
self.make_depreciation_schedule(date_of_disposal)
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
else:
self.finance_books = []
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(
Expand Down Expand Up @@ -225,9 +228,7 @@ def set_depreciation_rate(self):
)

def make_depreciation_schedule(self, date_of_disposal):
if "Manual" not in [d.depreciation_method for d in self.finance_books] and not self.get(
"schedules"
):
if not self.get("schedules"):
self.schedules = []

if not self.available_for_use_date:
Expand Down Expand Up @@ -556,7 +557,9 @@ def set_accumulated_depreciation(
self, date_of_disposal=None, date_of_return=None, ignore_booked_entry=False
):
straight_line_idx = [
d.idx for d in self.get("schedules") if d.depreciation_method == "Straight Line"
d.idx
for d in self.get("schedules")
if d.depreciation_method == "Straight Line" or d.depreciation_method == "Manual"
]
finance_books = []

Expand Down

0 comments on commit 971c072

Please sign in to comment.