From b3a99e38cc1cd7319ab91a860e83d10dbc91164d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:31:19 +0530 Subject: [PATCH] chore: add asset depr posting error in error log (backport #36052) (#36055) chore: add asset depr posting error in error log (#36052) (cherry picked from commit 0f9a6ee70acc88a1190fc66fb95a3bd5d6dea02f) Co-authored-by: Anand Baburajan --- 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 259568a24b..e1431eae17 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()