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-19 09:02:36 +00:00
|
|
|
from frappe.utils import update_progress_bar
|
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'),
|
2017-03-30 16:20:21 +00:00
|
|
|
('Lead', 'lead'),
|
2017-01-13 13:23:11 +00:00
|
|
|
('Sales Partner', 'sales_partner')
|
|
|
|
)
|
|
|
|
for doctype in ('Contact', 'Address'):
|
|
|
|
if frappe.db.has_column(doctype, 'customer'):
|
2017-01-19 09:02:36 +00:00
|
|
|
items = frappe.get_all(doctype)
|
|
|
|
for i, doc in enumerate(items):
|
|
|
|
doc = frappe.get_doc(doctype, doc.name)
|
2017-01-13 13:23:11 +00:00
|
|
|
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()
|
2017-01-19 09:02:36 +00:00
|
|
|
|
|
|
|
update_progress_bar('Updating {0}'.format(doctype), i, len(items))
|
|
|
|
print
|