From deff57826a33131cde4193cc7355e52356ea9eab Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 24 Jul 2013 11:30:35 +0530 Subject: [PATCH] [minor] [fix] fetch contact details --- .../purchase_common/purchase_common.js | 2 +- selling/doctype/sales_common/sales_common.js | 2 +- utilities/transaction_base.py | 50 +++++++++++-------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index c05eba8aa3..e15e076412 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -104,7 +104,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ if (this.frm.doc.supplier) { wn.call({ doc: this.frm.doc, - method: "get_supplier_address", + method: "set_supplier_address", freeze: true, args: { supplier: this.frm.doc.supplier, diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index e3e5f87f13..e9f185b5db 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -163,7 +163,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ address: this.frm.doc.customer_address, contact: this.frm.doc.contact_person }, - method: "get_customer_address", + method: "set_customer_address", freeze: true, callback: function(r) { me.frm.refresh_fields(); diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 8f168f6479..de229b9162 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -149,7 +149,10 @@ class TransactionBase(StatusUpdater): ret.update(map_party_contact_details(args['contact'])) return ret - + + def set_customer_address(self, args): + self.doc.fields.update(self.get_customer_address(args)) + # TODO deprecate this - used only in sales_order.js def get_shipping_address(self, name): shipping_address = get_default_address("customer", name, is_shipping_address=True) @@ -183,6 +186,9 @@ class TransactionBase(StatusUpdater): } ret.update(map_party_contact_details(contact_name=args['contact'])) return ret + + def set_supplier_address(self, args): + self.doc.fields.update(self.get_supplier_address(args)) # Get Supplier Details # ----------------------- @@ -389,27 +395,29 @@ def map_party_contact_details(contact_name=None, party_field=None, party_name=No for fieldname in ["contact_person", "contact_display", "contact_email", "contact_mobile", "contact_phone", "contact_designation", "contact_department"]: out[fieldname] = None - - if not contact_name: - contact_name = get_default_contact(party_field, party_name) - if party_field: - contact = webnotes.conn.sql("""select * from `tabContact` where `%s`=%s - order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"), - (party_name,), as_dict=True) + + condition = "" + if contact_name: + condition = " name = '%s'" % contact_name + elif party_field and party_name: + condition = " `%s`='%s'" % (party_field, party_name) + + contact = webnotes.conn.sql("""select * from `tabContact` where %s + order by is_primary_contact desc, name asc limit 1""" % condition, as_dict=True) - if contact: - contact = contact[0] - out.update({ - "contact_person": contact.get("name"), - "contact_display": " ".join(filter(None, - [contact.get("first_name"), contact.get("last_name")])), - "contact_email": contact.get("email_id"), - "contact_mobile": contact.get("mobile_no"), - "contact_phone": contact.get("phone"), - "contact_designation": contact.get("designation"), - "contact_department": contact.get("department") - }) - + if contact: + contact = contact[0] + out.update({ + "contact_person": contact.get("name"), + "contact_display": " ".join(filter(None, + [contact.get("first_name"), contact.get("last_name")])), + "contact_email": contact.get("email_id"), + "contact_mobile": contact.get("mobile_no"), + "contact_phone": contact.get("phone"), + "contact_designation": contact.get("designation"), + "contact_department": contact.get("department") + }) + return out def get_address_territory(address_doc):