mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
fix: cannot save customer email & phone (#23797)
This commit is contained in:
@@ -229,13 +229,31 @@ def set_customer_info(fieldname, customer, value=""):
|
|||||||
frappe.db.set_value('Customer', customer, 'loyalty_program', value)
|
frappe.db.set_value('Customer', customer, 'loyalty_program', value)
|
||||||
|
|
||||||
contact = frappe.get_cached_value('Customer', customer, 'customer_primary_contact')
|
contact = frappe.get_cached_value('Customer', customer, 'customer_primary_contact')
|
||||||
|
if not contact:
|
||||||
|
contact = frappe.db.sql("""
|
||||||
|
SELECT parent FROM `tabDynamic Link`
|
||||||
|
WHERE
|
||||||
|
parenttype = 'Contact' AND
|
||||||
|
parentfield = 'links' AND
|
||||||
|
link_doctype = 'Customer' AND
|
||||||
|
link_name = %s
|
||||||
|
""", (customer), as_dict=1)
|
||||||
|
contact = contact[0].get('parent') if contact else None
|
||||||
|
|
||||||
if contact:
|
if not contact:
|
||||||
contact_doc = frappe.get_doc('Contact', contact)
|
new_contact = frappe.new_doc('Contact')
|
||||||
if fieldname == 'email_id':
|
new_contact.is_primary_contact = 1
|
||||||
contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}])
|
new_contact.first_name = customer
|
||||||
frappe.db.set_value('Customer', customer, 'email_id', value)
|
new_contact.set('links', [{'link_doctype': 'Customer', 'link_name': customer}])
|
||||||
elif fieldname == 'mobile_no':
|
new_contact.save()
|
||||||
contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}])
|
contact = new_contact.name
|
||||||
frappe.db.set_value('Customer', customer, 'mobile_no', value)
|
frappe.db.set_value('Customer', customer, 'customer_primary_contact', contact)
|
||||||
contact_doc.save()
|
|
||||||
|
contact_doc = frappe.get_doc('Contact', contact)
|
||||||
|
if fieldname == 'email_id':
|
||||||
|
contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}])
|
||||||
|
frappe.db.set_value('Customer', customer, 'email_id', value)
|
||||||
|
elif fieldname == 'mobile_no':
|
||||||
|
contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}])
|
||||||
|
frappe.db.set_value('Customer', customer, 'mobile_no', value)
|
||||||
|
contact_doc.save()
|
||||||
Reference in New Issue
Block a user