2017-01-13 13:23:11 +00:00
|
|
|
import frappe
|
2017-01-19 08:57:02 +00:00
|
|
|
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
|
2017-01-13 13:23:11 +00:00
|
|
|
|
|
|
|
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')
|
2017-01-13 13:23:11 +00:00
|
|
|
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()
|