brotherton-erpnext/erpnext/patches/v7_2/contact_address_links.py

28 lines
851 B
Python
Raw Normal View History

import frappe
2017-01-19 08:57:02 +00:00
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
def execute():
2017-01-19 08:57:02 +00:00
frappe.reload_doc('core', 'doctype', 'dynamic_link')
frappe.reload_doc('email', 'doctype', 'contact')
frappe.reload_doc('geo', 'doctype', 'address')
map_fields = (
('Customer', 'customer'),
('Supplier', 'supplier'),
('Load', 'lead'),
('Sales Partner', 'sales_partner')
)
for doctype in ('Contact', 'Address'):
if frappe.db.has_column(doctype, 'customer'):
for doc in frappe.get_all(doctype, fields='*'):
doc.doctype = doctype
doc = frappe.get_doc(doc)
dirty = False
for field in map_fields:
if doc.get(field[1]):
doc.append('links', dict(link_doctype=field[0], link_name=doc.get(field[1])))
dirty = True
if dirty:
2017-01-19 08:57:02 +00:00
deduplicate_dynamic_links(doc)
doc.update_children()