From 6e56664cb988d5c3dfd2f9ce7fd6196559b4ebd8 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Mon, 10 Jul 2023 13:45:56 +0530 Subject: [PATCH] chore: add asset depr posting error in error log (#36052) (cherry picked from commit 0f9a6ee70acc88a1190fc66fb95a3bd5d6dea02f) --- erpnext/assets/doctype/asset/depreciation.py | 29 ++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 259568a24b1a..e1431eae1761 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -40,6 +40,7 @@ def post_depreciation_entries(date=None): date = today() failed_asset_names = [] + error_log_names = [] for asset_name in get_depreciable_assets(date): asset_doc = frappe.get_doc("Asset", asset_name) @@ -50,10 +51,12 @@ def post_depreciation_entries(date=None): except Exception as e: frappe.db.rollback() failed_asset_names.append(asset_name) + error_log = frappe.log_error(e) + error_log_names.append(error_log.name) if failed_asset_names: set_depr_entry_posting_status_for_failed_assets(failed_asset_names) - notify_depr_entry_posting_error(failed_asset_names) + notify_depr_entry_posting_error(failed_asset_names, error_log_names) frappe.db.commit() @@ -239,7 +242,7 @@ def set_depr_entry_posting_status_for_failed_assets(failed_asset_names): frappe.db.set_value("Asset", asset_name, "depr_entry_posting_status", "Failed") -def notify_depr_entry_posting_error(failed_asset_names): +def notify_depr_entry_posting_error(failed_asset_names, error_log_names): recipients = get_users_with_role("Accounts Manager") if not recipients: @@ -247,7 +250,8 @@ def notify_depr_entry_posting_error(failed_asset_names): subject = _("Error while posting depreciation entries") - asset_links = get_comma_separated_asset_links(failed_asset_names) + asset_links = get_comma_separated_links(failed_asset_names, "Asset") + error_log_links = get_comma_separated_links(error_log_names, "Error Log") message = ( _("Hello,") @@ -257,23 +261,26 @@ def notify_depr_entry_posting_error(failed_asset_names): ) + "." + "

" - + _( - "Please raise a support ticket and share this email, or forward this email to your development team so that they can find the issue in the developer console by manually creating the depreciation entry via the asset's depreciation schedule table." + + _("Here are the error logs for the aforementioned failed depreciation entries: {0}").format( + error_log_links ) + + "." + + "

" + + _("Please share this email with your support team so that they can find and fix the issue.") ) frappe.sendmail(recipients=recipients, subject=subject, message=message) -def get_comma_separated_asset_links(asset_names): - asset_links = [] +def get_comma_separated_links(names, doctype): + links = [] - for asset_name in asset_names: - asset_links.append(get_link_to_form("Asset", asset_name)) + for name in names: + links.append(get_link_to_form(doctype, name)) - asset_links = ", ".join(asset_links) + links = ", ".join(links) - return asset_links + return links @frappe.whitelist()