Skip to content

Commit

Permalink
chore: add asset depr posting error in error log (backport #36052) (#…
Browse files Browse the repository at this point in the history
…36055)

chore: add asset depr posting error in error log (#36052)

(cherry picked from commit 0f9a6ee)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
  • Loading branch information
mergify[bot] and anandbaburajan authored Jul 10, 2023
1 parent 22eee47 commit b3a99e3
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions erpnext/assets/doctype/asset/depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -239,15 +242,16 @@ 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:
recipients = get_users_with_role("System Manager")

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,")
Expand All @@ -257,23 +261,26 @@ def notify_depr_entry_posting_error(failed_asset_names):
)
+ "."
+ "<br><br>"
+ _(
"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
)
+ "."
+ "<br><br>"
+ _("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()
Expand Down

0 comments on commit b3a99e3

Please sign in to comment.