Update territory and customer_group patch optimization (#5073)
This commit is contained in:
parent
22534536ce
commit
b5ecdf22fd
1 changed files with 13 additions and 11 deletions
|
|
@ -393,12 +393,13 @@ def bulk_rename(doctype, rows=None, via_console = False):
|
|||
if not via_console:
|
||||
return rename_log
|
||||
|
||||
def update_linked_doctypes(linked_doctype_info_list, docname, value):
|
||||
def update_linked_doctypes(doctype, docname, linked_to, value, ignore_doctypes=None):
|
||||
"""
|
||||
linked_doctype_info_list = list formed by get_fetch_fields() function
|
||||
docname = Master DocType's name in which modification are made
|
||||
value = Value for the field thats set in other DocType's by fetching from Master DocType
|
||||
"""
|
||||
linked_doctype_info_list = get_fetch_fields(doctype, linked_to, ignore_doctypes)
|
||||
|
||||
for d in linked_doctype_info_list:
|
||||
frappe.db.sql("""
|
||||
|
|
@ -417,34 +418,35 @@ def update_linked_doctypes(linked_doctype_info_list, docname, value):
|
|||
docname = docname
|
||||
))
|
||||
|
||||
def get_fetch_fields(master, linked_to):
|
||||
def get_fetch_fields(doctype, linked_to, ignore_doctypes=None):
|
||||
"""
|
||||
master = Master DocType in which the changes are being made
|
||||
doctype = Master DocType in which the changes are being made
|
||||
linked_to = DocType name of the field thats being updated in Master
|
||||
|
||||
This function fetches list of all DocType where both master and linked_to is found
|
||||
This function fetches list of all DocType where both doctype and linked_to is found
|
||||
as link fields.
|
||||
Forms a list of dict in the form -
|
||||
[{doctype: , parent_fieldname: , child_fieldname: ]
|
||||
[{doctype: , master_fieldname: , linked_to_fieldname: ]
|
||||
where
|
||||
doctype = DocType where changes need to be made
|
||||
parent_fieldname = Fieldname where options = parent
|
||||
child_fieldname = Fieldname where options = child
|
||||
master_fieldname = Fieldname where options = doctype
|
||||
linked_to_fieldname = Fieldname where options = linked_to
|
||||
"""
|
||||
|
||||
master_list = get_link_fields(master)
|
||||
master_list = get_link_fields(doctype)
|
||||
linked_to_list = get_link_fields(linked_to)
|
||||
out, linked_doctype_info = [], {}
|
||||
out = []
|
||||
|
||||
from itertools import product
|
||||
product_list = product(master_list, linked_to_list)
|
||||
|
||||
for d in product_list:
|
||||
if d[0]['parent'] == d[1]['parent']:
|
||||
linked_doctype_info = frappe._dict()
|
||||
if d[0]['parent'] == d[1]['parent'] \
|
||||
and (not ignore_doctypes or d[0]['parent'] not in ignore_doctypes):
|
||||
linked_doctype_info['doctype'] = d[0]['parent']
|
||||
linked_doctype_info['master_fieldname'] = d[0]['fieldname']
|
||||
linked_doctype_info['linked_to_fieldname'] = d[1]['fieldname']
|
||||
out.append(linked_doctype_info)
|
||||
linked_doctype_info = {}
|
||||
|
||||
return out
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue