diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 921c3b57eac..720a1dc208f 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -75,7 +75,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ }, refresh: function(doc) { - frappe.contact_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'}; + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'}; this.frm.toggle_display("supplier_name", (this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier)); diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 98087184468..ce6f4511dd3 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -16,7 +16,7 @@ frappe.ui.form.on("Supplier", { }); }, refresh: function(frm) { - frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Supplier'} + frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Supplier'} if(frappe.defaults.get_default("supp_master_name")!="Naming Series") { frm.toggle_display("naming_series", false); diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index d7d412a1e12..32171b06010 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -52,9 +52,9 @@ frappe.ui.form.on("Opportunity", { set_contact_link: function(frm) { if(frm.doc.customer) { - frappe.contact_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} } else if(frm.doc.lead) { - frappe.contact_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'} + frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'} } }, diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js index b5d1ad320f6..9639e7faa2d 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js +++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js @@ -23,7 +23,7 @@ frappe.ui.form.on('Maintenance Schedule', { // TODO commonify this code erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({ refresh: function() { - frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} var me = this; diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js index 1a3c35cc06e..62cdf865e0a 100644 --- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js +++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js @@ -25,7 +25,7 @@ frappe.ui.form.on('Maintenance Visit', { // TODO commonify this code erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({ refresh: function() { - frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Maintenance Schedule'), diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index 8236ce7ae6b..1141f99623b 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -43,28 +43,28 @@ $.extend(erpnext.queries, { }, contact_query: function(doc) { - if(frappe.contact_link) { - if(!doc[frappe.contact_link.fieldname]) { + if(frappe.dynamic_link) { + if(!doc[frappe.dynamic_link.fieldname]) { frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype, - frappe.contact_link.fieldname, doc.name)))); + frappe.dynamic_link.fieldname, doc.name)))); } return { query: 'frappe.email.doctype.contact.contact.contact_query', - filters: { link_doctype: frappe.contact_link.doctype, link_name: doc[frappe.contact_link.fieldname] } }; + filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } }; } }, address_query: function(doc) { - if(frappe.contact_link) { - if(!doc[frappe.contact_link.fieldname]) { + if(frappe.dynamic_link) { + if(!doc[frappe.dynamic_link.fieldname]) { frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype, - frappe.contact_link.fieldname, doc.name)))); + frappe.dynamic_link.fieldname, doc.name)))); } return { - query: 'frappe.email.doctype.address.address_query', - filters: { link_doctype: frappe.contact_link.doctype, link_name: doc[frappe.contact_link.fieldname] } }; + query: 'frappe.geo.doctype.address.address.address_query', + filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } }; } }, diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 975604deb4a..747b31e13dd 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -32,7 +32,7 @@ frappe.ui.form.on("Customer", { erpnext.toggle_naming_series(); } - frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'} + frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'} frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index ab1a24a80ab..e06f96307fc 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -67,12 +67,8 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer"); // to overwrite the customer_filter trigger from queries.js - $.each(["customer_address", "shipping_address_name"], - function(i, opts) { - me.frm.set_query(opts, me.frm.doc.quotation_to==="Lead" - ? erpnext.queries["lead_filter"] : erpnext.queries["customer_filter"]); - } - ); + this.frm.set_query('customer_address', erpnext.queries.address_query); + this.frm.set_query('shipping_address_name', erpnext.queries.address_query); }, tc_name: function() { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 96ce79acb04..9d9511e7cbc 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -106,7 +106,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ refresh: function() { this._super(); - frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} this.frm.toggle_display("customer_name", (this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer)); diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js index 653163075bd..df8d23f7af3 100644 --- a/erpnext/setup/doctype/sales_partner/sales_partner.js +++ b/erpnext/setup/doctype/sales_partner/sales_partner.js @@ -3,7 +3,7 @@ frappe.ui.form.on('Sales Partner', { refresh: function(frm) { - frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Person'} + frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Person'} if(doc.__islocal){ hide_field(['address_html', 'contact_html']); diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index e52ef8105d9..5ca0315ccc9 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -375,15 +375,17 @@ def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_ if not party: return [] - address_docs = frappe.db.sql("""select * from `tabAddress` - where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(), - limit_start, limit_page_length), party.name, - as_dict=True, update={"doctype": "Address"}) + address_names = frappe.db.get_all('Dyanamic Link', fields=('parent'), + filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name)) - for address in address_docs: - address.display = get_address_display(address) + out = [] - return address_docs + for address_name in address_names: + address = frappe.get_doc('Address', address_name) + address.display = get_address_display(address.as_dict()) + out.append(address) + + return out @frappe.whitelist() def apply_shipping_rule(shipping_rule): diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js index abd207b9e49..2369a8ac01f 100644 --- a/erpnext/support/doctype/warranty_claim/warranty_claim.js +++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js @@ -21,7 +21,7 @@ frappe.ui.form.on("Warranty Claim", { erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({ refresh: function() { - frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} if(!cur_frm.doc.__islocal && (cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) { diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py index eaa71f9b1fc..f3435aeed4f 100644 --- a/erpnext/utilities/address_and_contact.py +++ b/erpnext/utilities/address_and_contact.py @@ -122,7 +122,7 @@ def get_permitted_and_not_permitted_links(doctype): def delete_contact_and_address(doctype, name): for parenttype in ('Contact', 'Address'): items = frappe.db.sql("""select parent from `tabDynamic Link` - where parenttype=%s and link_type=%s and link_name=%s""", + where parenttype=%s and link_doctype=%s and link_name=%s""", (parenttype, doctype, name)) for name in items: