the error saved in error log but does not display in list view and display in form view?
import frappe
from frappe import _
from frappe.core.doctype.sms_settings.sms_settings import send_sms
def after_insert(doc, method=None):
try:
if doc.party_type == "Customer":
path = str(frappe.local.request.path)
if path in ['/api/method/frappe.model.workflow.apply_workflow',
'/api/method/frappe.desk.form.save.savedocs',
'/api/method/frappe.model.workflow.bulk_workflow_approval'] and not path in ['/api/method/erpnext.controllers.stock_controller.show_accounting_ledger_preview']:
list_no = []
number = 0
# Get all Contacts that have the Customer as DynamicLink
DynamicLink = frappe.qb.DocType("Dynamic Link")
Contacts = (
frappe.qb.from_(DynamicLink)
.select(DynamicLink.parent)
.where(
(DynamicLink.parenttype == "Contact")
& (DynamicLink.link_doctype == doc.party_type)
& (DynamicLink.link_name == doc.party)
)
.orderby('modified', order=frappe.qb.desc)
).run(as_dict=True)
# Retrieve primary mobile number
for row in Contacts:
ContactPhone = frappe.qb.DocType("Contact Phone")
ContactPhoneData = (
frappe.qb.from_(ContactPhone)
.select(ContactPhone.Phone)
.where(
(ContactPhone.parent == row.parent)
& (ContactPhone.is_primary_mobile_no == 1)
)
).run(as_dict=True)
if ContactPhoneData:
number = ContactPhoneData[0].Phone
break
if number != 0:
list_no.append(str(number))
if len(list_no) > 0:
msg = ""
if doc.debit == 0.0:
number_as_string = str(doc.credit)
first_number_after_decimal = int(number_as_string.split('.')[1][0])
round_amount = int(number_as_string.split('.')[0]) + (1 if first_number_after_decimal >= 5 else 0)
msg = " تم إضافة " + "{:,.0f}".format(round_amount) + _(doc.account_currency)
elif doc.credit == 0.0:
number_as_string = str(doc.debit)
first_number_after_decimal = int(number_as_string.split('.')[1][0])
round_amount = int(number_as_string.split('.')[0]) + (1 if first_number_after_decimal >= 5 else 0)
msg = " تم خصم " + "{:,.0f}".format(round_amount) + _(doc.account_currency)
if doc.voucher_type != "Journal Entry":
Voucher = frappe.qb.DocType(doc.voucher_type)
receipt_number = (
frappe.qb.from_(Voucher)
.select(Voucher.custom_receipt_number)
.where(Voucher.name == doc.voucher_no)
).run(as_dict=True)[0].custom_receipt_number
sales_invoice_id = doc.voucher_no.split("-")[1]
msg += " لفاتورة " + str(sales_invoice_id)
msg += " بإيصال " + str(receipt_number)
send_sms(list_no, msg)
else:
raise ValueError("Can not send sms Tell IT manager")
else:
raise ValueError("Can not send sms Tell IT manager")
except Exception as e:
error_message = f"Error in after_insert: {str(e)}"
frappe.msgprint(error_message)
frappe.log_error(message=error_message, title="SMS Sending Error")*emphasized text*