fix(data-import): Name field in export
Force name field to be exported while updating records, optional while inserting
This commit is contained in:
parent
08e18c649e
commit
5c153e88e8
2 changed files with 24 additions and 24 deletions
|
|
@ -79,29 +79,14 @@ class Exporter:
|
|||
return children_fields
|
||||
|
||||
def get_exportable_fields(self, doctype):
|
||||
fields = []
|
||||
|
||||
def is_exportable(df):
|
||||
return (
|
||||
df.fieldtype not in display_fieldtypes
|
||||
and df.fieldtype not in no_value_fields
|
||||
)
|
||||
|
||||
meta = frappe.get_meta(doctype)
|
||||
|
||||
# filter out layout fields
|
||||
fields = [df for df in meta.fields if is_exportable(df)]
|
||||
|
||||
if self.export_fields == "Mandatory":
|
||||
fields = [df for df in fields if df.reqd]
|
||||
|
||||
if self.export_fields == "All":
|
||||
fields = list(fields)
|
||||
|
||||
elif isinstance(self.export_fields, dict):
|
||||
whitelist = self.export_fields.get(doctype, [])
|
||||
fields = [df for df in fields if df.fieldname in whitelist]
|
||||
def is_exportable(df):
|
||||
return df and df.fieldtype not in (display_fieldtypes + no_value_fields)
|
||||
|
||||
# filter out invalid fieldtypes
|
||||
all_fields = [df for df in meta.fields if is_exportable(df)]
|
||||
# add name field
|
||||
name_field = frappe._dict(
|
||||
{
|
||||
"fieldtype": "Data",
|
||||
|
|
@ -112,10 +97,20 @@ class Exporter:
|
|||
}
|
||||
)
|
||||
|
||||
if fields:
|
||||
return [name_field] + fields
|
||||
else:
|
||||
return []
|
||||
if self.export_fields == "Mandatory":
|
||||
fields = [df for df in all_fields if df.reqd]
|
||||
|
||||
if self.export_fields == "All":
|
||||
fields = list(all_fields)
|
||||
|
||||
elif isinstance(self.export_fields, dict):
|
||||
fields_to_export = self.export_fields.get(doctype, [])
|
||||
fields = [meta.get_field(fieldname) for fieldname in fields_to_export]
|
||||
fields = [df for df in fields if is_exportable(df)]
|
||||
if 'name' in fields_to_export:
|
||||
fields = [name_field] + fields
|
||||
|
||||
return fields or []
|
||||
|
||||
def get_data_to_export(self):
|
||||
frappe.permissions.can_export(self.doctype, raise_exception=True)
|
||||
|
|
|
|||
|
|
@ -158,6 +158,11 @@ frappe.ui.form.on('Data Import Beta', {
|
|||
} else {
|
||||
frm.data_exporter.dialog.set_value('export_records', 'all');
|
||||
}
|
||||
// Force ID field to be exported when updating existing records
|
||||
let id_field = frm.data_exporter.dialog.get_field(frm.doc.reference_doctype).options[0];
|
||||
if (id_field.value === 'name' && id_field.$checkbox) {
|
||||
id_field.$checkbox.find('input').prop('disabled', frm.doc.import_type === 'Update Existing Records');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue