Skip to content

Commit

Permalink
fix: asset repair status after deletion and asset status after manual…
Browse files Browse the repository at this point in the history
… depr entry

(cherry picked from commit 03f07a2)

# Conflicts:
#	erpnext/assets/doctype/asset/asset.py
  • Loading branch information
anandbaburajan authored and mergify[bot] committed Feb 17, 2023
1 parent 5fc68a3 commit 922b30a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
22 changes: 7 additions & 15 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,16 @@ def update_asset_value(self):
):
processed_assets.append(d.reference_name)

asset = frappe.db.get_value(
"Asset", d.reference_name, ["calculate_depreciation", "value_after_depreciation"], as_dict=1
)
asset = frappe.get_doc("Asset", d.reference_name)

if asset.calculate_depreciation:
continue

depr_value = d.debit or d.credit

frappe.db.set_value(
"Asset",
d.reference_name,
"value_after_depreciation",
asset.value_after_depreciation - depr_value,
)
asset.db_set("value_after_depreciation", asset.value_after_depreciation - depr_value)

asset.set_status()

def update_inter_company_jv(self):
if (
Expand Down Expand Up @@ -351,12 +346,9 @@ def unlink_asset_reference(self):
else:
depr_value = d.debit or d.credit

frappe.db.set_value(
"Asset",
d.reference_name,
"value_after_depreciation",
asset.value_after_depreciation + depr_value,
)
asset.db_set("value_after_depreciation", asset.value_after_depreciation + depr_value)

asset.set_status()

def unlink_inter_company_jv(self):
if (
Expand Down
2 changes: 1 addition & 1 deletion erpnext/assets/doctype/asset/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ frappe.ui.form.on('Asset', {
$.each(depr_entries || [], function(i, v) {
x_intervals.push(frappe.format(v.posting_date, { fieldtype: 'Date' }));
let last_asset_value = asset_values[asset_values.length - 1]
asset_values.push(last_asset_value - v.value);
asset_values.push(flt(last_asset_value - v.value, precision('gross_purchase_amount')));
});
}

Expand Down
34 changes: 30 additions & 4 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,15 @@ def get_status(self):

if self.journal_entry_for_scrap:
status = "Scrapped"
elif self.finance_books:
idx = self.get_default_finance_book_idx() or 0
else:
expected_value_after_useful_life = 0
value_after_depreciation = self.value_after_depreciation

if self.calculate_depreciation:
idx = self.get_default_finance_book_idx() or 0

expected_value_after_useful_life = self.finance_books[idx].expected_value_after_useful_life
value_after_depreciation = self.finance_books[idx].value_after_depreciation
expected_value_after_useful_life = self.finance_books[idx].expected_value_after_useful_life
value_after_depreciation = self.finance_books[idx].value_after_depreciation

if flt(value_after_depreciation) <= expected_value_after_useful_life:
status = "Fully Depreciated"
Expand Down Expand Up @@ -838,6 +842,28 @@ def make_gl_entries(self):
self.db_set("booked_fixed_asset", 1)

@frappe.whitelist()
<<<<<<< HEAD
=======
def get_manual_depreciation_entries(self):
(_, _, depreciation_expense_account) = get_depreciation_accounts(self)

gle = frappe.qb.DocType("GL Entry")

records = (
frappe.qb.from_(gle)
.select(gle.voucher_no.as_("name"), gle.debit.as_("value"), gle.posting_date)
.where(gle.against_voucher == self.name)
.where(gle.account == depreciation_expense_account)
.where(gle.debit != 0)
.where(gle.is_cancelled == 0)
.orderby(gle.posting_date)
.orderby(gle.creation)
).run(as_dict=True)

return records

@frappe.whitelist()
>>>>>>> 03f07a20e7 (fix: asset repair status after deletion and asset status after manual depr entry)
def get_depreciation_rate(self, args, on_validate=False):
if isinstance(args, string_types):
args = json.loads(args)
Expand Down
2 changes: 1 addition & 1 deletion erpnext/assets/doctype/asset/depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def make_depreciation_entry(asset_name, date=None):
finance_books.value_after_depreciation -= d.depreciation_amount
finance_books.db_update()

frappe.db.set_value("Asset", asset_name, "depr_entry_posting_status", "Successful")
asset.db_set("depr_entry_posting_status", "Successful")

asset.set_status()

Expand Down
3 changes: 3 additions & 0 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def before_cancel(self):
self.asset_doc.prepare_depreciation_data()
self.asset_doc.save()

def after_delete(self):
frappe.get_doc("Asset", self.asset).set_status()

def check_repair_status(self):
if self.repair_status == "Pending":
frappe.throw(_("Please update Repair Status."))
Expand Down

0 comments on commit 922b30a

Please sign in to comment.