From 5eeef7f065ed1b75152ed2f81393937a9612addc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 24 Nov 2014 14:16:51 +0530 Subject: [PATCH] [refactor] address and contact list in customer, supplier, lead, sales person --- erpnext/public/js/templates/address_list.html | 20 +++++++++++++++++++ erpnext/public/js/templates/contact_list.html | 18 +++++++++++++++++ erpnext/utilities/address_and_contact.py | 19 ++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 erpnext/public/js/templates/address_list.html create mode 100644 erpnext/public/js/templates/contact_list.html create mode 100644 erpnext/utilities/address_and_contact.py diff --git a/erpnext/public/js/templates/address_list.html b/erpnext/public/js/templates/address_list.html new file mode 100644 index 0000000000..e85723fe89 --- /dev/null +++ b/erpnext/public/js/templates/address_list.html @@ -0,0 +1,20 @@ +

+{% for(var i=0, l=addr_list.length; i + + {%= __("Edit") %} +

{%= i+1 %}. {%= addr_list[i].address_type %}

+
+
+ {% if(addr_list[i].is_primary_address) { %} + {%= __("Primary") %}{% } %} + {% if(addr_list[i].is_shipping_address) { %} + {%= __("Shipping") %}{% } %} +
+

{%= addr_list[i].display %}

+
+{% } %} +{% if(!addr_list.length) { %} +

{%= __("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 0000000000..ac192eaa0a --- /dev/null +++ b/erpnext/public/js/templates/contact_list.html @@ -0,0 +1,18 @@ +

+{% for(var i=0, l=contact_list.length; i + + {%= __("Edit") %} +

{%= i+1 %}. {%= contact_list[i].first_name %} {%= contact_list[i].last_name %}

+
+
+ {% if(contact_list[i].is_primary_contact) { %} + {%= __("Primary") %}{% } %} +
+

{%= __("Phone") %}: {%= contact_list[i].phone %}

+
+{% } %} +{% if(!contact_list.length) { %} +

{%= __("No contacts added yet.") %}

+{% } %} diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py new file mode 100644 index 0000000000..382c98c3e6 --- /dev/null +++ b/erpnext/utilities/address_and_contact.py @@ -0,0 +1,19 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def load_address_and_contact(doc, key): + """Loads address list and contact list in `__onload`""" + from erpnext.utilities.doctype.address.address import get_address_display + + doc.get("__onload").addr_list = [a.update({"display": get_address_display(a)}) \ + for a in frappe.get_all("Address", + fields="*", filters={key: doc.name}, + order_by="is_primary_address desc, modified desc")] + + if doc.doctype != "Lead": + doc.get("__onload").contact_list = frappe.get_all("Contact", + fields="*", filters={key: doc.name}, + order_by="is_primary_contact desc, modified desc")