Include the parent record in the "Linked With" dialog
This commit is contained in:
parent
e222b2acc0
commit
ea2d213fff
2 changed files with 26 additions and 11 deletions
|
|
@ -116,22 +116,29 @@ class FormMeta(Meta):
|
|||
|
||||
links = dict(links)
|
||||
|
||||
if not links:
|
||||
return {}
|
||||
|
||||
ret = {}
|
||||
|
||||
for dt in links:
|
||||
ret[dt] = { "fieldname": links[dt] }
|
||||
|
||||
for grand_parent, options in frappe.db.sql("""select parent, options from tabDocField
|
||||
where fieldtype="Table"
|
||||
and options in (select name from tabDocType
|
||||
where istable=1 and name in (%s))""" % ", ".join(["%s"] * len(links)) ,tuple(links)):
|
||||
if links:
|
||||
for grand_parent, options in frappe.db.sql("""select parent, options from tabDocField
|
||||
where fieldtype="Table"
|
||||
and options in (select name from tabDocType
|
||||
where istable=1 and name in (%s))""" % ", ".join(["%s"] * len(links)) ,tuple(links)):
|
||||
|
||||
ret[grand_parent] = {"child_doctype": options, "fieldname": links[options] }
|
||||
if options in ret:
|
||||
del ret[options]
|
||||
ret[grand_parent] = {"child_doctype": options, "fieldname": links[options] }
|
||||
if options in ret:
|
||||
del ret[options]
|
||||
|
||||
links = frappe.db.sql("""select dt from `tabCustom Field`
|
||||
where (fieldtype="Table" and options=%s)""", (self.name))
|
||||
links += frappe.db.sql("""select parent from tabDocField
|
||||
where (fieldtype="Table" and options=%s)""", (self.name))
|
||||
|
||||
for dt, in links:
|
||||
if not dt in ret:
|
||||
ret[dt] = {"get_parent": True}
|
||||
|
||||
self.set("__linked_with", ret)
|
||||
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ def get_linked_docs(doctype, name, metadata_loaded=None, no_metadata=False):
|
|||
if not linkinfo:
|
||||
return results
|
||||
|
||||
me = frappe.db.get_value(doctype, name, ["parenttype", "parent"], as_dict=True)
|
||||
for dt, link in linkinfo.items():
|
||||
link["doctype"] = dt
|
||||
link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
|
||||
|
|
@ -123,7 +124,14 @@ def get_linked_docs(doctype, name, metadata_loaded=None, no_metadata=False):
|
|||
fields = ["`tab{dt}`.`{fn}`".format(dt=dt, fn=sf.strip()) for sf in fields if sf]
|
||||
|
||||
try:
|
||||
if link.get("child_doctype"):
|
||||
if link.get("get_parent"):
|
||||
if me and me.parent and me.parenttype == dt:
|
||||
ret = frappe.get_list(doctype=dt, fields=fields,
|
||||
filters=[[dt, "name", '=', me.parent]])
|
||||
else:
|
||||
ret = None
|
||||
|
||||
elif link.get("child_doctype"):
|
||||
ret = frappe.get_list(doctype=dt, fields=fields,
|
||||
filters=[[link.get('child_doctype'), link.get("fieldname"), '=', name]])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue