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

32 lines
1.0 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
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
def execute():
2017-01-19 08:57:02 +00:00
frappe.reload_doc('core', 'doctype', 'dynamic_link')
frappe.reload_doc('contacts', 'doctype', 'contact')
frappe.reload_doc('contacts', 'doctype', 'address')
map_fields = (
('Customer', 'customer'),
('Supplier', 'supplier'),
2017-03-30 16:20:21 +00:00
('Lead', 'lead'),
('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)
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