|
7 | 7 |
|
8 | 8 | import frappe |
9 | 9 | from frappe import _ |
10 | | -from frappe.utils import add_days, cint, flt, nowdate |
| 10 | +from frappe.utils import add_days, cint, escape_html, flt, nowdate |
11 | 11 |
|
12 | 12 | import erpnext |
13 | 13 |
|
@@ -223,15 +223,6 @@ def create_material_request(material_requests): |
223 | 223 | mr_list = [] |
224 | 224 | exceptions_list = [] |
225 | 225 |
|
226 | | - def _log_exception(mr): |
227 | | - if frappe.local.message_log: |
228 | | - exceptions_list.extend(frappe.local.message_log) |
229 | | - frappe.local.message_log = [] |
230 | | - else: |
231 | | - exceptions_list.append(frappe.get_traceback(with_context=True)) |
232 | | - |
233 | | - mr.log_error("Unable to create material request") |
234 | | - |
235 | 226 | company_wise_mr = frappe._dict({}) |
236 | 227 | for request_type in material_requests: |
237 | 228 | for company in material_requests[request_type]: |
@@ -305,8 +296,9 @@ def _log_exception(mr): |
305 | 296 |
|
306 | 297 | company_wise_mr.setdefault(company, []).append(mr) |
307 | 298 |
|
308 | | - except Exception: |
309 | | - _log_exception(mr) |
| 299 | + except Exception as exception: |
| 300 | + exceptions_list.append(exception) |
| 301 | + mr.log_error("Unable to create material request") |
310 | 302 |
|
311 | 303 | if company_wise_mr: |
312 | 304 | if getattr(frappe.local, "reorder_email_notify", None) is None: |
@@ -391,10 +383,7 @@ def notify_errors(exceptions_list): |
391 | 383 |
|
392 | 384 | for exception in exceptions_list: |
393 | 385 | try: |
394 | | - exception = json.loads(exception) |
395 | | - error_message = """<div class='small text-muted'>{}</div><br>""".format( |
396 | | - _(exception.get("message")) |
397 | | - ) |
| 386 | + error_message = f"<div class='small text-muted'>{escape_html(str(exception))}</div><br>" |
398 | 387 | content += error_message |
399 | 388 | except Exception: |
400 | 389 | pass |
|
0 commit comments