mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-24 05:32:46 +01:00
fix: handle_post_depr_entries_fail, show error alert and send email
This commit is contained in:
@@ -136,6 +136,10 @@ frappe.ui.form.on('Asset', {
|
|||||||
}, __("Manage"));
|
}, __("Manage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (frm.doc.depr_entry_posting_status === "Failed") {
|
||||||
|
frm.trigger("set_depr_posting_failure_alert");
|
||||||
|
}
|
||||||
|
|
||||||
frm.trigger("setup_chart");
|
frm.trigger("setup_chart");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +150,19 @@ frappe.ui.form.on('Asset', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
set_depr_posting_failure_alert: function (frm) {
|
||||||
|
const alert = `
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
<span class="indicator whitespace-nowrap red">
|
||||||
|
<span>Failed to post depreciation entries</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
frm.dashboard.set_headline_alert(alert);
|
||||||
|
},
|
||||||
|
|
||||||
toggle_reference_doc: function(frm) {
|
toggle_reference_doc: function(frm) {
|
||||||
if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) {
|
if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) {
|
||||||
frm.set_df_property('purchase_invoice', 'read_only', 1);
|
frm.set_df_property('purchase_invoice', 'read_only', 1);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
"column_break_51",
|
"column_break_51",
|
||||||
"purchase_receipt_amount",
|
"purchase_receipt_amount",
|
||||||
"default_finance_book",
|
"default_finance_book",
|
||||||
|
"depr_entry_posting_status",
|
||||||
"amended_from"
|
"amended_from"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -488,6 +489,16 @@
|
|||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Asset Quantity",
|
"label": "Asset Quantity",
|
||||||
"read_only_depends_on": "eval:!doc.is_existing_asset"
|
"read_only_depends_on": "eval:!doc.is_existing_asset"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "depr_entry_posting_status",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Depreciation Entry Posting Status",
|
||||||
|
"no_copy": 1,
|
||||||
|
"options": "\nSuccessful\nFailed",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 72,
|
"idx": 72,
|
||||||
@@ -510,7 +521,7 @@
|
|||||||
"link_fieldname": "asset"
|
"link_fieldname": "asset"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2022-07-20 10:15:12.887372",
|
"modified": "2022-12-05 16:21:30.024060",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import add_months, cint, flt, getdate, nowdate, today
|
from frappe.utils import add_months, cint, flt, getdate, nowdate, today
|
||||||
|
from frappe.utils.user import get_users_with_role
|
||||||
|
from frappe.utils.data import get_link_to_form
|
||||||
|
|
||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
get_checks_for_pl_and_bs_accounts,
|
get_checks_for_pl_and_bs_accounts,
|
||||||
@@ -12,7 +15,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
|||||||
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
|
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
|
||||||
|
|
||||||
|
|
||||||
def post_depreciation_entries(date=None, commit=True):
|
def post_depreciation_entries(date=None):
|
||||||
# Return if automatic booking of asset depreciation is disabled
|
# Return if automatic booking of asset depreciation is disabled
|
||||||
if not cint(
|
if not cint(
|
||||||
frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically")
|
frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically")
|
||||||
@@ -21,10 +24,22 @@ def post_depreciation_entries(date=None, commit=True):
|
|||||||
|
|
||||||
if not date:
|
if not date:
|
||||||
date = today()
|
date = today()
|
||||||
for asset in get_depreciable_assets(date):
|
|
||||||
make_depreciation_entry(asset, date)
|
failed_asset_names = []
|
||||||
if commit:
|
|
||||||
|
for asset_name in get_depreciable_assets(date):
|
||||||
|
try:
|
||||||
|
make_depreciation_entry(asset_name, date)
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
except Exception as e:
|
||||||
|
frappe.db.rollback()
|
||||||
|
failed_asset_names.append(asset_name)
|
||||||
|
|
||||||
|
if failed_asset_names:
|
||||||
|
mark_asset_depr_entry_posting_status_as_failed(failed_asset_names)
|
||||||
|
notify_depr_entry_posting_error_to_account_managers(failed_asset_names)
|
||||||
|
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
|
|
||||||
def get_depreciable_assets(date):
|
def get_depreciable_assets(date):
|
||||||
@@ -123,6 +138,10 @@ def make_depreciation_entry(asset_name, date=None):
|
|||||||
finance_books.value_after_depreciation -= d.depreciation_amount
|
finance_books.value_after_depreciation -= d.depreciation_amount
|
||||||
finance_books.db_update()
|
finance_books.db_update()
|
||||||
|
|
||||||
|
asset.flags.ignore_validate_update_after_submit = True
|
||||||
|
asset.depr_entry_posting_status = "Successful"
|
||||||
|
asset.save()
|
||||||
|
|
||||||
asset.set_status()
|
asset.set_status()
|
||||||
|
|
||||||
return asset
|
return asset
|
||||||
@@ -186,6 +205,47 @@ def get_credit_and_debit_accounts(accumulated_depreciation_account, depreciation
|
|||||||
return credit_account, debit_account
|
return credit_account, debit_account
|
||||||
|
|
||||||
|
|
||||||
|
def mark_asset_depr_entry_posting_status_as_failed(failed_asset_names):
|
||||||
|
for asset_name in failed_asset_names:
|
||||||
|
asset = frappe.get_doc("Asset", asset_name)
|
||||||
|
asset.flags.ignore_validate_update_after_submit = True
|
||||||
|
asset.depr_entry_posting_status = "Failed"
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
|
||||||
|
def notify_depr_entry_posting_error_to_account_managers(failed_asset_names):
|
||||||
|
recipients = get_users_with_role("Accounts Manager")
|
||||||
|
|
||||||
|
if not recipients:
|
||||||
|
recipients = get_users_with_role("System Manager")
|
||||||
|
|
||||||
|
subject = _("Error while posting depreciation entries")
|
||||||
|
|
||||||
|
asset_links = get_comma_separated_asset_links(failed_asset_names)
|
||||||
|
|
||||||
|
message = (
|
||||||
|
_("Hi,")
|
||||||
|
+ "<br>"
|
||||||
|
+_(
|
||||||
|
"The following assets have failed to post depreciation entries: {0}"
|
||||||
|
).format(asset_links)
|
||||||
|
+ "."
|
||||||
|
)
|
||||||
|
|
||||||
|
frappe.sendmail(recipients=recipients, subject=subject, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
def get_comma_separated_asset_links(asset_names):
|
||||||
|
asset_links = []
|
||||||
|
|
||||||
|
for asset_name in asset_names:
|
||||||
|
asset_links.append(get_link_to_form("Asset", asset_name))
|
||||||
|
|
||||||
|
asset_links = ", ".join(asset_links)
|
||||||
|
|
||||||
|
return asset_links
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def scrap_asset(asset_name):
|
def scrap_asset(asset_name):
|
||||||
asset = frappe.get_doc("Asset", asset_name)
|
asset = frappe.get_doc("Asset", asset_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user