Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | 5eeef7f | 2014-11-24 14:16:51 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import frappe |
| 6 | |
| 7 | def load_address_and_contact(doc, key): |
| 8 | """Loads address list and contact list in `__onload`""" |
| 9 | from erpnext.utilities.doctype.address.address import get_address_display |
| 10 | |
| 11 | doc.get("__onload").addr_list = [a.update({"display": get_address_display(a)}) \ |
| 12 | for a in frappe.get_all("Address", |
| 13 | fields="*", filters={key: doc.name}, |
| 14 | order_by="is_primary_address desc, modified desc")] |
| 15 | |
| 16 | if doc.doctype != "Lead": |
| 17 | doc.get("__onload").contact_list = frappe.get_all("Contact", |
| 18 | fields="*", filters={key: doc.name}, |
| 19 | order_by="is_primary_contact desc, modified desc") |