import frappe
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links

def execute():
	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:
						deduplicate_dynamic_links(doc)
						doc.update_children()

@@ -90,16 +90,61 @@
 ic_links
+%0Afrom frappe.utils import update_progress_bar
 %0A%0Adef ex
@@ -531,18 +531,15 @@
 %0A%09%09%09
-for doc in
+items =
  fra
@@ -561,48 +561,44 @@
 type
-, fields='*'):%0A%09%09%09%09doc.doctype = doctype
+)%0A%09%09%09for i, doc in enumerate(items):
 %0A%09%09%09
@@ -618,24 +618,38 @@
 .get_doc(doc
+type, doc.name
 )%0A%09%09%09%09dirty 
@@ -896,8 +896,89 @@
 ldren()%0A
+%0A%09%09%09%09%09update_progress_bar('Updating %7B0%7D'.format(doctype), i, len(items))%0A%09%09%09print

add progress bar in patch