fetch customer/supplier given a contact in communication
This commit is contained in:
parent
3ee7bb5ead
commit
a65ad2c901
@ -92,3 +92,22 @@ cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView, make_new
|
|||||||
var record_list_view = new RecordListView(doctype, wrapper, ListView);
|
var record_list_view = new RecordListView(doctype, wrapper, ListView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cur_frm.cscript.contact = function(doc, dt, dn) {
|
||||||
|
if (doc.contact) {
|
||||||
|
wn.call({
|
||||||
|
method: 'support.doctype.communication.communication.get_customer_supplier',
|
||||||
|
args: {
|
||||||
|
contact: doc.contact
|
||||||
|
},
|
||||||
|
callback: function(r, rt) {
|
||||||
|
if (!r.exc && r.message) {
|
||||||
|
doc = locals[doc.doctype][doc.name];
|
||||||
|
doc[r.message['fieldname']] = r.message['value'];
|
||||||
|
refresh_field(r.message['fieldname']);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,26 @@
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.model.doc import make_autoname
|
from webnotes.model.doc import make_autoname
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_customer_supplier(args=None):
|
||||||
|
"""
|
||||||
|
Get Customer/Supplier, given a contact, if a unique match exists
|
||||||
|
"""
|
||||||
|
import webnotes
|
||||||
|
if not args: args = webnotes.form_dict
|
||||||
|
if not args.get('contact'):
|
||||||
|
raise Exception, "Please specify a contact to fetch Customer/Supplier"
|
||||||
|
result = webnotes.conn.sql("""\
|
||||||
|
select customer, supplier
|
||||||
|
from `tabContact`
|
||||||
|
where name = %s""", args.get('contact'), as_dict=1)
|
||||||
|
if result and len(result)==1 and (result[0]['customer'] or result[0]['supplier']):
|
||||||
|
return {
|
||||||
|
'fieldname': result[0]['customer'] and 'customer' or 'supplier',
|
||||||
|
'value': result[0]['customer'] or result[0]['supplier']
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
|
||||||
class DocType():
|
class DocType():
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user