From fcc0246b3820d59d87a3212346eed395e654fabb Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 4 May 2017 12:11:48 +0530 Subject: [PATCH] Get mobile nos for customer contact (#8674) --- erpnext/public/js/sms_manager.js | 16 ++++++++-------- .../setup/doctype/sms_settings/sms_settings.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/erpnext/public/js/sms_manager.js b/erpnext/public/js/sms_manager.js index a06c43c6f5..d6293ea107 100644 --- a/erpnext/public/js/sms_manager.js +++ b/erpnext/public/js/sms_manager.js @@ -21,9 +21,9 @@ function SMSManager(doc) { } if (in_list(['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice'], doc.doctype)) - this.show(doc.contact_person, 'customer', doc.customer, '', default_msg[doc.doctype]); + this.show(doc.contact_person, 'Customer', doc.customer, '', default_msg[doc.doctype]); else if (in_list(['Purchase Order', 'Purchase Receipt'], doc.doctype)) - this.show(doc.contact_person, 'supplier', doc.supplier, '', default_msg[doc.doctype]); + this.show(doc.contact_person, 'Supplier', doc.supplier, '', default_msg[doc.doctype]); else if (doc.doctype == 'Lead') this.show('', '', '', doc.mobile_no, default_msg[doc.doctype]); else if (doc.doctype == 'Opportunity') @@ -33,13 +33,13 @@ function SMSManager(doc) { }; - this.get_contact_number = function(contact, key, value) { + this.get_contact_number = function(contact, ref_doctype, ref_name) { frappe.call({ method: "erpnext.setup.doctype.sms_settings.sms_settings.get_contact_number", args: { - contact_name:contact, - value:value, - key:key + contact_name: contact, + ref_doctype: ref_doctype, + ref_name: ref_name }, callback: function(r) { if(r.exc) { msgprint(r.exc); return; } @@ -49,13 +49,13 @@ function SMSManager(doc) { }); }; - this.show = function(contact, key, value, mobile_nos, message) { + this.show = function(contact, ref_doctype, ref_name, mobile_nos, message) { this.message = message; if (mobile_nos) { me.number = mobile_nos; me.show_dialog(); } else if (contact){ - this.get_contact_number(contact, key, value) + this.get_contact_number(contact, ref_doctype, ref_name) } else { me.show_dialog(); } diff --git a/erpnext/setup/doctype/sms_settings/sms_settings.py b/erpnext/setup/doctype/sms_settings/sms_settings.py index 2888942613..a8b59beffa 100644 --- a/erpnext/setup/doctype/sms_settings/sms_settings.py +++ b/erpnext/setup/doctype/sms_settings/sms_settings.py @@ -40,10 +40,15 @@ def get_sender_name(): return sender_name @frappe.whitelist() -def get_contact_number(contact_name, value, key): +def get_contact_number(contact_name, ref_doctype, ref_name): "returns mobile number of the contact" - number = frappe.db.sql("""select mobile_no, phone from tabContact where name=%s and %s=%s""" % - ('%s', frappe.db.escape(key), '%s'), (contact_name, value)) + number = frappe.db.sql("""select mobile_no, phone from tabContact + where name=%s + and exists( + select name from `tabDynamic Link` where link_doctype=%s and link_name=%s + ) + """, (contact_name, ref_doctype, ref_name)) + return number and (number[0][0] or number[0][1]) or '' @frappe.whitelist()