Merge pull request #15757 from nextchamp-saqib/fix-form-tour
This commit is contained in:
commit
4fa20f862a
5 changed files with 79 additions and 148 deletions
|
|
@ -15,12 +15,12 @@ frappe.ui.form.on('Form Tour', {
|
|||
|
||||
frm.add_custom_button(__('Show Tour'), async () => {
|
||||
const issingle = await check_if_single(frm.doc.reference_doctype);
|
||||
const name = await get_first_document(frm.doc.reference_doctype);
|
||||
let route_changed = null;
|
||||
|
||||
|
||||
if (issingle) {
|
||||
route_changed = frappe.set_route('Form', frm.doc.reference_doctype);
|
||||
} else if (frm.doc.first_document) {
|
||||
const name = await get_first_document(frm.doc.reference_doctype);
|
||||
route_changed = frappe.set_route('Form', frm.doc.reference_doctype, name);
|
||||
} else {
|
||||
route_changed = frappe.set_route('Form', frm.doc.reference_doctype, 'new');
|
||||
|
|
@ -53,73 +53,69 @@ frappe.ui.form.on('Form Tour', {
|
|||
};
|
||||
});
|
||||
|
||||
frm.set_query("field", "steps", function() {
|
||||
return {
|
||||
query: "frappe.desk.doctype.form_tour.form_tour.get_docfield_list",
|
||||
filters: {
|
||||
doctype: frm.doc.reference_doctype,
|
||||
hidden: 0
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("parent_field", "steps", function() {
|
||||
return {
|
||||
query: "frappe.desk.doctype.form_tour.form_tour.get_docfield_list",
|
||||
filters: {
|
||||
doctype: frm.doc.reference_doctype,
|
||||
fieldtype: "Table",
|
||||
hidden: 0,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.trigger('reference_doctype');
|
||||
},
|
||||
|
||||
reference_doctype(frm) {
|
||||
if (!frm.doc.reference_doctype) return;
|
||||
|
||||
frappe.db.get_list('DocField', {
|
||||
filters: {
|
||||
parent: frm.doc.reference_doctype,
|
||||
parenttype: 'DocType',
|
||||
fieldtype: 'Table'
|
||||
},
|
||||
fields: ['options']
|
||||
}).then(res => {
|
||||
if (Array.isArray(res)) {
|
||||
frm.child_doctypes = res.map(r => r.options);
|
||||
}
|
||||
frm.set_fields_as_options(
|
||||
"fieldname",
|
||||
frm.doc.reference_doctype,
|
||||
df => !df.hidden
|
||||
).then(options => {
|
||||
frm.fields_dict.steps.grid.update_docfield_property(
|
||||
"fieldname",
|
||||
"options",
|
||||
[""].concat(options)
|
||||
);
|
||||
});
|
||||
|
||||
frm.set_fields_as_options(
|
||||
'parent_fieldname',
|
||||
frm.doc.reference_doctype,
|
||||
(df) => df.fieldtype == "Table" && !df.hidden,
|
||||
).then(options => {
|
||||
frm.fields_dict.steps.grid.update_docfield_property(
|
||||
"parent_fieldname",
|
||||
"options",
|
||||
[""].concat(options)
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Form Tour Step', {
|
||||
parent_field(frm, cdt, cdn) {
|
||||
form_render(frm, cdt, cdn) {
|
||||
if (locals[cdt][cdn].is_table_field) {
|
||||
frm.trigger('parent_fieldname', cdt, cdn);
|
||||
}
|
||||
},
|
||||
parent_fieldname(frm, cdt, cdn) {
|
||||
const child_row = locals[cdt][cdn];
|
||||
frappe.model.set_value(cdt, cdn, 'field', '');
|
||||
const field_control = get_child_field("steps", cdn, "field");
|
||||
field_control.get_query = function() {
|
||||
return {
|
||||
query: "frappe.desk.doctype.form_tour.form_tour.get_docfield_list",
|
||||
filters: {
|
||||
doctype: child_row.child_doctype,
|
||||
hidden: 0
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const parent_fieldname_df = frappe
|
||||
.get_meta(frm.doc.reference_doctype)
|
||||
.fields.find(df => df.fieldname == child_row.parent_fieldname);
|
||||
|
||||
frm.set_fields_as_options(
|
||||
'fieldname',
|
||||
parent_fieldname_df.options,
|
||||
(df) => !df.hidden,
|
||||
).then(options => {
|
||||
frm.fields_dict.steps.grid.update_docfield_property(
|
||||
"fieldname",
|
||||
"options",
|
||||
[""].concat(options)
|
||||
);
|
||||
if (child_row.fieldname) {
|
||||
frappe.model.set_value(cdt, cdn, 'fieldname', child_row.fieldname);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function get_child_field(child_table, child_name, fieldname) {
|
||||
// gets the field from grid row form
|
||||
const grid = cur_frm.fields_dict[child_table].grid;
|
||||
const grid_row = grid.grid_rows_by_docname[child_name];
|
||||
return grid_row.grid_form.fields_dict[fieldname];
|
||||
}
|
||||
|
||||
async function check_if_single(doctype) {
|
||||
const { message } = await frappe.db.get_value('DocType', doctype, 'issingle');
|
||||
return message.issingle || 0;
|
||||
|
|
|
|||
|
|
@ -5,58 +5,23 @@ import frappe
|
|||
from frappe.model.document import Document
|
||||
from frappe.modules.export_file import export_to_files
|
||||
|
||||
|
||||
class FormTour(Document):
|
||||
def before_insert(self):
|
||||
if not self.is_standard:
|
||||
return
|
||||
def before_save(self):
|
||||
meta = frappe.get_meta(self.reference_doctype)
|
||||
for step in self.steps:
|
||||
if step.is_table_field and step.parent_fieldname:
|
||||
parent_field_df = meta.get_field(step.parent_fieldname)
|
||||
step.child_doctype = parent_field_df.options
|
||||
|
||||
# while syncing, set proper docfield reference
|
||||
for d in self.steps:
|
||||
if not frappe.db.exists('DocField', d.field):
|
||||
d.field = frappe.db.get_value('DocField', {
|
||||
'fieldname': d.fieldname, 'parent': self.reference_doctype, 'fieldtype': d.fieldtype
|
||||
}, "name")
|
||||
|
||||
if d.is_table_field and not frappe.db.exists('DocField', d.parent_field):
|
||||
d.parent_field = frappe.db.get_value('DocField', {
|
||||
'fieldname': d.parent_fieldname, 'parent': self.reference_doctype, 'fieldtype': 'Table'
|
||||
}, "name")
|
||||
field_df = frappe.get_meta(step.child_doctype).get_field(step.fieldname)
|
||||
step.label = field_df.label
|
||||
step.fieldtype = field_df.fieldtype
|
||||
else:
|
||||
field_df = meta.get_field(step.fieldname)
|
||||
step.label = field_df.label
|
||||
step.fieldtype = field_df.fieldtype
|
||||
|
||||
def on_update(self):
|
||||
if frappe.conf.developer_mode and self.is_standard:
|
||||
export_to_files([['Form Tour', self.name]], self.module)
|
||||
|
||||
def before_export(self, doc):
|
||||
for d in doc.steps:
|
||||
d.field = ""
|
||||
d.parent_field = ""
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_docfield_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
or_filters = [
|
||||
['fieldname', 'like', '%' + txt + '%'],
|
||||
['label', 'like', '%' + txt + '%'],
|
||||
['fieldtype', 'like', '%' + txt + '%']
|
||||
]
|
||||
|
||||
parent_doctype = filters.get('doctype')
|
||||
fieldtype = filters.get('fieldtype')
|
||||
if not fieldtype:
|
||||
excluded_fieldtypes = ['Column Break']
|
||||
excluded_fieldtypes += filters.get('excluded_fieldtypes', [])
|
||||
fieldtype_filter = ['not in', excluded_fieldtypes]
|
||||
else:
|
||||
fieldtype_filter = fieldtype
|
||||
|
||||
docfields = frappe.get_all(
|
||||
doctype,
|
||||
fields=["name as value", "label", "fieldtype"],
|
||||
filters={'parent': parent_doctype, 'fieldtype': fieldtype_filter},
|
||||
or_filters=or_filters,
|
||||
limit_start=start,
|
||||
limit_page_length=page_len,
|
||||
order_by="idx",
|
||||
as_list=1,
|
||||
)
|
||||
return docfields
|
||||
export_to_files([["Form Tour", self.name]], self.module)
|
||||
|
|
|
|||
|
|
@ -6,19 +6,17 @@
|
|||
"field_order": [
|
||||
"is_table_field",
|
||||
"section_break_2",
|
||||
"parent_field",
|
||||
"field",
|
||||
"parent_fieldname",
|
||||
"fieldname",
|
||||
"title",
|
||||
"description",
|
||||
"column_break_2",
|
||||
"position",
|
||||
"label",
|
||||
"fieldtype",
|
||||
"has_next_condition",
|
||||
"next_step_condition",
|
||||
"section_break_13",
|
||||
"fieldname",
|
||||
"parent_fieldname",
|
||||
"fieldtype",
|
||||
"child_doctype"
|
||||
],
|
||||
"fields": [
|
||||
|
|
@ -38,23 +36,13 @@
|
|||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: (!doc.is_table_field || (doc.is_table_field && doc.parent_field))",
|
||||
"fieldname": "field",
|
||||
"fieldtype": "Link",
|
||||
"label": "Field",
|
||||
"options": "DocField",
|
||||
"depends_on": "eval: (!doc.is_table_field || (doc.is_table_field && doc.parent_fieldname))",
|
||||
"fieldname": "fieldname",
|
||||
"fieldtype": "Select",
|
||||
"label": "Fieldname",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "field.fieldname",
|
||||
"fieldname": "fieldname",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Fieldname",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "field.label",
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
|
|
@ -88,10 +76,8 @@
|
|||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fetch_from": "field.fieldtype",
|
||||
"fieldname": "fieldtype",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Fieldtype",
|
||||
"read_only": 1
|
||||
},
|
||||
|
|
@ -105,14 +91,6 @@
|
|||
"fieldname": "section_break_2",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "is_table_field",
|
||||
"fieldname": "parent_field",
|
||||
"fieldtype": "Link",
|
||||
"label": "Parent Field",
|
||||
"mandatory_depends_on": "is_table_field",
|
||||
"options": "DocField"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_13",
|
||||
"fieldtype": "Section Break",
|
||||
|
|
@ -120,7 +98,6 @@
|
|||
"label": "Hidden Fields"
|
||||
},
|
||||
{
|
||||
"fetch_from": "parent_field.options",
|
||||
"fieldname": "child_doctype",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
|
|
@ -128,18 +105,17 @@
|
|||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "parent_field.fieldname",
|
||||
"depends_on": "is_table_field",
|
||||
"fieldname": "parent_fieldname",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Parent Fieldname",
|
||||
"read_only": 1
|
||||
"fieldtype": "Select",
|
||||
"label": "Parent Field",
|
||||
"mandatory_depends_on": "is_table_field"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-06 20:52:21.076972",
|
||||
"modified": "2022-01-27 15:18:36.481801",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "Form Tour Step",
|
||||
|
|
@ -147,5 +123,6 @@
|
|||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ frappe.ui.form.FormTour = class FormTour {
|
|||
|
||||
const curr_step = step_info;
|
||||
const next_step = this.tour.steps[curr_step.idx];
|
||||
const is_next_field_in_curr_table = next_step.parent_field == curr_step.field;
|
||||
const is_next_field_in_curr_table = next_step.parent_fieldname == curr_step.fieldname;
|
||||
|
||||
if (!is_next_field_in_curr_table) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -148,9 +148,6 @@ def create_form_tour():
|
|||
if frappe.db.exists('Form Tour', {'name': 'Test Form Tour'}):
|
||||
return
|
||||
|
||||
def get_docfield_name(filters):
|
||||
return frappe.db.get_value('DocField', filters, "name")
|
||||
|
||||
tour = frappe.get_doc({
|
||||
'doctype': 'Form Tour',
|
||||
'title': 'Test Form Tour',
|
||||
|
|
@ -161,7 +158,6 @@ def create_form_tour():
|
|||
"description": "Test Description 1",
|
||||
"has_next_condition": 1,
|
||||
"next_step_condition": "eval: doc.first_name",
|
||||
"field": get_docfield_name({'parent': 'Contact', 'fieldname': 'first_name'}),
|
||||
"fieldname": "first_name",
|
||||
"fieldtype": "Data"
|
||||
},{
|
||||
|
|
@ -169,21 +165,18 @@ def create_form_tour():
|
|||
"description": "Test Description 2",
|
||||
"has_next_condition": 1,
|
||||
"next_step_condition": "eval: doc.last_name",
|
||||
"field": get_docfield_name({'parent': 'Contact', 'fieldname': 'last_name'}),
|
||||
"fieldname": "last_name",
|
||||
"fieldtype": "Data"
|
||||
},{
|
||||
"title": "Test Title 3",
|
||||
"description": "Test Description 3",
|
||||
"field": get_docfield_name({'parent': 'Contact', 'fieldname': 'phone_nos'}),
|
||||
"fieldname": "phone_nos",
|
||||
"fieldtype": "Table"
|
||||
},{
|
||||
"title": "Test Title 4",
|
||||
"description": "Test Description 4",
|
||||
"is_table_field": 1,
|
||||
"parent_field": get_docfield_name({'parent': 'Contact', 'fieldname': 'phone_nos'}),
|
||||
"field": get_docfield_name({'parent': 'Contact Phone', 'fieldname': 'phone'}),
|
||||
"parent_fieldname": "phone_nos",
|
||||
"next_step_condition": "eval: doc.phone",
|
||||
"has_next_condition": 1,
|
||||
"fieldname": "phone",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue