[fix] get linked doc only if add fetch option is found
This commit is contained in:
parent
029ad4b7dd
commit
1ff7dff91b
2 changed files with 11 additions and 5 deletions
|
|
@ -43,7 +43,7 @@ def get_mapped_doc(from_doctype, from_docname, table_maps, target_doc=None,
|
|||
table_map = {
|
||||
"doctype": target_child_doctype
|
||||
}
|
||||
|
||||
|
||||
if table_map:
|
||||
for source_d in source_doc.get(df.fieldname):
|
||||
if "condition" in table_map:
|
||||
|
|
@ -133,10 +133,7 @@ def map_fields(source_doc, target_doc, table_map, source_parent):
|
|||
map_fetch_fields(target_doc, df, no_copy_fields)
|
||||
|
||||
def map_fetch_fields(target_doc, df, no_copy_fields):
|
||||
try:
|
||||
linked_doc = frappe.get_doc(df.options, target_doc.get(df.fieldname))
|
||||
except:
|
||||
return
|
||||
linked_doc = None
|
||||
|
||||
# options should be like "link_fieldname.fieldname_in_liked_doc"
|
||||
for fetch_df in target_doc.meta.get("fields", {"options": "^{0}.".format(df.fieldname)}):
|
||||
|
|
@ -145,6 +142,13 @@ def map_fetch_fields(target_doc, df, no_copy_fields):
|
|||
|
||||
if not target_doc.get(fetch_df.fieldname) and fetch_df.fieldname not in no_copy_fields:
|
||||
source_fieldname = fetch_df.options.split(".")[1]
|
||||
|
||||
if not linked_doc:
|
||||
try:
|
||||
linked_doc = frappe.get_doc(df.options, target_doc.get(df.fieldname))
|
||||
except:
|
||||
return
|
||||
|
||||
val = linked_doc.get(source_fieldname)
|
||||
|
||||
if val not in (None, ""):
|
||||
|
|
@ -156,6 +160,7 @@ def map_child_doc(source_d, target_parent, table_map, source_parent=None):
|
|||
target_d = frappe.new_doc(target_child_doctype, target_parent, target_parentfield)
|
||||
|
||||
map_doc(source_d, target_d, table_map, source_parent)
|
||||
|
||||
target_d.idx = None
|
||||
target_parent.append(target_parentfield, target_d)
|
||||
return target_d
|
||||
|
|
|
|||
|
|
@ -221,6 +221,7 @@ $.extend(frappe.model, {
|
|||
args: {
|
||||
"source_name": opts.source_name
|
||||
},
|
||||
freeze: true,
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
var doc = frappe.model.sync(r.message);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue