diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 91ec8131693..97eef797729 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -1,8 +1,6 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -{% include 'setup/doctype/contact_control/contact_control.js' %}; - cur_frm.cscript.refresh = function(doc, dt, dn) { cur_frm.cscript.make_dashboard(doc); @@ -17,9 +15,8 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { } else{ unhide_field(['address_html','contact_html']); - // make lists - cur_frm.cscript.make_address(doc,dt,dn); - cur_frm.cscript.make_contact(doc,dt,dn); + + erpnext.utils.render_address_and_contact(cur_frm) cur_frm.communication_view = new frappe.views.CommunicationList({ parent: cur_frm.fields_dict.communication_html.wrapper, @@ -60,45 +57,6 @@ cur_frm.cscript.make_dashboard = function(doc) { }) } - -cur_frm.cscript.make_address = function() { - if(!cur_frm.address_list) { - cur_frm.address_list = new frappe.ui.Listing({ - parent: cur_frm.fields_dict['address_html'].wrapper, - page_length: 5, - new_doctype: "Address", - get_query: function() { - return "select name, address_type, address_line1, address_line2, city, state, country, pincode, fax, email_id, phone, is_primary_address, is_shipping_address from tabAddress where supplier='" + - cur_frm.doc.name.replace(/'/g, "\\'") + "' and docstatus != 2 order by is_primary_address desc" - }, - as_dict: 1, - no_results_message: __('No addresses created'), - render_row: cur_frm.cscript.render_address_row, - }); - // note: render_address_row is defined in contact_control.js - } - cur_frm.address_list.run(); -} - -cur_frm.cscript.make_contact = function() { - if(!cur_frm.contact_list) { - cur_frm.contact_list = new frappe.ui.Listing({ - parent: cur_frm.fields_dict['contact_html'].wrapper, - page_length: 5, - new_doctype: "Contact", - get_query: function() { - return "select name, first_name, last_name, email_id, phone, mobile_no, department, designation, is_primary_contact from tabContact where supplier='" + - cur_frm.doc.name.replace(/'/g, "\\'") + "' and docstatus != 2 order by is_primary_contact desc" - }, - as_dict: 1, - no_results_message: __('No contacts created'), - render_row: cur_frm.cscript.render_contact_row, - }); - // note: render_contact_row is defined in contact_control.js - } - cur_frm.contact_list.run(); -} - cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) { return{ filters:{'buying': 1} diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 240762eb2c8..8a0af9c78ae 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -9,10 +9,14 @@ from frappe.utils import cint from frappe import msgprint, _ from frappe.model.naming import make_autoname from erpnext.accounts.party import create_party_account +from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.utilities.transaction_base import TransactionBase class Supplier(TransactionBase): + def onload(self): + """Load address and contacts in `__onload`""" + load_address_and_contact(self, "supplier") def autoname(self): supp_master_name = frappe.defaults.get_global_default('supp_master_name') diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d9a6b649f1d..4c975815c54 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -88,3 +88,4 @@ execute:frappe.delete_doc("DocType", "Purchase Request Item") erpnext.patches.v4_2.recalculate_bom_cost erpnext.patches.v4_2.fix_gl_entries_for_stock_transactions erpnext.patches.v4_2.update_requested_and_ordered_qty +execute:frappe.delete_doc("DocType", "Contact Control") diff --git a/erpnext/public/build.json b/erpnext/public/build.json index 0998c53821b..ac77cfc21be 100644 --- a/erpnext/public/build.json +++ b/erpnext/public/build.json @@ -10,6 +10,8 @@ "public/js/feature_setup.js", "public/js/utils.js", "public/js/queries.js", - "public/js/utils/party.js" + "public/js/utils/party.js", + "public/js/templates/address_list.html", + "public/js/templates/contact_list.html" ] } diff --git a/erpnext/public/js/templates/address_list.html b/erpnext/public/js/templates/address_list.html new file mode 100644 index 00000000000..e85723fe89b --- /dev/null +++ b/erpnext/public/js/templates/address_list.html @@ -0,0 +1,20 @@ +
+{% for(var i=0, l=addr_list.length; i{%= i+1 %}. {%= addr_list[i].address_type %}
+{%= addr_list[i].display %}
+{%= __("No address added yet.") %}
+{% } %} diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html new file mode 100644 index 00000000000..c4c058c117b --- /dev/null +++ b/erpnext/public/js/templates/contact_list.html @@ -0,0 +1,25 @@ + +{% for(var i=0, l=contact_list.length; i{%= i+1 %}. {%= contact_list[i].first_name %} {%= contact_list[i].last_name %}
+
+ {% if(contact_list[i].phone) { %}
+ {%= __("Phone") %}: {%= contact_list[i].phone %}
+ {% } %}
+ {% if(contact_list[i].email_id) { %}
+ {%= __("Email Id") %}: {%= contact_list[i].email_id %}
+ {% } %}
+
{%= __("No contacts added yet.") %}
+{% } %} diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index ef7d03ea458..6a96fac7dbe 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -81,5 +81,28 @@ $.extend(erpnext, { d.show(); }); - } + }, }); + +erpnext.utils = { + render_address_and_contact: function(frm) { + // render address + $(frm.fields_dict['address_html'].wrapper) + .html(frappe.render(frappe.templates.address_list, + cur_frm.doc.__onload)) + .find(".btn-address").on("click", function() { + new_doc("Address"); + }); + + // render contact + if(frm.fields_dict['contact_html']) { + $(frm.fields_dict['contact_html'].wrapper) + .html(frappe.render(frappe.templates.contact_list, + cur_frm.doc.__onload)) + .find(".btn-contact").on("click", function() { + new_doc("Contact"); + } + ); + } + } +} diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index e5d2ca95826..afde2b0d636 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -1,8 +1,6 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -{% include 'setup/doctype/contact_control/contact_control.js' %}; - cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.load_defaults(doc, dt, dn); } @@ -32,8 +30,8 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { }else{ unhide_field(['address_html','contact_html']); // make lists - cur_frm.cscript.make_address(doc, dt, dn); - cur_frm.cscript.make_contact(doc, dt, dn); + + erpnext.utils.render_address_and_contact(cur_frm) cur_frm.communication_view = new frappe.views.CommunicationList({ parent: cur_frm.fields_dict.communication_html.wrapper, @@ -79,44 +77,6 @@ cur_frm.cscript.setup_dashboard = function(doc) { }); } -cur_frm.cscript.make_address = function() { - if(!cur_frm.address_list) { - cur_frm.address_list = new frappe.ui.Listing({ - parent: cur_frm.fields_dict['address_html'].wrapper, - page_length: 5, - new_doctype: "Address", - get_query: function() { - return "select name, address_type, address_line1, address_line2, city, state, country, pincode, fax, email_id, phone, is_primary_address, is_shipping_address from tabAddress where customer='" + - cur_frm.doc.name.replace(/'/g, "\\'") + "' and docstatus != 2 order by is_primary_address desc" - }, - as_dict: 1, - no_results_message: __('No addresses created'), - render_row: cur_frm.cscript.render_address_row, - }); - // note: render_address_row is defined in contact_control.js - } - cur_frm.address_list.run(); -} - -cur_frm.cscript.make_contact = function() { - if(!cur_frm.contact_list) { - cur_frm.contact_list = new frappe.ui.Listing({ - parent: cur_frm.fields_dict['contact_html'].wrapper, - page_length: 5, - new_doctype: "Contact", - get_query: function() { - return "select name, first_name, last_name, email_id, phone, mobile_no, department, designation, is_primary_contact from tabContact where customer='" + - cur_frm.doc.name.replace(/'/g, "\\'") + "' and docstatus != 2 order by is_primary_contact desc" - }, - as_dict: 1, - no_results_message: __('No contacts created'), - render_row: cur_frm.cscript.render_contact_row, - }); - // note: render_contact_row is defined in contact_control.js - } - cur_frm.contact_list.run(); -} - cur_frm.fields_dict['customer_group'].get_query = function(doc, dt, dn) { return{ filters:{'is_group': 'No'} diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 362542e55a0..36af1f51b00 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -7,11 +7,14 @@ from frappe.model.naming import make_autoname from frappe import msgprint, _ import frappe.defaults - from erpnext.utilities.transaction_base import TransactionBase +from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.accounts.party import create_party_account class Customer(TransactionBase): + def onload(self): + """Load address and contacts in `__onload`""" + load_address_and_contact(self, "customer") def autoname(self): cust_master_name = frappe.defaults.get_global_default('cust_master_name') diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js index ca6d0076417..c51892e0c71 100644 --- a/erpnext/selling/doctype/lead/lead.js +++ b/erpnext/selling/doctype/lead/lead.js @@ -1,8 +1,6 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -{% include 'setup/doctype/contact_control/contact_control.js' %}; - frappe.provide("erpnext"); erpnext.LeadController = frappe.ui.form.Controller.extend({ setup: function() { @@ -42,33 +40,10 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({ }); if(!this.frm.doc.__islocal) { - this.make_address_list(); + erpnext.utils.render_address_and_contact(cur_frm); } }, - make_address_list: function() { - var me = this; - if(!this.frm.address_list) { - this.frm.address_list = new frappe.ui.Listing({ - parent: this.frm.fields_dict['address_html'].wrapper, - page_length: 5, - new_doctype: "Address", - get_query: function() { - return 'select name, address_type, address_line1, address_line2, \ - city, state, country, pincode, fax, email_id, phone, \ - is_primary_address, is_shipping_address from tabAddress \ - where lead="'+me.frm.doc.name+'" and docstatus != 2 \ - order by is_primary_address, is_shipping_address desc' - }, - as_dict: 1, - no_results_message: __('No addresses created'), - render_row: this.render_address_row, - }); - // note: render_address_row is defined in contact_control.js - } - this.frm.address_list.run(); - }, - create_customer: function() { frappe.model.open_mapped_doc({ method: "erpnext.selling.doctype.lead.lead.make_customer", diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py index 3c345efc475..98bed4dfc26 100644 --- a/erpnext/selling/doctype/lead/lead.py +++ b/erpnext/selling/doctype/lead/lead.py @@ -9,11 +9,13 @@ from frappe import session from frappe.model.mapper import get_mapped_doc from erpnext.controllers.selling_controller import SellingController +from erpnext.utilities.address_and_contact import load_address_and_contact class Lead(SellingController): def onload(self): customer = frappe.db.get_value("Customer", {"lead_name": self.name}) self.get("__onload").is_customer = customer + load_address_and_contact(self, "lead") def validate(self): self._prev = frappe._dict({ diff --git a/erpnext/setup/doctype/contact_control/README.md b/erpnext/setup/doctype/contact_control/README.md deleted file mode 100644 index ca98eff3766..00000000000 --- a/erpnext/setup/doctype/contact_control/README.md +++ /dev/null @@ -1 +0,0 @@ -[To deprecate] Common scripts for Contacts. \ No newline at end of file diff --git a/erpnext/setup/doctype/contact_control/__init__.py b/erpnext/setup/doctype/contact_control/__init__.py deleted file mode 100644 index baffc488252..00000000000 --- a/erpnext/setup/doctype/contact_control/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/erpnext/setup/doctype/contact_control/contact_control.js b/erpnext/setup/doctype/contact_control/contact_control.js deleted file mode 100755 index 0ca59fc4499..00000000000 --- a/erpnext/setup/doctype/contact_control/contact_control.js +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -if(cur_frm.fields_dict['territory']) { - cur_frm.fields_dict['territory'].get_query = function(doc, dt, dn) { - return { - filters: { - 'is_group': "No" - } - } - } -} - -cur_frm.cscript.render_contact_row = function(wrapper, data) { - // prepare data - data.fullname = (data.first_name || '') - + (data.last_name ? ' ' + data.last_name : ''); - data.primary = data.is_primary_contact ? ' [Primary]' : ''; - - // prepare description - var description = []; - $.each([ - ['phone', 'Tel'], - ['mobile_no', 'Mobile'], - ['email_id', 'Email'], - ['department', 'Department'], - ['designation', 'Designation']], - function(i, v) { - if(v[0] && data[v[0]]) { - description.push(repl('" + data.address + "
"; - - // prepare description - var description = []; - $.each([ - ['address', 'Address'], - ['phone', 'Tel'], - ['fax', 'Fax'], - ['email_id', 'Email']], - function(i, v) { - if(data[v[0]]) { - description.push(repl('%(description)s
\ - \ -