diff --git a/smart_service/apis/app_user_login.py b/smart_service/apis/app_user_login.py index 637e2b9..422e80c 100644 --- a/smart_service/apis/app_user_login.py +++ b/smart_service/apis/app_user_login.py @@ -352,4 +352,14 @@ def login_generate_token(doc=None,method=None): water.apple = new_tok water.save() return water.apple - \ No newline at end of file + +@frappe.whitelist(allow_guest=True) +def temporary_login(): + user_details={} + docu = frappe.get_doc("Fish", None) + token = docu.apple + user_details['token'] = token + user_details['Installation ID'] = "AppDev-0142" + user_details['User ID'] = "U-00006" + user_details['Code'] = "SJ010081" + return user_details \ No newline at end of file diff --git a/smart_service/apis/update_validation.py b/smart_service/apis/update_validation.py index 724920b..a2ac04b 100644 --- a/smart_service/apis/update_validation.py +++ b/smart_service/apis/update_validation.py @@ -249,7 +249,14 @@ def check_vehicle_update(vehicle_list): final.append(variant_out) res = {'Name': '%s-%s_%s' % (iid, vehicle, l_id), 'Language': l_id, 'IsUpdateAvailable': 'true', 'CurrentVersion': float(current_version), 'Version': float(update_version)} + try: + if not os.path.exists(base_url+"/files/json_files"): + os.makedirs(base_url+"/files/json_files") + + if not os.path.exists(base_url+"/files/json_files/temp"): + os.makedirs(base_url+"/files/json_files/temp") + file_name = "/files/json_files/temp/%s-%s_%s.json" % (iid, vehicle, l_id) dicfinal = {'JSON': final} @@ -305,4 +312,12 @@ def delete_complete(doc=None,method=None): - \ No newline at end of file +@frappe.whitelist() +def file_details(): + lst=[] + with os.scandir() as dir_entries: + for entry in dir_entries: + info = entry.stat() + lst.append(info) + + return lst \ No newline at end of file diff --git a/smart_service/fixtures/client_script.json b/smart_service/fixtures/client_script.json index cea090c..dcaed40 100644 --- a/smart_service/fixtures/client_script.json +++ b/smart_service/fixtures/client_script.json @@ -17,12 +17,12 @@ "doctype": "Client Script", "dt": "Procedure", "enabled": 1, - "modified": "2022-03-04 16:44:26.162097", + "modified": "2022-03-29 16:14:33.283915", "name": "Procedure-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "var trigger = true;\n\ncur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.variant\",};\n};\ncur_frm.fields_dict['sub_systems'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.sub_systems\",};\n};\n\nfrappe.ui.form.on('Procedure', {\n onload: function (frm) {\n if (frm.doc.workflow_state == 'Publish Ready'){\n frm.set_read_only();\n }\n var html = \"\";\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"
HTML Tag\" + \"How to tag <...>\" + \"Result
Bold\" + \"<b>Using a 10 mm socket.</b>\" + \"Using a 10 mm socket.
Break\" + \"Using a <br>10 mm socket.\" + \"Using a
10 mm socket.
Italic\" + \"<i>Using a 10 mm socket.</i>\" + \"Using a 10 mm socket.
Unordered List\" + \"<ul><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ul>\" + \"
  • Using a 10 mm socket.
  • the steering fluid line.
Ordered List\" + \"<ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol>\" + \"
  1. Using a 10 mm socket.
  2. the steering fluid line.
\";\n $(frm.fields_dict.html_reference.wrapper).html(html);\n },\n procedure_details_on_form_rendered: function(frm,cdt,cdn){\n\t\tcur_frm.cscript.highlight_row(frm.open_grid_row());\n\t\t\n\t},\n validate: function(frm){\n frm.doc.procedure_filter = \"All\";\n if(frm.doc.procedure_filter == \"All\"){\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n }\n\n frm.refresh();\n },\n refresh: function (frm) {\n select_row(frm);\n if(frm.doc.procedure_filter == \"All\"){\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n }\n var previous_procedure_name = \"\";\n var previous_step_name = \"\";\n $(\"select[data-fieldname='procedure_filter']\").empty();\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(\"All\", \"All\"));\n $(\"select[data-fieldname='step_filter']\").empty();\n $(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n cur_frm.doc.procedure_filter = \"All\";\n cur_frm.doc.step_filter = \"All\";\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.step_name){\n fn_addSteptolist(row.doc.step_name);\n }\n\n if (row.doc.procedure_name){\n fn_addProceduretolist(row.doc.procedure_name);\n }\n \n if (row.doc.procedure_name == previous_procedure_name){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"procedure_name\"]').find('a[data-doctype=\"Procedure Name\"]').css({'color': '#EDEDED'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#FFFFFF'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #ebeef0'});\n }else{\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"procedure_name\"]').find('a[data-doctype=\"Procedure Name\"]').css({'color': '#000000'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#EDEDED'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #7b7c7c'});\n }\n previous_procedure_name = row.doc.procedure_name;\n \n \n if (row.doc.step_name == previous_step_name){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"step_name\"]').find('a[data-doctype=\"Procedure Step Name\"]').css({'color': '#DFDFDF'});\n }else{\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"step_name\"]').find('a[data-doctype=\"Procedure Step Name\"]').css({'color': '#000000'});\n }\n previous_step_name = row.doc.step_name;\n let id = row.doc.idx;\n\n });\n\n if (frm.doc.workflow_state == \"Publish Ready\" && frappe.user_roles.indexOf(\"_Admin\") > 0){\n frm.add_custom_button(__('Revoke Publish'), function(){\n //get all system mapping with the procedure linked\n frappe.db.get_list('System Mapping_Sub System', {\n fields: ['parent', 'procedure', 'procedure_status'],\n filters: {\n procedure: frm.doc.name\n }\n }).then(records => {\n var html = \"

\";\n $.each(records, function(index, row){\n html = html + \"\" +\"\";\n });\n html = html + \"
\" + row.parent + \"\" + row.procedure + \"
\";\n frappe.warn('Are you sure you want to Revoke?',\n 'Since there are System Mappings attached to it!!! ' + html,\n () => {\n frm.set_value(\"workflow_state\",\"Draft\");\n frm.save();\n // action to perform if Continue is selected\n },\n 'Continue', false // Sets dialog as minimizable\n );\n });\n });\n }\n },\n \n procedure_filter: function (frm) {\n //if (!trigger){ trigger = true; return;}\n select_row(frm);\n if (frm.doc.procedure_filter ==\"All\"){\n frm.doc.step_filter = \"All\";\n cur_frm.refresh_field('step_filter');\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name != frm.doc.procedure_filter){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n } else {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }\n });\n }\n //frm.refresh();\n \n //Filtered by as per step filter\n if(frm.doc.name && frm.is_new() == undefined){\n $(\"select[data-fieldname='step_filter']\").empty();\n\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n\t\tvar x = frappe.db.get_list('Procedure_Details', {\n\t\t\tfields: ['step_name'],\n\t\t\tfilters: {\n\t\t\t\tprocedure_name: frm.doc.procedure_filter,\n\t\t\t\tparent: frm.doc.name\n\t\t\t}\n\t\t\n\t\t}).then(steps => {\n\t\tvar child;\n\t\t\t$.each(steps, function(index, row){\n\t\t\t\tfn_steplist(row.step_name);\n\t\t\t})\n\t\t})\n }\n \n $(\"select[data-fieldname='step_filter']\").empty();\n\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n for(var i = 0;i {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name == frm.doc.procedure_filter && row.doc.step_name == frm.doc.step_filter){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }else if(row.doc.procedure_name == frm.doc.procedure_filter && frm.doc.step_filter == \"All\"){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n \n }else {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n }\n });\n }\n },\n \n before_workflow_action: (frm) => {\n if ((frm.doc.workflow_state == 'Review Pending' || frm.doc.workflow_state == 'Publish Ready') && (frm.selected_workflow_action == 'Revoke')){\n //frappe.throw(\"Any connected Publish Planning will get affected. Please check!\");\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.procedure.procedure.get_publish_details\",\n \"args\": {\n \"procedure_name\": frm.doc.name,\n \"status\":'Published1',\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){\n \t var publish_list = r.message;\n \t if (publish_list.length){\n \t var html = \"This Procedure is linked with the following Publish Docs:
    \";\n \t publish_list.forEach((array_row) => {\n \t html = html + \"
  1. \" + array_row + \"
  2. \";\n \t });\n \t html = html + \"
\";\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'green',\n message: __(html)\n });\n \t }\n \t}\n });\n }\n },\n mat:function(frm){\n if (!frm.is_new()){\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'green',\n message: __('Updating MAT will impact its connected System Mapping and so with Kilometer Mapping. Please Check!')\n });\n }\n }\n});\n\nfrappe.ui.form.on('Procedure_Details', {\n procedure_name: function (frm,cdt,cdn) {\n var title = frm.doc.procedure_filter;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n let value = row.doc.procedure_name;\n if (value)\n if ($(\"select[data-fieldname='procedure_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(value, value));\n }\n \n });\n frm.doc.procedure_filter = title;\n // frm.refresh();\n },\n step_name: function (frm,cdt,cdn) {\n // frm.refresh();\n var filtered_step = frm.doc.step_filter;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n let value = row.doc.step_name;\n if (value && frm.doc.procedure_filter == \"All\"){\n if ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n }\n }\n if(value && frm.doc.procedure_filter == row.doc.procedure_name){\n fn_stepfilter(row.doc.step_name)\n }\n });\n frm.doc.step_filter = filtered_step;\n\n },\n content_type: function (frm,cdt,cdn) {\n var df;\n let d = locals[cdt][cdn];\n var id = d.idx;\n id = id-1;\n let row = frm.fields_dict.procedure_details.grid.grid_rows[id];\n if (d.content_type == 'Link'){\n let d = new frappe.ui.Dialog({\n title: 'Select a Procedure',\n fields:[\n {\n label: 'Procedure',\n fieldname: 'procedure_map',\n fieldtype: 'Link',\n options:'Procedure'\n }\n ],\n primary_action_label: 'Select',\n primary_action(values) {\n // row.doc.content = values.procedure_map;\n var url = window.location.host;\n var content = values.procedure_map;\n row.doc.temp_cnt = values.procedure_map;\n row.doc.content = content.link(\"http://\" + url + \"/app/procedure/\" + content);\n // row.doc.content = '' + content + '';\n d.hide();\n frm.refresh();\n }\n });\n d.show();\n } else {\n d.content = d.content1;\n }\n },\n procedure_details_move: function (frm,cdt,cdn) {\n frm.refresh();\n },\n procedure_details_remove: function(frm,cdt,cdn){\n frm.doc.procedure_filter = \"All\";\n frm.doc.step_filter = \"All\";\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name){\n fn_addProceduretolist(row.doc.procedure_name);\n }\n })\n frm.refresh_field('procedure_details');\n cur_frm.refresh_fields();\n frm.refresh();\n },\n procedure_details_add: function(frm,cdt,cdn) {\n select_row(frm);\n \tvar d = locals[cdt][cdn];\n \tvar id = d.idx;\n id = id-1;\n var row = frm.fields_dict.procedure_details.grid.grid_rows[id];\n var prevrow = frm.fields_dict.procedure_details.grid.grid_rows[id-1];\n if (frm.doc.procedure_filter == \"All\"){\n if (prevrow !== undefined) {\n row.doc.procedure_name = prevrow.doc.procedure_name;\n row.doc.step_name = prevrow.doc.step_name;\n }\n }else{\n row.doc.procedure_name = frm.doc.procedure_filter;\n // row.doc.step_name = prevrow.doc.step_name;\n }\n if (frm.doc.step_filter == \"All\" && frm.doc.procedure_filter == \"All\"){\n if (prevrow !== undefined) {\n row.doc.procedure_name = prevrow.doc.procedure_name;\n row.doc.step_name = prevrow.doc.step_name;\n }\n }\n else if(frm.doc.step_filter == \"All\" && frm.doc.procedure_filter != \"All\"){\n row.doc.procedure_name = frm.doc.procedure_filter;\n // row.doc.step_name = prevrow.doc.step_name;\n }else{\n row.doc.procedure_name = frm.doc.procedure_filter;\n row.doc.step_name = frm.doc.step_filter;\n }\n\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.step_name && row.doc.procedure_name == frm.doc.procedure_filter){\n fn_addSteptolist(row.doc.step_name);\n }\n })\n\n refresh_field(\"procedure_filter\");\n refresh_field(\"step_filter\");\n },\n});\n\nfunction fn_addProceduretolist(value){\n if (value === \"\") {return;}\n if ($(\"select[data-fieldname='procedure_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(value, value));\n }\n}\nfunction fn_addSteptolist(value){\n if (value === \"\") {return;}\n if ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n }\n}\n\nfunction fn_steplist(value){\n\tif (value === \"\") {return;}\n\t\tif ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n\t\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n\t\t}\n}\n\nfunction fn_stepfilter(value){\n\tif (value === \"\") {return;}\n\t \n\t\tif ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n\t\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n\t\t}\n}\nfunction select_row(frm){\n if(frm.doc.procedure_filter != \"All\"){\n\t$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class=\"row-index sortable-handle col col-xs-1\"]').find('input[class=\"grid-row-check pull-left\"]').css({'visibility': 'hidden'});\n\t}\n\telse{\n\t$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class=\"row-index sortable-handle col col-xs-1\"]').find('input[class=\"grid-row-check pull-left\"]').css({'visibility': 'visible'});\n\n\t}\n\n}\ncur_frm.cscript.highlight_row = function(grid_row){\n\tvar idx = grid_row.doc.idx;\n\tcur_frm.fields_dict[\"procedure_details\"].$wrapper.find('.grid-body .rows').find(\".grid-row\").each(function(i, item) {\n\tlet d = locals[cur_frm.fields_dict[\"procedure_details\"].grid.doctype][$(item).attr('data-name')];\n\tif(d[\"idx\"] === idx){\n\t\tgrid_row.toggle_editable_row(true);\n\t}\n\t});\n}\n\n", + "script": "var trigger = true;\n\ncur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.variant\",};\n};\ncur_frm.fields_dict['sub_systems'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.sub_systems\",};\n};\n\nfrappe.ui.form.on('Procedure', {\n onload: function (frm) {\n if (frm.doc.workflow_state == 'Publish Ready'){\n frm.set_read_only();\n }\n var html = \"\";\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"\" ;\n html = html + \"
HTML Tag\" + \"How to tag <...>\" + \"Result
Bold\" + \"<b>Using a 10 mm socket.</b>\" + \"Using a 10 mm socket.
Break\" + \"Using a <br>10 mm socket.\" + \"Using a
10 mm socket.
Italic\" + \"<i>Using a 10 mm socket.</i>\" + \"Using a 10 mm socket.
Unordered List\" + \"<ul><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ul>\" + \"
  • Using a 10 mm socket.
  • the steering fluid line.
Ordered List\" + \"<ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol>\" + \"
  1. Using a 10 mm socket.
  2. the steering fluid line.
\";\n $(frm.fields_dict.html_reference.wrapper).html(html);\n },\n procedure_details_on_form_rendered: function(frm,cdt,cdn){\n\t\tcur_frm.cscript.highlight_row(frm.open_grid_row());\n\t\t\n\t},\n validate: function(frm){\n var regex = /[@#$%^&*+\\=\\[\\]{};:\\\\|.\\/?]+/;\n for (var i=0;iContent: Only letters, numbers and - ,'<>_()! are allowed.\"));\n frappe.validated = false;\n } \n }\n \n frm.doc.procedure_filter = \"All\";\n if(frm.doc.procedure_filter == \"All\"){\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n }\n\n frm.refresh();\n },\n refresh: function (frm) {\n select_row(frm);\n if(frm.doc.procedure_filter == \"All\"){\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n }\n var previous_procedure_name = \"\";\n var previous_step_name = \"\";\n $(\"select[data-fieldname='procedure_filter']\").empty();\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(\"All\", \"All\"));\n $(\"select[data-fieldname='step_filter']\").empty();\n $(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n cur_frm.doc.procedure_filter = \"All\";\n cur_frm.doc.step_filter = \"All\";\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.step_name){\n fn_addSteptolist(row.doc.step_name);\n }\n\n if (row.doc.procedure_name){\n fn_addProceduretolist(row.doc.procedure_name);\n }\n \n if (row.doc.procedure_name == previous_procedure_name){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"procedure_name\"]').find('a[data-doctype=\"Procedure Name\"]').css({'color': '#EDEDED'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#FFFFFF'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #ebeef0'});\n }else{\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"procedure_name\"]').find('a[data-doctype=\"Procedure Name\"]').css({'color': '#000000'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#EDEDED'});\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #7b7c7c'});\n }\n previous_procedure_name = row.doc.procedure_name;\n \n \n if (row.doc.step_name == previous_step_name){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"step_name\"]').find('a[data-doctype=\"Procedure Step Name\"]').css({'color': '#DFDFDF'});\n }else{\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"step_name\"]').find('a[data-doctype=\"Procedure Step Name\"]').css({'color': '#000000'});\n }\n previous_step_name = row.doc.step_name;\n let id = row.doc.idx;\n\n });\n\n if (frm.doc.workflow_state == \"Publish Ready\" && frappe.user_roles.indexOf(\"_Admin\") > 0){\n frm.add_custom_button(__('Revoke Publish'), function(){\n //get all system mapping with the procedure linked\n frappe.db.get_list('System Mapping_Sub System', {\n fields: ['parent', 'procedure', 'procedure_status'],\n filters: {\n procedure: frm.doc.name\n }\n }).then(records => {\n var html = \"

\";\n $.each(records, function(index, row){\n html = html + \"\" +\"\";\n });\n html = html + \"
\" + row.parent + \"\" + row.procedure + \"
\";\n frappe.warn('Are you sure you want to Revoke?',\n 'Since there are System Mappings attached to it!!! ' + html,\n () => {\n frm.set_value(\"workflow_state\",\"Draft\");\n frm.save();\n // action to perform if Continue is selected\n },\n 'Continue', false // Sets dialog as minimizable\n );\n });\n });\n }\n },\n \n procedure_filter: function (frm) {\n //if (!trigger){ trigger = true; return;}\n select_row(frm);\n if (frm.doc.procedure_filter ==\"All\"){\n frm.doc.step_filter = \"All\";\n cur_frm.refresh_field('step_filter');\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name != frm.doc.procedure_filter){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n } else {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }\n });\n }\n //frm.refresh();\n \n //Filtered by as per step filter\n if(frm.doc.name && frm.is_new() == undefined){\n $(\"select[data-fieldname='step_filter']\").empty();\n\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n\t\tvar x = frappe.db.get_list('Procedure_Details', {\n\t\t\tfields: ['step_name'],\n\t\t\tfilters: {\n\t\t\t\tprocedure_name: frm.doc.procedure_filter,\n\t\t\t\tparent: frm.doc.name\n\t\t\t}\n\t\t\n\t\t}).then(steps => {\n\t\tvar child;\n\t\t\t$.each(steps, function(index, row){\n\t\t\t\tfn_steplist(row.step_name);\n\t\t\t})\n\t\t})\n }\n \n $(\"select[data-fieldname='step_filter']\").empty();\n\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(\"All\", \"All\"));\n for(var i = 0;i {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('procedure_details').grid.static_rows = false;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name == frm.doc.procedure_filter && row.doc.step_name == frm.doc.step_filter){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }else if(row.doc.procedure_name == frm.doc.procedure_filter && frm.doc.step_filter == \"All\"){\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n \n }else {\n $(\"div[data-fieldname=procedure_details]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n }\n });\n }\n },\n \n before_workflow_action: (frm) => {\n if ((frm.doc.workflow_state == 'Review Pending' || frm.doc.workflow_state == 'Publish Ready') && (frm.selected_workflow_action == 'Revoke')){\n //frappe.throw(\"Any connected Publish Planning will get affected. Please check!\");\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.procedure.procedure.get_publish_details\",\n \"args\": {\n \"procedure_name\": frm.doc.name,\n \"status\":'Published1',\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){\n \t var publish_list = r.message;\n \t if (publish_list.length){\n \t var html = \"This Procedure is linked with the following Publish Docs:
    \";\n \t publish_list.forEach((array_row) => {\n \t html = html + \"
  1. \" + array_row + \"
  2. \";\n \t });\n \t html = html + \"
\";\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'green',\n message: __(html)\n });\n \t }\n \t}\n });\n }\n },\n mat:function(frm){\n if (!frm.is_new()){\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'green',\n message: __('Updating MAT will impact its connected System Mapping and so with Kilometer Mapping. Please Check!')\n });\n }\n }\n});\n\nfrappe.ui.form.on('Procedure_Details', {\n procedure_name: function (frm,cdt,cdn) {\n var title = frm.doc.procedure_filter;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n let value = row.doc.procedure_name;\n if (value)\n if ($(\"select[data-fieldname='procedure_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(value, value));\n }\n \n });\n frm.doc.procedure_filter = title;\n // frm.refresh();\n },\n step_name: function (frm,cdt,cdn) {\n // frm.refresh();\n var filtered_step = frm.doc.step_filter;\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n let value = row.doc.step_name;\n if (value && frm.doc.procedure_filter == \"All\"){\n if ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n }\n }\n if(value && frm.doc.procedure_filter == row.doc.procedure_name){\n fn_stepfilter(row.doc.step_name)\n }\n });\n frm.doc.step_filter = filtered_step;\n\n },\n content_type: function (frm,cdt,cdn) {\n var df;\n let d = locals[cdt][cdn];\n var id = d.idx;\n id = id-1;\n let row = frm.fields_dict.procedure_details.grid.grid_rows[id];\n if (d.content_type == 'Link'){\n let d = new frappe.ui.Dialog({\n title: 'Select a Procedure',\n fields:[\n {\n label: 'Procedure',\n fieldname: 'procedure_map',\n fieldtype: 'Link',\n options:'Procedure'\n }\n ],\n primary_action_label: 'Select',\n primary_action(values) {\n // row.doc.content = values.procedure_map;\n var url = window.location.host;\n var content = values.procedure_map;\n row.doc.temp_cnt = values.procedure_map;\n row.doc.content = content.link(\"http://\" + url + \"/app/procedure/\" + content);\n // row.doc.content = '' + content + '';\n d.hide();\n frm.refresh();\n }\n });\n d.show();\n } else {\n d.content = d.content1;\n }\n },\n procedure_details_move: function (frm,cdt,cdn) {\n frm.refresh();\n },\n procedure_details_remove: function(frm,cdt,cdn){\n frm.doc.procedure_filter = \"All\";\n frm.doc.step_filter = \"All\";\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.procedure_name){\n fn_addProceduretolist(row.doc.procedure_name);\n }\n })\n frm.refresh_field('procedure_details');\n cur_frm.refresh_fields();\n frm.refresh();\n },\n procedure_details_add: function(frm,cdt,cdn) {\n select_row(frm);\n \tvar d = locals[cdt][cdn];\n \tvar id = d.idx;\n id = id-1;\n var row = frm.fields_dict.procedure_details.grid.grid_rows[id];\n var prevrow = frm.fields_dict.procedure_details.grid.grid_rows[id-1];\n if (frm.doc.procedure_filter == \"All\"){\n if (prevrow !== undefined) {\n row.doc.procedure_name = prevrow.doc.procedure_name;\n row.doc.step_name = prevrow.doc.step_name;\n }\n }else{\n row.doc.procedure_name = frm.doc.procedure_filter;\n // row.doc.step_name = prevrow.doc.step_name;\n }\n if (frm.doc.step_filter == \"All\" && frm.doc.procedure_filter == \"All\"){\n if (prevrow !== undefined) {\n row.doc.procedure_name = prevrow.doc.procedure_name;\n row.doc.step_name = prevrow.doc.step_name;\n }\n }\n else if(frm.doc.step_filter == \"All\" && frm.doc.procedure_filter != \"All\"){\n row.doc.procedure_name = frm.doc.procedure_filter;\n // row.doc.step_name = prevrow.doc.step_name;\n }else{\n row.doc.procedure_name = frm.doc.procedure_filter;\n row.doc.step_name = frm.doc.step_filter;\n }\n\n frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {\n if (row.doc.step_name && row.doc.procedure_name == frm.doc.procedure_filter){\n fn_addSteptolist(row.doc.step_name);\n }\n })\n\n refresh_field(\"procedure_filter\");\n refresh_field(\"step_filter\");\n },\n});\n\nfunction fn_addProceduretolist(value){\n if (value === \"\") {return;}\n if ($(\"select[data-fieldname='procedure_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='procedure_filter']\").append(new Option(value, value));\n }\n}\nfunction fn_addSteptolist(value){\n if (value === \"\") {return;}\n if ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n $(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n }\n}\n\nfunction fn_steplist(value){\n\tif (value === \"\") {return;}\n\t\tif ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n\t\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n\t\t}\n}\n\nfunction fn_stepfilter(value){\n\tif (value === \"\") {return;}\n\t \n\t\tif ($(\"select[data-fieldname='step_filter'] option[value='\" + value + \"']\").length === 0){\n\t\t\t$(\"select[data-fieldname='step_filter']\").append(new Option(value, value));\n\t\t}\n}\nfunction select_row(frm){\n if(frm.doc.procedure_filter != \"All\"){\n\t$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class=\"row-index sortable-handle col col-xs-1\"]').find('input[class=\"grid-row-check pull-left\"]').css({'visibility': 'hidden'});\n\t}\n\telse{\n\t$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class=\"row-index sortable-handle col col-xs-1\"]').find('input[class=\"grid-row-check pull-left\"]').css({'visibility': 'visible'});\n\n\t}\n\n}\ncur_frm.cscript.highlight_row = function(grid_row){\n\tvar idx = grid_row.doc.idx;\n\tcur_frm.fields_dict[\"procedure_details\"].$wrapper.find('.grid-body .rows').find(\".grid-row\").each(function(i, item) {\n\tlet d = locals[cur_frm.fields_dict[\"procedure_details\"].grid.doctype][$(item).attr('data-name')];\n\tif(d[\"idx\"] === idx){\n\t\tgrid_row.toggle_editable_row(true);\n\t}\n\t});\n}\n\n", "view": "Form" }, { @@ -82,12 +82,12 @@ "doctype": "Client Script", "dt": "Publish", "enabled": 1, - "modified": "2022-03-25 11:19:22.991552", + "modified": "2022-03-30 15:44:25.764355", "name": "Publish-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.variant\",};\n};\n\ncur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter\",};\n};\n\nvar lang_set_first_time = true;\n\nfrappe.ui.form.on('Publish', {\n onload: function(frm) {\n lang_set_first_time = true;\n frm.get_field('publish_documents').grid.cannot_add_rows = true;\n },\n planned_publish_date: function(frm){\n var date = (frappe.datetime.nowdate())\n if (frm.doc.planned_publish_date < date){\n frm.doc.planned_publish_date = '';\n cur_frm.refresh_fields();\n frappe.msgprint(\"Planned Publish Date: You can not select past date\");\n frappe.validated = false;\n }\n\n },\n refresh: function(frm) {\n if (frm.doc.docstatus === 1 && frm.doc.publish_type == \"Internal\" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish) {\n frm.add_custom_button(__('Global Publish'), function() {\n frappe.call({\n method: \"smart_service.transactions.doctype.publish.publish.global_publish\",\n args: {\n \"doc\": frm.doc.name,\n },\n callback: function(r) {\n cur_frm.reload_doc();\n }\n });\n }).addClass(\"btn-warning\").css({ 'background-color': '#f5b0cd', 'color': 'black' });\n }\n\n\n if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish'){\n frm.add_custom_button(__('Publish'), function(){\n // frm.trigger(\"auto_version_update\");\n frappe.confirm('Are you sure you want to Internal Publish?',\n () => {\n // action to perform if Yes is selected\n if(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){\n \t\t frappe.call({\n method: 'smart_service.transactions.doctype.publish.publish.cal_ver',\n args: {\n vehicle: frm.doc.vehicle,\n lang:frm.doc.language,\n publish_type:frm.doc.publish_type,\n doc:frm.doc.name\n },\n callback: (r) => {\n frm.set_value('version',r.message);\n cur_frm.refresh_field('version')\n // },\n \n // });\n //\t}\n if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish'){\n frappe.call({\n method: \"smart_service.apis.publish_api.api_procedure\",\n // async:false,\n args: {\n \"args\":frm.doc.name,\n \"vehicle\": frm.doc.vehicle,\n \"language\":frm.doc.language,\n \"version\":frm.doc.version\n },\n callback: function(r) {\n frm.set_value('publish_status','Published');\n frm.set_value('actual_published_date',frappe.datetime.nowdate());\n // frm.set_value('published_link',r.message)\n frappe.msgprint(__());\n frappe.msgprint({\n title: __('Notification'),\n message: __('Successfully Published' + r.message),\n primary_action:{\n action(values) {\n frm.save('Update');\n }\n }\n });\n \n }\n \n });\n }\n \n },\n })\n }\n \n }, () => {\n // action to perform if No is selected\n }); \n }).addClass(\"btn-warning\").css({'background-color':'#f5b0cd', 'color':'black'});\n } else if(frm.doc.publish_status == 'Published'){\n frm.set_read_only();\n frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);\n }\n \n frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function() {\n\t var added = 0;\n\t var topublish = [];\n if (frm.doc.publish_type =='Global'){topublish = ['Publish Ready'];}else{topublish = ['Review Pending','Publish Ready','Approval Pending'];}\n frm.doc.system_mapping.forEach(row => {\n if (topublish.indexOf(row.procedure_status) > -1){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && \n row.systems == publishrow.system && \n row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.system = row.systems;\n child.sub_system = row.sub_systems;\n child.procedure_link = row.procedure;\n child.procedure_status = row.procedure_status;\n child.item_category = \"System Mapping\";\n child.variant = frm.doc.variant;\n refresh_field(\"publish_documents\");\n added += 1;\n }\n }\n });\n if (added){frappe.msgprint(__(added + \" Doc(s) Added\"));}\n else{frappe.msgprint(__(\"No Doc Added\"));}\n });\n \n frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');\n\n\t frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function() {\n\t var added = 0;\n\t var topublish = [];\n frm.doc.variant_mapping_assets.forEach(row => {\n if (row.active_status == \"Active\" || row.active_status == \"Inactive\"){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && \n row.category == publishrow.asset_category){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.asset_category = row.category;\n child.item_category = \"Variant Mapping Assets\";\n child.variant = frm.doc.variant;\n refresh_field(\"publish_documents\");\n added += 1;\n }\n }\n });\n if (added){frappe.msgprint(__(added + \" Doc(s) Added\"));}\n else{frappe.msgprint(__(\"No Doc Added\"));}\n });\n \n frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');\n\t},\n\tvalidate: function(frm) {\n\t \n\t if (frm.fields_dict.publish_documents.grid.grid_rows.length === 0){\n\t frappe.msgprint(__(\"No item selected to Publish\"));\n\t frappe.validated = false;\n\t }\n if (frm.doc.planned_publish_date < frappe.datetime.get_today()) {\n frappe.msgprint(__(\"Planned Publish Date: You can not select past date\"));\n frappe.validated = false;\n }\n },\n before_save: function(frm) {\n //frm.set_value('variant_mapping',null);\n // frm.set_value('system_mapping', null);\n // frm.set_value('variant_mapping_assets', null);\n },\n before_cancel: function(frm) {\n if (frm.doc.publish_status == 'Published'){\n //frappe.throw(__('You can not cancel a Published Document!'));\n //frappe.validated = false;\n }\n },\n\tvariant_mapping:function(frm){\n\t frappe.db.get_value('Variant Mapping', { name: frm.doc.variant_mapping }, ['fuel', 'transmission', 'drive'], (r) => {\n frm.doc.variant = r.fuel + ',' + r.transmission + ',' + r.drive;\n cur_frm.refresh_field('variant');\n })\n\n\t var km_name = frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\";\n\t frappe.db.get_value('Kilometer Mapping', {name: km_name}, 'workflow_state' , (r) =>{\n\t if(r.workflow_state == \"Draft\"){\n\t frm.doc.kilometer_mapping = '';\n\t frm.refresh_field('kilometer_mapping')\n\t frappe.throw(\"Kilometer Mapping Draft record not loaded\")\n\t }\n\t \n\t else{\n if (frm.doc.variant_mapping === undefined) {return;}\n frm.set_value('system_mapping', null);\n frm.set_value('variant_mapping_assets', null);\n frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\")\n .then(exists => {\n if (exists){\n frm.set_value(\"kilometer_mapping\",frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\");\n frm.refresh_field('kilometer_mapping')\n } else {\n // frm.set_value(\"kilometer_mapping\",null);\n frm.set_value(\"km_active_status\",\"Not Configured!\");\n }\n });\n\t }\n\t })\n\t},\n\tkm_active_status:function(frm){\n \tif(frm.doc.km_active_status === \"\" || frm.doc.km_active_status === null) {return;}\n var filter = frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-SM\";\n if (frm.doc.variant_mapping_status == \"Active\" && frm.doc.km_active_status == \"Active\") {\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_system\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child;\n child = cur_frm.add_child(\"system_mapping\");\n child.systems = row.systems;\n child.sub_systems = row.sub_systems;\n child.active_status = row.active_status;\n child.symptom = row.symptom;\n child.component = row.component;\n child.estimated_time = row.estimated_time;\n child.rts = row.rts;\n child.mat = row.mat;\n //child.cover_image = row.cover_image;\n child.procedure = row.procedure;\n child.procedure_status = row.procedure_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n \n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_vm_asset\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child;\n child = cur_frm.add_child(\"variant_mapping_assets\");\n child.category = row.category;\n child.language = row.language;\n child.attach_file = row.attach_file;\n child.active_status = row.active_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n \n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_sm_asset\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child_row;\n child_row = cur_frm.add_child(\"variant_mapping_assets\");\n child_row.category = row.systems;\n child_row.language = row.language;\n child_row.attach_file = row.system_asset;\n child_row.active_status = row.active_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n /* frappe.db.get_list('System Mapping_Sub System', {\n fields: ['systems', 'sub_systems','active_status','symptom','component','estimated_time','rts','mat','procedure','procedure_status'],\n filters: { parent: filter,\n procedure_is_published: [\"=\",'0'], }\n }).then(records => {\n //frm.set_value('system_mapping', null);\n var child;\n $.each(records, function(index, row){\n child = cur_frm.add_child(\"system_mapping\");\n child.systems = row.systems;\n child.sub_systems = row.sub_systems;\n child.active_status = row.active_status;\n child.symptom = row.symptom;\n child.component = row.component;\n child.estimated_time = row.estimated_time;\n child.rts = row.rts;\n child.mat = row.mat;\n //child.cover_image = row.cover_image;\n child.procedure = row.procedure;\n child.procedure_status = row.procedure_status;\n if (row.procedure) {\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.procedure.procedure.get_doc_status\",\n \"args\": {\n \"docname\": row.procedure,\n \t},\n \tasync:false,\n \tcallback:function(r){\n child.procedure_status = r.message; //doc.workflow_state;\n if (r.message == 'Review Pending'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#ffa243'});}\n else if (r.message == 'Publish Ready'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#cfffcf'});}\n //refresh_field(\"system_mapping\");\n \t}\n });\n //frappe.db.get_doc('Procedure', row.procedure)\n // .then(doc => {\n \n // child.procedure_status = doc.workflow_state;\n // if (doc.workflow_state == 'Review Pending'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#ffa243'});}\n // else if (doc.workflow_state == 'Publish Ready'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#cfffcf'});}\n // frm.refresh_field(\"system_mapping\");\n // });\n }\n });\n frm.refresh_field('system_mapping');\n });\n \n frappe.db.get_list('Variant Mapping_Assets', {\n fields: ['category', 'language','active_status','attach_file'],\n filters: {\n parent: frm.doc.variant_mapping, \n language: frm.doc.language,\n published: [\"=\",'0'],\n \n }\n }).then(assets => {\n var child;\n $.each(assets, function(index, row){\n //child = cur_frm.add_child(\"variant_mapping_assets\");\n // console.log(row.category)\n // child.category = row.category;\n // child.language = row.language;\n //child.attach_file = row.attach_file;\n // child.active_status = row.active_status;\n });\n \n frappe.db.get_list('System Mapping_System Assets', {\n fields: ['systems', 'language','active_status','system_asset'],\n filters: {\n parent: filter,\n published: [\"=\",'0'],\n \n }\n }).then(asset => {\n var child_row;\n $.each(asset, function(index, row){\n child_row = cur_frm.add_child(\"variant_mapping_assets\");\n child_row.category = row.systems;\n child_row.language = row.language;\n child_row.attach_file = row.system_asset;\n child_row.active_status = row.active_status;\n });\n cur_frm.refresh_field('variant_mapping_assets');\n })\n \n });*/\n \n } else {\n if (frm.doc.variant_mapping_status != null){\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'red',\n message: __('System Mapping & Assets not loaded as the selected Variant/Kilometer Mapping is Inactive or not configured')\n });\n }\n }\t\n\t},\n\tadd_variant_mapping_to_publish:function(frm){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && publishrow.systems === undefined && publishrow.sub_systems === undefined && publishrow.procedure === undefined){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.item_category = \"Variant Mapping\";\n refresh_field(\"publish_documents\");\n frappe.msgprint(__(frm.doc.variant_mapping + \" Added\"));\n }\n\t},\n\tkm_report: function(frm, cdt, cdn) {\n frappe.set_route(\"query-report\", 'Kilometer Mapping', { 'kilometer_mapping': frm.doc.kilometer_mapping });\n },\n\n\tvehicle:function(frm){\n\t frappe.call({\n method: \"smart_service.transactions.doctype.publish.publish.old_publish\",\n async:false,\n args: {\n \"vehicle\": frm.doc.vehicle,\n \"language\": frm.doc.language\n },\n callback: function(r) {\n if (r.message) {\n var vehicle = frm.doc.vehicle;\n cur_frm.doc.vehicle = '';\n cur_frm.doc.vehicle_status = '';\n cur_frm.refresh_field('vehicle');\n cur_frm.refresh_field('vehicle_status');\n frappe.throw(\"Already publish record \" + r.message + \" created for \" + vehicle + \" vehicle. Please edit already available internal publish!\")\n }\n }\n });\n\n\n\t \n\t if (frm.doc.vehicle === undefined || frm.doc.vehicle === null) {return;}\n\t //frm.trigger(\"auto_version_update\");\n var filter = frm.doc.vehicle;\n filter = \"%\"+filter+\"%\";\n frm.set_query(\"variant_mapping\", function() {\n return {\n \"filters\": {\n // \"name\": [\"like\",filter]\n \"vehicle\":frm.doc.vehicle\n }\n };\n });\n $(\"[data-fieldname=variant_mapping]\").focus();\n if(frm.doc.vehicle){\n frm.set_df_property('vehicle', 'read_only', 1);\n }\n\t},\n\tlanguage:function(frm){\n if (!lang_set_first_time){\n frappe.confirm('This will clear all the data, are you sure you want to proceed?',\n () => {\n // action to perform if Yes is selected\n frm.set_value('variant_mapping',null);\n frm.set_value('variant_mapping_status',null);\n frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);\n frm.set_value('system_mapping', null);\n frm.set_value('variant_mapping_assets', null);\n frm.set_value('publish_documents', null);\n lang_set_first_time = false;\n }, () => {\n // action to perform if No is selected\n });\n } else {lang_set_first_time = false;}\n\t},\n\tauto_version_update:function(frm){\n \tif(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){\n \t console.log(\"called ver\")\n \t\tfrappe.call({\n method: 'smart_service.transactions.doctype.publish.publish.cal_ver',\n args: {\n vehicle: frm.doc.vehicle,\n lang:frm.doc.language,\n publish_type:frm.doc.publish_type,\n doc:frm.doc.name\n },\n callback: (r) => {\n //frm.set_value('version',r.message);\n cur_frm.refresh_field('version')\n console.log(frm.doc.version);\n },\n error: (r) => {\n // on error\n }\n });\n \t}\n\t},\n});", + "script": "cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.variant\",};\n};\n\ncur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter\",};\n};\n\nvar lang_set_first_time = true;\n\nfrappe.ui.form.on('Publish', {\n onload: function(frm) {\n lang_set_first_time = true;\n frm.get_field('publish_documents').grid.cannot_add_rows = true;\n },\n planned_publish_date: function(frm){\n var date = (frappe.datetime.nowdate())\n if (frm.doc.planned_publish_date < date){\n frm.doc.planned_publish_date = '';\n cur_frm.refresh_fields();\n frappe.msgprint(\"Planned Publish Date: You can not select past date\");\n frappe.validated = false;\n }\n\n },\n refresh: function(frm) {\n if (frm.doc.docstatus === 1 && frm.doc.publish_type == \"Internal\" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish) {\n frm.add_custom_button(__('Global Publish'), function() {\n frappe.call({\n method: \"smart_service.transactions.doctype.publish.publish.global_publish\",\n args: {\n \"doc\": frm.doc.name,\n },\n callback: function(r) {\n cur_frm.reload_doc();\n }\n });\n }).addClass(\"btn-warning\").css({ 'background-color': '#f5b0cd', 'color': 'black' });\n }\n\n\n if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish'){\n frm.add_custom_button(__('Publish'), function(){\n // frm.trigger(\"auto_version_update\");\n frappe.confirm('Are you sure you want to Internal Publish?',\n () => {\n // action to perform if Yes is selected\n if(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){\n \t\t frappe.call({\n method: 'smart_service.transactions.doctype.publish.publish.cal_ver',\n args: {\n vehicle: frm.doc.vehicle,\n lang:frm.doc.language,\n publish_type:frm.doc.publish_type,\n doc:frm.doc.name\n },\n callback: (r) => {\n frm.set_value('version',r.message);\n cur_frm.refresh_field('version')\n // },\n \n // });\n //\t}\n if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish'){\n frappe.call({\n method: \"smart_service.apis.publish_api.api_procedure\",\n // async:false,\n args: {\n \"args\":frm.doc.name,\n \"vehicle\": frm.doc.vehicle,\n \"language\":frm.doc.language,\n \"version\":frm.doc.version\n },\n callback: function(r) {\n frm.set_value('publish_status','Published');\n frm.set_value('actual_published_date',frappe.datetime.nowdate());\n // frm.set_value('published_link',r.message)\n frappe.msgprint(__());\n frappe.msgprint({\n title: __('Notification'),\n message: __('Successfully Published' + r.message),\n primary_action:{\n action(values) {\n frm.save('Update');\n }\n }\n });\n \n }\n \n });\n }\n \n },\n })\n }\n \n }, () => {\n // action to perform if No is selected\n }); \n }).addClass(\"btn-warning\").css({'background-color':'#f5b0cd', 'color':'black'});\n } else if(frm.doc.publish_status == 'Published'){\n frm.set_read_only();\n frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);\n }\n \n frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function() {\n\t var added = 0;\n\t var topublish = [];\n if (frm.doc.publish_type =='Global'){topublish = ['Publish Ready'];}else{topublish = ['Review Pending','Publish Ready','Approval Pending'];}\n frm.doc.system_mapping.forEach(row => {\n if (topublish.indexOf(row.procedure_status) > -1){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && \n row.systems == publishrow.system && \n row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.system = row.systems;\n child.sub_system = row.sub_systems;\n child.procedure_link = row.procedure;\n child.procedure_status = row.procedure_status;\n child.item_category = \"System Mapping\";\n child.variant = frm.doc.variant;\n refresh_field(\"publish_documents\");\n added += 1;\n }\n }\n });\n if (added){frappe.msgprint(__(added + \" Doc(s) Added\"));}\n else{frappe.msgprint(__(\"No Doc Added\"));}\n });\n \n frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');\n\n\t frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function() {\n\t var added = 0;\n\t var topublish = [];\n frm.doc.variant_mapping_assets.forEach(row => {\n if (row.active_status == \"Active\" || row.active_status == \"Inactive\"){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && \n row.category == publishrow.asset_category){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.asset_category = row.category;\n child.item_category = \"Variant Mapping Assets\";\n child.variant = frm.doc.variant;\n refresh_field(\"publish_documents\");\n added += 1;\n }\n }\n });\n if (added){frappe.msgprint(__(added + \" Doc(s) Added\"));}\n else{frappe.msgprint(__(\"No Doc Added\"));}\n });\n \n frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');\n\t},\n\tvalidate: function(frm) {\n\t \n\t if (frm.fields_dict.publish_documents.grid.grid_rows.length === 0){\n\t frappe.msgprint(__(\"No item selected to Publish\"));\n\t frappe.validated = false;\n\t }\n if (frm.doc.planned_publish_date < frappe.datetime.get_today()) {\n frappe.msgprint(__(\"Planned Publish Date: You can not select past date\"));\n frappe.validated = false;\n }\n },\n before_save: function(frm) {\n //frm.set_value('variant_mapping',null);\n // frm.set_value('system_mapping', null);\n // frm.set_value('variant_mapping_assets', null);\n },\n before_cancel: function(frm) {\n if (frm.doc.publish_status == 'Published'){\n //frappe.throw(__('You can not cancel a Published Document!'));\n //frappe.validated = false;\n }\n },\n\tvariant_mapping:function(frm){\n\t frappe.db.get_value('Variant Mapping', { name: frm.doc.variant_mapping }, ['fuel', 'transmission', 'drive'], (r) => {\n frm.doc.variant = r.fuel + ',' + r.transmission + ',' + r.drive;\n cur_frm.refresh_field('variant');\n })\n\n\t var km_name = frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\";\n\t frappe.db.get_value('Kilometer Mapping', {name: km_name}, 'workflow_state' , (r) =>{\n\t if(r.workflow_state == \"Draft\"){\n\t frm.doc.kilometer_mapping = '';\n\t frm.refresh_field('kilometer_mapping')\n\t frappe.msgprint(\"Kilometer Mapping Draft record not loaded\")\n\t }\n\t \n\t else{\n if (frm.doc.variant_mapping === undefined) {return;}\n frm.set_value('system_mapping', null);\n frm.set_value('variant_mapping_assets', null);\n frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\")\n .then(exists => {\n if (exists){\n frm.set_value(\"kilometer_mapping\",frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-KM\");\n frm.refresh_field('kilometer_mapping')\n } else {\n // frm.set_value(\"kilometer_mapping\",null);\n frm.set_value(\"km_active_status\",\"Not Configured!\");\n }\n });\n\t }\n\t })\n\t},\n\tkm_active_status:function(frm){\n \tif(frm.doc.km_active_status === \"\" || frm.doc.km_active_status === null) {return;}\n var filter = frm.doc.variant_mapping + \"-\" + frm.doc.language + \"-SM\";\n if (frm.doc.variant_mapping_status == \"Active\" && frm.doc.km_active_status == \"Active\") {\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_system\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child;\n child = cur_frm.add_child(\"system_mapping\");\n child.systems = row.systems;\n child.sub_systems = row.sub_systems;\n child.active_status = row.active_status;\n child.symptom = row.symptom;\n child.component = row.component;\n child.estimated_time = row.estimated_time;\n child.rts = row.rts;\n child.mat = row.mat;\n //child.cover_image = row.cover_image;\n child.procedure = row.procedure;\n child.procedure_status = row.procedure_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n \n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_vm_asset\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child;\n child = cur_frm.add_child(\"variant_mapping_assets\");\n child.category = row.category;\n child.language = row.language;\n child.attach_file = row.attach_file;\n child.active_status = row.active_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n \n frappe.call({\n \"method\": \"smart_service.transactions.doctype.publish.publish.get_sm_asset\",\n \"args\": {\n \"doc\": frm.doc.variant_mapping,\n },\n callback: function(r) {\n $.each(r.message, function(index, row) {\n var child_row;\n child_row = cur_frm.add_child(\"variant_mapping_assets\");\n child_row.category = row.systems;\n child_row.language = row.language;\n child_row.attach_file = row.system_asset;\n child_row.active_status = row.active_status;\n cur_frm.refresh_field('variant_mapping_assets');\n cur_frm.refresh_fields();\n })\n }\n\n })\n /* frappe.db.get_list('System Mapping_Sub System', {\n fields: ['systems', 'sub_systems','active_status','symptom','component','estimated_time','rts','mat','procedure','procedure_status'],\n filters: { parent: filter,\n procedure_is_published: [\"=\",'0'], }\n }).then(records => {\n //frm.set_value('system_mapping', null);\n var child;\n $.each(records, function(index, row){\n child = cur_frm.add_child(\"system_mapping\");\n child.systems = row.systems;\n child.sub_systems = row.sub_systems;\n child.active_status = row.active_status;\n child.symptom = row.symptom;\n child.component = row.component;\n child.estimated_time = row.estimated_time;\n child.rts = row.rts;\n child.mat = row.mat;\n //child.cover_image = row.cover_image;\n child.procedure = row.procedure;\n child.procedure_status = row.procedure_status;\n if (row.procedure) {\n frappe.call({\n \"method\": \"smart_service.transactions.doctype.procedure.procedure.get_doc_status\",\n \"args\": {\n \"docname\": row.procedure,\n \t},\n \tasync:false,\n \tcallback:function(r){\n child.procedure_status = r.message; //doc.workflow_state;\n if (r.message == 'Review Pending'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#ffa243'});}\n else if (r.message == 'Publish Ready'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#cfffcf'});}\n //refresh_field(\"system_mapping\");\n \t}\n });\n //frappe.db.get_doc('Procedure', row.procedure)\n // .then(doc => {\n \n // child.procedure_status = doc.workflow_state;\n // if (doc.workflow_state == 'Review Pending'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#ffa243'});}\n // else if (doc.workflow_state == 'Publish Ready'){$(\"div[data-fieldname=system_mapping]\").find('div.grid-row[data-idx=\"'+ child.idx + '\"]').find('div.col[data-fieldname=\"procedure_status\"]').css({'background-color': '#cfffcf'});}\n // frm.refresh_field(\"system_mapping\");\n // });\n }\n });\n frm.refresh_field('system_mapping');\n });\n \n frappe.db.get_list('Variant Mapping_Assets', {\n fields: ['category', 'language','active_status','attach_file'],\n filters: {\n parent: frm.doc.variant_mapping, \n language: frm.doc.language,\n published: [\"=\",'0'],\n \n }\n }).then(assets => {\n var child;\n $.each(assets, function(index, row){\n //child = cur_frm.add_child(\"variant_mapping_assets\");\n // console.log(row.category)\n // child.category = row.category;\n // child.language = row.language;\n //child.attach_file = row.attach_file;\n // child.active_status = row.active_status;\n });\n \n frappe.db.get_list('System Mapping_System Assets', {\n fields: ['systems', 'language','active_status','system_asset'],\n filters: {\n parent: filter,\n published: [\"=\",'0'],\n \n }\n }).then(asset => {\n var child_row;\n $.each(asset, function(index, row){\n child_row = cur_frm.add_child(\"variant_mapping_assets\");\n child_row.category = row.systems;\n child_row.language = row.language;\n child_row.attach_file = row.system_asset;\n child_row.active_status = row.active_status;\n });\n cur_frm.refresh_field('variant_mapping_assets');\n })\n \n });*/\n \n } else {\n if (frm.doc.variant_mapping_status != null){\n frappe.msgprint({\n title: __('Notification'),\n indicator: 'red',\n message: __('System Mapping & Assets not loaded as the selected Variant/Kilometer Mapping is Inactive or not configured')\n });\n }\n }\t\n\t},\n\tadd_variant_mapping_to_publish:function(frm){\n var dulicate = false;\n if (frm.doc.publish_documents){\n frm.doc.publish_documents.forEach(publishrow => {\n if (frm.doc.variant_mapping == publishrow.variant_mapping && publishrow.systems === undefined && publishrow.sub_systems === undefined && publishrow.procedure === undefined){\n dulicate = true;\n }\n });\n }\n if (dulicate === false){\n var child = cur_frm.add_child(\"publish_documents\");\n child.variant_mapping = frm.doc.variant_mapping;\n child.item_category = \"Variant Mapping\";\n refresh_field(\"publish_documents\");\n frappe.msgprint(__(frm.doc.variant_mapping + \" Added\"));\n }\n\t},\n\tkm_report: function(frm, cdt, cdn) {\n frappe.set_route(\"query-report\", 'Kilometer Mapping', { 'kilometer_mapping': frm.doc.kilometer_mapping });\n },\n\n\tvehicle:function(frm){\n\t frappe.call({\n method: \"smart_service.transactions.doctype.publish.publish.old_publish\",\n async:false,\n args: {\n \"vehicle\": frm.doc.vehicle,\n \"language\": frm.doc.language\n },\n callback: function(r) {\n if (r.message) {\n var vehicle = frm.doc.vehicle;\n cur_frm.doc.vehicle = '';\n cur_frm.doc.vehicle_status = '';\n cur_frm.refresh_field('vehicle');\n cur_frm.refresh_field('vehicle_status');\n frappe.throw(\"Already publish record \" + r.message + \" created for \" + vehicle + \" vehicle. Please edit already available internal publish!\")\n }\n }\n });\n\n\n\t \n\t if (frm.doc.vehicle === undefined || frm.doc.vehicle === null) {return;}\n\t //frm.trigger(\"auto_version_update\");\n var filter = frm.doc.vehicle;\n filter = \"%\"+filter+\"%\";\n frm.set_query(\"variant_mapping\", function() {\n return {\n \"filters\": {\n // \"name\": [\"like\",filter]\n \"vehicle\":frm.doc.vehicle\n }\n };\n });\n $(\"[data-fieldname=variant_mapping]\").focus();\n if(frm.doc.vehicle){\n frm.set_df_property('vehicle', 'read_only', 1);\n }\n\t},\n\tlanguage:function(frm){\n if (!lang_set_first_time){\n frappe.confirm('This will clear all the data, are you sure you want to proceed?',\n () => {\n // action to perform if Yes is selected\n frm.set_value('variant_mapping',null);\n frm.set_value('variant_mapping_status',null);\n frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);\n frm.set_value('system_mapping', null);\n frm.set_value('variant_mapping_assets', null);\n frm.set_value('publish_documents', null);\n lang_set_first_time = false;\n }, () => {\n // action to perform if No is selected\n });\n } else {lang_set_first_time = false;}\n\t},\n\tauto_version_update:function(frm){\n \tif(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){\n \t console.log(\"called ver\")\n \t\tfrappe.call({\n method: 'smart_service.transactions.doctype.publish.publish.cal_ver',\n args: {\n vehicle: frm.doc.vehicle,\n lang:frm.doc.language,\n publish_type:frm.doc.publish_type,\n doc:frm.doc.name\n },\n callback: (r) => {\n //frm.set_value('version',r.message);\n cur_frm.refresh_field('version')\n console.log(frm.doc.version);\n },\n error: (r) => {\n // on error\n }\n });\n \t}\n\t},\n});", "view": "Form" }, { @@ -121,12 +121,12 @@ "doctype": "Client Script", "dt": "Vehicle", "enabled": 1, - "modified": "2022-02-12 15:09:06.166586", + "modified": "2022-03-31 11:06:30.151988", "name": "Vehicle-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "cur_frm.fields_dict['vehicle_segment'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_segment\",\n };\n };\n\nvar original_display_order = 0;\nvar vehicle_count = 0;\nvar skm_array = [];\nvar dusted = false;\n\nfrappe.ui.form.on('Vehicle', {\n\tonload: function(frm) {\n if (!frm.is_new()) fnLoad_skm_initial_values(frm);\n\t},\n\n\trefresh: function(frm) {\n if (frm.is_new()){\n frm.set_df_property('display_order', 'read_only', 1);\n } else {\n frm.set_df_property('display_order', 'read_only', 0);\n }\n if (!frm.is_new()) {\n frm.disable_save(); //*** Check Refresh for Save Function\n \n frm.add_custom_button(__('Save'), function(){\n fnSave(frm);\n }).addClass(\"btn-warning\").css({'background-color':'#e31a37', 'color':'white'});\n }\n\n\t\tfrappe.db.count('Vehicle')\n .then(count => {\n vehicle_count = count + 1;\n if (frm.is_new()){ \n frm.set_value(\"display_order\",vehicle_count); \n } else {\n original_display_order = frm.doc.display_order;\n }\n });\n\t},\n\t\n\tvalidate: function(frm) {\n\t if (frm.doc.vehicle == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;\n if (regex.test(frm.doc.vehicle) === false){\n frappe.throw(__(\"Vehicle: Only letters, numbers and &()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.vehicle) {\n if(frm.doc.vehicle.includes(\"'\")) {\n frappe.throw(__(\"Vehicle: Only letters, numbers and &()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n }\n }\n \n if (frm.doc.display_order && frm.doc.vehicle && frm.doc.vehicle_segment){\n //*** check if there is same display_order\n frappe.db.get_list('Vehicle', {\n fields: ['display_order', 'name'],\n filters: {\n display_order: frm.doc.display_order,\n vehicle:[\"!=\",frm.doc.vehicle]\n }\n }).then(records => {\n if (records.length){\n frappe.db.set_value('Vehicle', records[0].name, {\n display_order: original_display_order\n }).then(r => {\n let doc = r.message;\n frappe.show_alert({\n message:__('Swapped display order with: ' + records[0].name),\n indicator:'green'\n }, 5);\n });\n } else {\n if (frm.doc.display_order > vehicle_count){\n let display_vehicle_count = vehicle_count - 1;\n msgprint('There are only ' + display_vehicle_count + ' vehicle(s)');\n frappe.validated = false;\n }\n }\n });\n }\n\t},\n\n\tservice_kilometers: function(frm) {\n //*** Check & add any KM got added in Service Kilometers\n\n dusted = true;\n frm.doc.service_kilometers.forEach(row => {\n let index = skm_array.findIndex(o => o.name === row.name);\n if (index < 0){\n let index1 = skm_array.findIndex(o => o.skm_initial === row.service_kilometers);\n if (index1 >= 0){\n skm_array[index1].type = \"Initial\";\n } else {\n var valueToPush = {};\n valueToPush.type = \"New\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n skm_array.push(valueToPush);\n }\n }\n });\n var current_skm_array = [];\n frm.doc.service_kilometers.forEach(row => {\n var valueToPush = {};\n valueToPush.type = \"Initial\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n current_skm_array.push(valueToPush);\n });\n\n //*** Check & remove any KM got Removed in Service Kilometers\n var idx=0;\n skm_array.forEach(row => {\n idx++;\n let index = current_skm_array.findIndex(o => o.skm_initial === row.skm_initial);\n if (index < 0){\n //row.type = row.type === \"New\" ? \"No Action\": \"Deleted\";\n if (row.type == \"New\"){\n skm_array.splice(idx-1, 1);\n }else{\n row.type = \"Deleted\";\n }\n }\n });\n }\n});\n\nfrappe.ui.form.on('Vehicle', {\n\tafter_save1: function(frm) {\n\t frappe.call({\n \"method\": \"smart_service.masters.doctype.vehicle.vehicle.update_km_mapping\",\n \"args\": {\n \"doc\":frm.doc.name,\n \"skm_array\": skm_array,\n \"skm\": frm.doc.service_kilometers\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){}\n });\n \n\t}\n\t\n});\n\nfunction fnLoad_skm_initial_values(frm){\n // ***Store the Initial Service Kilometer values\n skm_array.length = 0;\n frm.doc.service_kilometers.forEach(row => {\n var valueToPush = {};\n valueToPush.type = \"Initial\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n skm_array.push(valueToPush);\n });\n}\n\nfunction fnSave(frm){\n //console.log(\"Dusted\");\n if (dusted){\n frappe.confirm('Changes will impact KM Mapping associated with this vehicle: ' + frm.doc.vehicle + '',\n () => {\n //*** Change the State to Draft for KM\n frm.save();\n skm_array.forEach((array_row) => {\n \n //*** Add Edit Delete the respective Kiolmeter with Updated/Deleted SKM\n if (array_row.type !== \"Initial\"){\n frappe.call({\n \"method\": \"smart_service.masters.doctype.vehicle.vehicle.update_km_mapping\",\n \"args\": {\n \"doc\": frm.doc.name,\n \"vehicle\":frm.doc.vehicle,\n \"type\":array_row.type,\n \"skm_initial\":array_row.skm_initial\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){}\n });\n }\n });\n frappe.show_alert({\n message:__('Inserted Rows in Respective KM Doc & made as Draft Mode!'),\n indicator:'green'\n }, 5);\n fnLoad_skm_initial_values(frm);\n }, () => {\n // action to perform if No is selected\n });\n } else if(frm.is_dirty()){\n frm.save();\n fnLoad_skm_initial_values(frm);\n } else {\n frappe.show_alert({\n message:__('No updates for Kilometer Mapping... '),\n indicator:'green'\n }, 5);\n }\n}", + "script": "cur_frm.fields_dict['vehicle_segment'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_segment\",\n };\n };\n\nvar original_display_order = 0;\nvar vehicle_count = 0;\nvar skm_array = [];\nvar dusted = false;\n\nfrappe.ui.form.on('Vehicle', {\n\tonload: function(frm) {\n if (!frm.is_new()) fnLoad_skm_initial_values(frm);\n\t},\n image: function (frm) {\n\t\tvar file = frm.doc.image;\n\t\tif (frm.doc.image) {\n\t\t\tfrappe.call({\n\t\t\t\tmethod: \"smart_service.masters.doctype.vehicle.vehicle.image_size\",\n\t\t\t\targs: {\n\t\t\t\t\t\"image\": frm.doc.image,\n\t\t\t\t\t\"doc\": frm.doc.name\n\t\t\t\t},\n\t\t\t\tcallback: function (r) {\n\t\t\t\tif(r.message){\n\t\t\t\t\tif(r.message == frm.doc.image){\n\t\t\t\t\t\tfrm.doc.image = '';\n\t\t\t\t\t\tcur_frm.refresh_field('image');\n\t\t\t\t\t\tfrappe.show_alert({\n\t\t\t\t\t\t\tmessage: __('Max Dimesions are 510*510.'),\n\t\t\t\t\t\t\tindicator: 'yellow'\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tfrm.doc.image = '';\n\t\t\t\t\t\tcur_frm.refresh_field('image');\n\t\t\t\t\t\tfrappe.show_alert({\n\t\t\t\t\t\t\tmessage: __('Max Image Size is 10MB.'),\n\t\t\t\t\t\t\tindicator: 'yellow'\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t},\n\trefresh: function(frm) {\n if (frm.is_new()){\n frm.set_df_property('display_order', 'read_only', 1);\n } else {\n frm.set_df_property('display_order', 'read_only', 0);\n }\n if (!frm.is_new()) {\n frm.disable_save(); //*** Check Refresh for Save Function\n \n frm.add_custom_button(__('Save'), function(){\n fnSave(frm);\n }).addClass(\"btn-warning\").css({'background-color':'#e31a37', 'color':'white'});\n }\n\n\t\tfrappe.db.count('Vehicle')\n .then(count => {\n vehicle_count = count + 1;\n if (frm.is_new()){ \n frm.set_value(\"display_order\",vehicle_count); \n } else {\n original_display_order = frm.doc.display_order;\n }\n });\n\t},\n\t\n\tvalidate: function(frm) {\n\t if (frm.doc.vehicle.length>50){\n\t\t\tfrappe.msgprint(\"Vehicle not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.vehicle.length == 1){\n\t\t\tfrappe.msgprint(\"Vehicle not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t if (frm.doc.vehicle == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n //var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\n if (regex.test(frm.doc.vehicle) === true){\n frappe.throw(__(\"Vehicle: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.vehicle) {\n if(frm.doc.vehicle.includes(\"'\")) {\n frappe.throw(__(\"Vehicle: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n }\n }\n \n if (frm.doc.display_order && frm.doc.vehicle && frm.doc.vehicle_segment){\n //*** check if there is same display_order\n frappe.db.get_list('Vehicle', {\n fields: ['display_order', 'name'],\n filters: {\n display_order: frm.doc.display_order,\n vehicle:[\"!=\",frm.doc.vehicle]\n }\n }).then(records => {\n if (records.length){\n frappe.db.set_value('Vehicle', records[0].name, {\n display_order: original_display_order\n }).then(r => {\n let doc = r.message;\n frappe.show_alert({\n message:__('Swapped display order with: ' + records[0].name),\n indicator:'green'\n }, 5);\n });\n } else {\n if (frm.doc.display_order > vehicle_count){\n let display_vehicle_count = vehicle_count - 1;\n msgprint('There are only ' + display_vehicle_count + ' vehicle(s)');\n frappe.validated = false;\n }\n }\n });\n }\n\t},\n\n\tservice_kilometers: function(frm) {\n //*** Check & add any KM got added in Service Kilometers\n\n dusted = true;\n frm.doc.service_kilometers.forEach(row => {\n let index = skm_array.findIndex(o => o.name === row.name);\n if (index < 0){\n let index1 = skm_array.findIndex(o => o.skm_initial === row.service_kilometers);\n if (index1 >= 0){\n skm_array[index1].type = \"Initial\";\n } else {\n var valueToPush = {};\n valueToPush.type = \"New\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n skm_array.push(valueToPush);\n }\n }\n });\n var current_skm_array = [];\n frm.doc.service_kilometers.forEach(row => {\n var valueToPush = {};\n valueToPush.type = \"Initial\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n current_skm_array.push(valueToPush);\n });\n\n //*** Check & remove any KM got Removed in Service Kilometers\n var idx=0;\n skm_array.forEach(row => {\n idx++;\n let index = current_skm_array.findIndex(o => o.skm_initial === row.skm_initial);\n if (index < 0){\n //row.type = row.type === \"New\" ? \"No Action\": \"Deleted\";\n if (row.type == \"New\"){\n skm_array.splice(idx-1, 1);\n }else{\n row.type = \"Deleted\";\n }\n }\n });\n }\n});\n\nfrappe.ui.form.on('Vehicle', {\n\tafter_save1: function(frm) {\n\t frappe.call({\n \"method\": \"smart_service.masters.doctype.vehicle.vehicle.update_km_mapping\",\n \"args\": {\n \"doc\":frm.doc.name,\n \"skm_array\": skm_array,\n \"skm\": frm.doc.service_kilometers\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){}\n });\n \n\t}\n\t\n});\n\nfunction fnLoad_skm_initial_values(frm){\n // ***Store the Initial Service Kilometer values\n skm_array.length = 0;\n frm.doc.service_kilometers.forEach(row => {\n var valueToPush = {};\n valueToPush.type = \"Initial\";\n valueToPush.name = row.name;\n valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);\n skm_array.push(valueToPush);\n });\n}\n\nfunction fnSave(frm){\n //console.log(\"Dusted\");\n if (dusted){\n frappe.confirm('Changes will impact KM Mapping associated with this vehicle: ' + frm.doc.vehicle + '',\n () => {\n //*** Change the State to Draft for KM\n frm.save();\n skm_array.forEach((array_row) => {\n \n //*** Add Edit Delete the respective Kiolmeter with Updated/Deleted SKM\n if (array_row.type !== \"Initial\"){\n frappe.call({\n \"method\": \"smart_service.masters.doctype.vehicle.vehicle.update_km_mapping\",\n \"args\": {\n \"doc\": frm.doc.name,\n \"vehicle\":frm.doc.vehicle,\n \"type\":array_row.type,\n \"skm_initial\":array_row.skm_initial\n \t},\n \tfreeze: true,\n \tasync:false,\n \tcallback:function(r){}\n });\n }\n });\n frappe.show_alert({\n message:__('Inserted Rows in Respective KM Doc & made as Draft Mode!'),\n indicator:'green'\n }, 5);\n fnLoad_skm_initial_values(frm);\n }, () => {\n // action to perform if No is selected\n });\n } else if(frm.is_dirty()){\n frm.save();\n fnLoad_skm_initial_values(frm);\n } else {\n frappe.show_alert({\n message:__('No updates for Kilometer Mapping... '),\n indicator:'green'\n }, 5);\n }\n}", "view": "Form" }, { @@ -147,12 +147,12 @@ "doctype": "Client Script", "dt": "Vehicle Segment", "enabled": 1, - "modified": "2022-01-23 12:00:08.159933", + "modified": "2022-03-29 16:52:17.474675", "name": "Vehicle Segment-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "var original_display_order = 0;\nvar vehicle_count = 0;\nfrappe.ui.form.on('Vehicle Segment', {\n\trefresh: function(frm) {\n if (frm.is_new()){\n frm.set_df_property('display_order', 'read_only', 1);\n } else {\n frm.set_df_property('display_order', 'read_only', 0);\n }\n\t\tfrappe.db.count('Vehicle Segment')\n .then(count => {\n vehicle_count = count + 1;\n if (frm.is_new()){ \n frm.set_value(\"display_order\",vehicle_count); \n } else {\n original_display_order = frm.doc.display_order;\n }\n });\n\t},\n\t\n\tvalidate: function(frm) {\n\t if (frm.doc.vehicle_segment == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;\n if (regex.test(frm.doc.vehicle_segment) === false){\n frappe.throw(__(\"Vehicle Segment: Only letters, numbers and &()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.vehicle_segment) {\n if(frm.doc.vehicle_segment.includes(\"'\")) {\n frappe.throw(__(\"Vehicle Segment: Only letters, numbers and &()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n }\n }\n if (frm.doc.display_order && frm.doc.vehicle_segment){\n \t //***check if there is same display_order\n frappe.db.get_list('Vehicle Segment', {\n fields: ['display_order', 'name'],\n filters: {\n display_order: frm.doc.display_order,\n vehicle_segment:[\"!=\",frm.doc.vehicle_segment]\n }\n }).then(records => {\n if (records.length){\n frappe.db.set_value('Vehicle Segment', records[0].name, {\n display_order: original_display_order\n }).then(r => {\n let doc = r.message;\n frappe.show_alert({\n message:__('Swapped display order with: ' + records[0].name),\n indicator:'green'\n }, 5);\n });\n } else {\n if (frm.doc.display_order > vehicle_count){\n let display_vehicle_count = vehicle_count - 1;\n msgprint('There are only ' + display_vehicle_count + ' Vehicle Segment(s)');\n frappe.validated = false;\n }\n }\n });\n }\n\t}\n});", + "script": "var original_display_order = 0;\nvar vehicle_count = 0;\nfrappe.ui.form.on('Vehicle Segment', {\n onload: function(frm){\n frappe.db.count('Vehicle Segment')\n .then(count => {\n vehicle_count = count + 1;\n console.log(vehicle_count)\n if (frm.is_new()){ \n frm.set_value(\"display_order\",vehicle_count); \n } else {\n original_display_order = frm.doc.display_order;\n }\n }); \n },\n\trefresh: function(frm) {\n if (frm.is_new()){\n frm.set_df_property('display_order', 'read_only', 1);\n } else {\n frm.set_df_property('display_order', 'read_only', 0);\n }\n\t\tfrappe.db.count('Vehicle Segment')\n .then(count => {\n vehicle_count = count + 1;\n if (frm.is_new()){ \n frm.set_value(\"display_order\",vehicle_count); \n } else {\n original_display_order = frm.doc.display_order;\n }\n });\n\t},\n\t\n\tvalidate: function(frm) {\n\t if (frm.doc.vehicle_segment.length>50){\n\t\t\tfrappe.msgprint(\"Vehicle Segment not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.vehicle_segment.length == 1){\n\t\t\tfrappe.msgprint(\"Vehicle Segment not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t if (frm.doc.vehicle_segment == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n //var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;\n var regex = /[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]+/;\n if (regex.test(frm.doc.vehicle_segment) === true){\n frappe.throw(__(\"Vehicle Segment: Only letters and numbers are allowed\"));\n frappe.validated = false;\n } else if(frm.doc.vehicle_segment) {\n if(frm.doc.vehicle_segment.includes(\"'\")) {\n frappe.throw(__(\"Vehicle Segment: Only letters and numbers are allowed.\"));\n frappe.validated = false;\n }\n }\n if (frm.doc.display_order && frm.doc.vehicle_segment){\n \t //***check if there is same display_order\n frappe.db.get_list('Vehicle Segment', {\n fields: ['display_order', 'name'],\n filters: {\n display_order: frm.doc.display_order,\n vehicle_segment:[\"!=\",frm.doc.vehicle_segment]\n }\n }).then(records => {\n if (records.length){\n frappe.db.set_value('Vehicle Segment', records[0].name, {\n display_order: original_display_order\n }).then(r => {\n let doc = r.message;\n frappe.show_alert({\n message:__('Swapped display order with: ' + records[0].name),\n indicator:'green'\n }, 5);\n });\n } else {\n if (frm.doc.display_order > vehicle_count){\n let display_vehicle_count = vehicle_count - 1;\n msgprint('There are only ' + display_vehicle_count + ' Vehicle Segment(s)');\n frappe.validated = false;\n }\n }\n });\n }\n\t}\n});", "view": "Form" }, { @@ -199,12 +199,12 @@ "doctype": "Client Script", "dt": "Service Kilometers", "enabled": 1, - "modified": "2022-01-27 10:25:48.290045", + "modified": "2022-03-31 15:43:01.588230", "name": "Service Kilometers-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "var km_exists = false;\nfrappe.ui.form.on('Service Kilometers', {\n\tvalidate: function(frm) {\n if(frm.doc.kilometer === undefined) {\n frappe.throw(__(\"Kilometer can not be empty!\"));\n frappe.validated = false;\n return;\n }\n var regex = /^[0-9]*$/;\n if (regex.test(frm.doc.kilometer) === false){\n frappe.throw(__(\"Kilometer: Only numbers are allowed.\"));\n frappe.validated = false;\n } else if((frm.doc.kilometer.includes(\"'\"))) {\n frappe.throw(__(\"Kilometer: Only numbers are allowed.\"));\n frappe.validated = false;\n }\n\t if (km_exists)\n\t {\n\t frappe.throw(__('Kilometer already Exists!'));\n\t frappe.validated = flase;\n\t }\n\t},\n\t\n kilometer: function(frm) {\n frappe.db.exists('Service Kilometers', frm.doc.kilometer)\n .then(exists => {\n km_exists = exists;\n console.log(exists);\n });\n }\n});", + "script": "var km_exists = false;\nfrappe.ui.form.on('Service Kilometers', {\n refresh: function (frm) {\n\t\tif (!frm.is_new()){\n\t\t\tcur_frm.toggle_display(\"km_name\", true); \n\t\t}else{\n\t\t\tcur_frm.toggle_display(\"km_name\", false);\n\t\t}\n\n\t\tif(frm.doc.name && frm.doc.kilometer){\n\t\t\tfrm.doc.km_name = frm.doc.name;\n\t\t\tcur_frm.refresh_field('km_name');\n\t\t}\n\t\tif (Object.keys(frm.doc.kilometer).length > 0) {\n\t\t\tfrm.doc.kilometer = '';\n\t\t\tcur_frm.refresh_field('kilometer');\n\t\t\t\n\t\t}\n\t},\n\tvalidate: function(frm) {\n\t if (frm.doc.kilometer.length>50){\n\t\t\tfrappe.msgprint(\"Service Kilometer not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\t\n if(frm.doc.kilometer === undefined) {\n frappe.throw(__(\"Kilometer can not be empty!\"));\n frappe.validated = false;\n return;\n }\n // var regex = /^[0-9]*$/;\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\n if (regex.test(frm.doc.kilometer) === true){\n frappe.throw(__(\"Kilometer: Only numbers are allowed.\"));\n frappe.validated = false;\n } else if((frm.doc.kilometer.includes(\"'\"))) {\n frappe.throw(__(\"Kilometer: Only numbers are allowed.\"));\n frappe.validated = false;\n }\n\t if (km_exists)\n\t {\n\t frappe.throw(__('Kilometer already Exists!'));\n\t frappe.validated = flase;\n\t }\n\t},\n\t\n kilometer: function(frm) {\n frappe.db.exists('Service Kilometers', frm.doc.kilometer)\n .then(exists => {\n km_exists = exists;\n console.log(exists);\n });\n }\n});", "view": "Form" }, { @@ -212,12 +212,12 @@ "doctype": "Client Script", "dt": "Variant", "enabled": 1, - "modified": "2022-02-12 16:05:44.983283", + "modified": "2022-03-29 11:55:36.316666", "name": "Variant-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "cur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {\n return {\n\t\t\tquery:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter\",\n\t\t\t}\n\t}\n\nfrappe.ui.form.on('Variant', {\n\tvalidate: function(frm) {\n\t if (frm.doc.variant == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n if (regex.test(frm.doc.variant) === false){\n frappe.throw(__(\"Variant: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.variant) {\n if(frm.doc.variant.includes(\"'\")) {\n frappe.throw(__(\"Variant: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n }\n }\n\t}\n});", + "script": "cur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {\n return {\n\t\t\tquery:\"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter\",\n\t\t\t}\n\t}\n\nfrappe.ui.form.on('Variant', {\n\tvalidate: function(frm) {\n\t if (frm.doc.variant.length>50){\n\t\t\tfrappe.msgprint(\"Variant not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.variant.length == 1){\n\t\t\tfrappe.msgprint(\"Variant not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t if (frm.doc.variant == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n //var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\n \n if (regex.test(frm.doc.variant) === true){\n frappe.throw(__(\"Variant: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.variant) {\n if(frm.doc.variant.includes(\"'\")) {\n frappe.throw(__(\"Variant: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n }\n }\n\t}\n});", "view": "Form" }, { @@ -225,12 +225,12 @@ "doctype": "Client Script", "dt": "Fuel", "enabled": 1, - "modified": "2022-01-23 12:10:47.026167", + "modified": "2022-03-29 11:59:16.802104", "name": "Fuel-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "frappe.ui.form.on('Fuel', {\n\tvalidate: function(frm) {\n\t if (frm.doc.fuel == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n if (regex.test(frm.doc.fuel) === false){\n frappe.throw(__(\"Fuel: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.fuel) {\n if(frm.doc.fuel.includes(\"'\")) {\n frappe.throw(__(\"Fuel: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n }\n }\n }\n});", + "script": "frappe.ui.form.on('Fuel', {\n\tvalidate: function(frm) {\n\t\tif (frm.doc.fuel.length>50){\n\t\t\tfrappe.msgprint(\"Fuel not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.fuel.length == 1){\n\t\t\tfrappe.msgprint(\"Fuel not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t if (frm.doc.fuel == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n //var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\n \n if (regex.test(frm.doc.fuel) === true){\n frappe.throw(__(\"Fuel: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.fuel) {\n if(frm.doc.fuel.includes(\"'\")) {\n frappe.throw(__(\"Fuel: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n }\n }\n }\n});", "view": "Form" }, { @@ -238,12 +238,12 @@ "doctype": "Client Script", "dt": "Transmission", "enabled": 1, - "modified": "2022-01-23 12:11:26.918615", + "modified": "2022-03-29 12:06:46.352939", "name": "Transmission-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "frappe.ui.form.on('Transmission', {\n\tvalidate: function(frm) {\n\t if (frm.doc.transmission == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n if (regex.test(frm.doc.transmission) === false){\n frappe.throw(__(\"Transmission: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.transmission) {\n if(frm.doc.transmission.includes(\"'\")) {\n frappe.throw(__(\"Transmission: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\n frappe.validated = false;\n }\n }\n\t}\n});", + "script": "frappe.ui.form.on('Transmission', {\n\tvalidate: function(frm) {\n\t if (frm.doc.transmission.length>50){\n\t\t\tfrappe.msgprint(\"Transmission not allow more than 50 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.transmission.length == 1){\n\t\t\tfrappe.msgprint(\"Transmission not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t if (frm.doc.transmission == \".\"){\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\n\t frappe.validated = false;\n\t }\n // var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\n if (regex.test(frm.doc.transmission) === true){\n frappe.throw(__(\"Transmission: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n } else if(frm.doc.transmission) {\n if(frm.doc.transmission.includes(\"'\")) {\n frappe.throw(__(\"Transmission: Only letters, numbers and -, are allowed.\"));\n frappe.validated = false;\n }\n }\n\t}\n});", "view": "Form" }, { @@ -251,12 +251,12 @@ "doctype": "Client Script", "dt": "Drive", "enabled": 1, - "modified": "2022-01-23 12:12:07.576330", + "modified": "2022-03-29 12:02:44.040553", "name": "Drive-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "frappe.ui.form.on('Drive', {\r\n\tvalidate: function(frm) {\r\n\t if (frm.doc.drive == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n if (regex.test(frm.doc.drive) === false){\r\n frappe.throw(__(\"Drive: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n } else if(frm.doc.drive) {\r\n if(frm.doc.drive.includes(\"'\")) {\r\n frappe.throw(__(\"Drive: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n }\r\n\t}\r\n});", + "script": "frappe.ui.form.on('Drive', {\r\n\tvalidate: function(frm) {\r\n\t if (frm.doc.drive.length>50){\r\n\t\t\tfrappe.msgprint(\"Drive not allow more than 50 characters\")\r\n\t\t\tvalidated = false;\r\n\t\t}\r\n\t\tif (frm.doc.drive.length == 1){\r\n\t\t\tfrappe.msgprint(\"Drive not allow single character\")\r\n\t\t\tvalidated = false;\r\n\t\t}\r\n\t if (frm.doc.drive == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n //var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};':\"\\\\|.<>\\/?]+/;\r\n if (regex.test(frm.doc.drive) === true){\r\n frappe.throw(__(\"Variant: Only letters, numbers and -, are allowed.\"));\r\n frappe.validated = false;\r\n } else if(frm.doc.drive) {\r\n if(frm.doc.drive.includes(\"'\")) {\r\n frappe.throw(__(\"Variant: Only letters, numbers and -, are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n }\r\n\t}\r\n});", "view": "Form" }, { @@ -264,12 +264,12 @@ "doctype": "Client Script", "dt": "Systems", "enabled": 1, - "modified": "2022-01-23 12:14:37.113142", + "modified": "2022-03-31 15:42:02.503749", "name": "Systems-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "frappe.ui.form.on('Systems', {\r\n\tvalidate: function(frm) {\r\n\t if (frm.doc.system_name == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n if (regex.test(frm.doc.system_name) === false){\r\n frappe.throw(__(\"System Name: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n } else if(frm.doc.system_name) {\r\n if(frm.doc.system_name.includes(\"'\")) {\r\n frappe.throw(__(\"System Name: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n }\r\n\t}\r\n});", + "script": "frappe.ui.form.on('Systems', {\r\n \r\n\tvalidate: function(frm) {\r\n\t\tif (frm.doc.system_name.length == 1){\r\n\t\t\tfrappe.msgprint(\"System Name not allow single character\")\r\n\t\t\tvalidated = false;\r\n\t\t}\r\n\t if (frm.doc.system_name == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n //var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};:\"\\\\|.<>\\/?]+/;\r\n if (regex.test(frm.doc.system_name) === true){\r\n frappe.throw(__(\"system Name: Only letters, numbers and -,' are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n\t}\r\n});", "view": "Form" }, { @@ -277,12 +277,12 @@ "doctype": "Client Script", "dt": "Sub Systems", "enabled": 1, - "modified": "2022-01-23 12:15:10.150129", + "modified": "2022-03-29 12:09:23.356292", "name": "Sub Systems-Form", "parent": null, "parentfield": null, "parenttype": null, - "script": "frappe.ui.form.on('Sub Systems', {\r\n\tvalidate: function(frm) {\r\n\t if (frm.doc.sub_system_name == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n if (regex.test(frm.doc.sub_system_name) === false){\r\n frappe.throw(__(\"Sub System Name: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n } else if(frm.doc.sub_system_name) {\r\n if(frm.doc.sub_system_name.includes(\"'\")) {\r\n frappe.throw(__(\"Sub System Name: Only letters, numbers and &-()@/,.<>%_\u2022 are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n }\r\n\t}\r\n});", + "script": "frappe.ui.form.on('Sub Systems', {\r\n\tvalidate: function(frm) {\r\n\t\tif (frm.doc.sub_system_name.length == 1){\r\n\t\t\tfrappe.msgprint(\"Sub System Name not allow single character\")\r\n\t\t\tvalidated = false;\r\n\t\t}\r\n\t if (frm.doc.sub_system_name == \".\"){\r\n\t frappe.throw(__(\"Just a . is not prescribed!\"));\r\n\t frappe.validated = false;\r\n\t }\r\n // var regex = /^[A-Za-z0-9\\-&()@/,.<>_ ]*$/;\r\n var regex = /[!@#$%^&*()_+\\=\\[\\]{};:\"\\\\|.<>\\/?]+/;\r\n if (regex.test(frm.doc.sub_system_name) === false){\r\n frappe.throw(__(\"Sub System Name: Only letters, numbers and -,' are allowed.\"));\r\n frappe.validated = false;\r\n }\r\n\t}\r\n});", "view": "Form" }, { @@ -323,5 +323,18 @@ "parenttype": null, "script": "cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {\n return {query:\"smart_service.transactions.doctype.procedure.procedure.variant\",};\n};\n\nvar trigger = true;\nfrappe.ui.form.on('Kilometer Mapping', {\n before_load: function (frm){\n frm.get_field('config_kilometer').grid.cannot_add_rows = true;\n frm.get_field(\"config_kilometer\").grid.df.cannot_delete_rows = true;\n },\n onload: function(frm) {\n frm.get_field('config_kilometer').grid.cannot_add_rows = true;\n frm.get_field(\"config_kilometer\").grid.df.cannot_delete_rows = true;\n\n //*** allign idx while deleting rows\n //if(cur_frm.doc.config_kilometer){\n //for (var i =0;i {\n smrecords.sort(sortsm);\n $.each(smrecords, function(index, smrow){\n sub_system_set.push(smrow.sub_systems);\n });\n frm.set_df_property('sub_system_filter', 'options', sub_system_set);\n });\n frappe.db.get_list('Vehicle_SK', {\n fields: ['service_kilometers'],\n //filters: { parent: frm.doc.variant_mapping }\n filters: { parent: frm.doc.vehicle }\n }).then(kmrecord => {\n kmrecord.sort(sortkm);\n $.each(kmrecord, function(index, kmsrow){\n kilometer_set.push(kmsrow.service_kilometers);\n });\n frm.set_df_property('kilometer_filter', 'options', kilometer_set);\n });\n }\n },\n refresh: function(frm) {\n // frm.get_field('config_kilometer').grid.cannot_add_rows = true;\n // frm.get_field(\"config_kilometer\").grid.df.cannot_delete_rows = true;\n\t\tvar previous_kilometer = \"\";\n\t\t//console.log(frm.doc.sub_system_filter,frm.doc.kilometer_filter);\n\t\tif (frm.doc.sub_system_filter ==\"All\" && frm.doc.kilometer_filter ==\"All\"){\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n if (row.doc.kilometer == previous_kilometer){\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'color': '#EDEDED'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#FFFFFF'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #ebeef0'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'text-align': 'right'});\n }else{\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'color': '#000000'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#EDEDED'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #7b7c7c'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'text-align': 'right'});\n }\n previous_kilometer = row.doc.kilometer;\n let id = row.doc.idx;\n });\n\t\t} else {\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'color': '#000000'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'background-color': '#FFFFFF'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').css({'border-bottom': '1px Solid #ebeef0'});\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').find('div.col[data-fieldname=\"kilometer\"]').css({'text-align': 'right'});\n });\n\t\t}\n\t},\n\t\tvariant_mapping: function(frm,cdt,cdn) {\n\t\tif(frm.doc.variant_mapping === undefined) {return;}\n\t\t\t var filter = frm.doc.variant_mapping + \"-en-SM\";\n\t\t\t var sub_system_set = ['All'];\n\t\t\t var kilometer_set = ['All'];\n\t\t\t frappe.call({\n\t\t\t\t\"method\": \"smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_subsystem\",\n\t\t\t\t\"args\": {\n\t\t\t\t\t\"doc\": frm.doc.variant_mapping,\n\t\t\t\t},\n\t\t\t\tcallback: function(r) {\n\t\t\t\t\t$.each(r.message, function(index, smrow){\n\t\t\t\t\t\tr.message.sort(sortsm);\n\t\t\t\t\t\tsub_system_set.push(smrow.sub_systems);\n\t\t\t\t\t});\n\t\t\t\t\tfrm.set_df_property('sub_system_filter', 'options', [...new Set(sub_system_set)]);\n\t\t\t \n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\tfrappe.db.get_list('Vehicle_SK', {\n\t\t\t\t\t fields: ['service_kilometers'],\n\t\t\t\t\t filters: { parent: frm.doc.vehicle }\n\t\t\t\t }).then(kmrecord => {\n\t\t\t\t\t kmrecord.sort(sortkm);\n\t\t\t\t\t $.each(kmrecord, function(index, kmsrow){\n\t\t\t\t\t\t kilometer_set.push(kmsrow.service_kilometers);\n\t\t\t\t\t });\n\t\t\t\t\t frm.set_df_property('kilometer_filter', 'options', kilometer_set);\n\t \n\t\t\t\t\t $.each(kmrecord, function(index, kmrow){\n\t \n\t\t\t frappe.call({\n\t\t\t\t\t \"method\": \"smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system\",\n\t\t\t\t\t \"args\": {\n\t\t\t\t\t\t \"doc\": frm.doc.variant_mapping,\n\t\t\t\t\t },\n\t\t\t\t\t callback: function(r) {\n\t\t\t\t\t\t\t $.each(r.message, function(index, smrow){\n\t\t\t\t\t\t\t var child;\n\t\t\t\t\t\t\t if (smrow.mat !== null){\n\t\t\t\t\t\t\t\t var child = cur_frm.add_child(\"config_kilometer\");\n\t\t\t\t\t\t\t\t child.sub_systems = smrow.sub_systems;\n\t\t\t\t\t\t\t\t child.mat = smrow.mat;\n\t\t\t\t\t\t\t\t child.kilometer = kmrow.service_kilometers;\n\t\t\t\t\t\t\t\t cur_frm.refresh_field('config_kilometer');\n \t\t cur_frm.refresh_fields();\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t });\n\t \t\t\t\t\t}\n\t \t\t\t\t\t})\n\t\t\t\t\t }); \n\t\t\t\t });\n\t\t },\n\n /*variant_mapping: function(frm) {\n if(frm.doc.variant_mapping === undefined) {return;}\n var filter = frm.doc.variant_mapping + \"-en-SM\";\n var sub_system_set = ['All'];\n var kilometer_set = ['All'];\n frappe.db.get_list('System Mapping_Sub System', {\n fields: ['sub_systems', 'mat','idx'],\n filters: { \n parent: filter,\n \"mat\": [\"!=\",'']\n }\n }).then(smrecords => {\n smrecords.sort(sortsm);\n $.each(smrecords, function(index, smrow){\n sub_system_set.push(smrow.sub_systems);\n });\n frm.set_df_property('sub_system_filter', 'options', sub_system_set);\n \n frappe.db.get_list('Vehicle_SK', {\n fields: ['service_kilometers'],\n filters: { parent: frm.doc.vehicle }\n }).then(kmrecord => {\n kmrecord.sort(sortkm);\n $.each(kmrecord, function(index, kmsrow){\n kilometer_set.push(kmsrow.service_kilometers);\n });\n frm.set_df_property('kilometer_filter', 'options', kilometer_set);\n $.each(kmrecord, function(index, kmrow){\n $.each(smrecords, function(index, smrow){\n if (smrow.mat !== null){\n var child = cur_frm.add_child(\"config_kilometer\");\n child.sub_systems = smrow.sub_systems;\n child.mat = smrow.mat;\n child.kilometer = kmrow.service_kilometers;\n }\n });\n frm.refresh();\n }); \n });\n });\n },*/\n kilometer_filter: function(frm) {\n if (!trigger){ trigger = true; return;}\n if (frm.doc.sub_system_filter !=\"All\"){trigger=false;frm.set_value(\"sub_system_filter\",\"All\");}\n if (frm.doc.kilometer_filter ==\"All\"){\n frm.get_field('config_kilometer').grid.static_rows = false;\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('config_kilometer').grid.static_rows = false;\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n if (row.doc.kilometer != frm.doc.kilometer_filter){\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n } else {\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }\n });\n }\n frm.refresh();\n },\n sub_system_filter: function(frm) {\n if (!trigger){ trigger = true; return;}\n if (frm.doc.kilometer_filter !=\"All\"){trigger=false;frm.set_value(\"kilometer_filter\",\"All\");}\n \n if (frm.doc.sub_system_filter ==\"All\"){\n frm.get_field('config_kilometer').grid.static_rows = false;\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n });\n } else {\n frm.get_field('config_kilometer').grid.static_rows = true;\n frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {\n if (row.doc.sub_systems != frm.doc.sub_system_filter){\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').hide();\n } else {\n $(\"div[data-fieldname=config_kilometer]\").find('div.grid-row[data-idx=\"'+ row.doc.idx + '\"]').show();\n }\n });\n }\n frm.refresh();\n },\n sort_by_kilometer: function(frm) {\n var idx = 1;\n frm.doc.config_kilometer.sort(function(a,b){\n if (parseInt(a.kilometer) < parseInt(b.kilometer)){ return -1 }\n else if ( parseInt(a.kilometer) > parseInt(b.kilometer)){ return 1 }\n return 1;\n });\n \n frm.doc.config_kilometer.map(function(item){\n item.idx = idx++;\n });\n if (frm.doc.temp_field == \"Set\") {frm.set_value(\"temp_field\",\"Not Set\");} else {frm.set_value(\"temp_field\",\"Set\");}\n refresh_field(\"config_kilometer\");\n }\n});\n\nfrappe.ui.form.on('Kilometer Mapping_Items', {\n config_kilometer_move: function(frm) {\n frm.refresh();\n }\n});\n\nfunction sortkm(a, b) {\n if (parseInt(a.service_kilometers) < parseInt(b.service_kilometers)){return -1;}\n if (parseInt(a.service_kilometers) > parseInt(b.service_kilometers)){return 1;}\n return 0;\n}\n\nfunction sortsm(a, b) {\n if (a.sub_systems < b.sub_systems){return -1;}\n if (a.sub_systems > b.sub_systems){return 1;}\n return 0;\n}", "view": "Form" + }, + { + "docstatus": 0, + "doctype": "Client Script", + "dt": "Translation", + "enabled": 1, + "modified": "2022-03-28 13:12:31.825466", + "name": "Translation-Form", + "parent": null, + "parentfield": null, + "parenttype": null, + "script": "frappe.ui.form.on('Translation', {\n\tvalidate(frm) {\n\t\tif (frm.doc.source_text.length>140){\n\t\t\tfrappe.msgprint(\"Source Text not allow more than 140 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.source_text.length == 1){\n\t\t\tfrappe.msgprint(\"Source Text not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.translated_text.length>140){\n\t\t\tfrappe.msgprint(\"Translated Text not allow more than 140 characters\")\n\t\t\tvalidated = false;\n\t\t}\n\t\tif (frm.doc.translated_text.length == 1){\n\t\t\tfrappe.msgprint(\"Translated Text not allow single character\")\n\t\t\tvalidated = false;\n\t\t}\n\t}\n})", + "view": "Form" } ] \ No newline at end of file diff --git a/smart_service/fixtures/workflow_state.json b/smart_service/fixtures/workflow_state.json index 8321a9d..6211ad3 100644 --- a/smart_service/fixtures/workflow_state.json +++ b/smart_service/fixtures/workflow_state.json @@ -123,12 +123,12 @@ "docstatus": 0, "doctype": "Workflow State", "icon": "", - "modified": "2021-11-26 15:26:56.857786", + "modified": "2022-03-28 15:50:00.411032", "name": "Publish Ready", "parent": null, "parentfield": null, "parenttype": null, - "style": "Info", + "style": "Success", "workflow_state_name": "Publish Ready" } ] \ No newline at end of file diff --git a/smart_service/masters/doctype/drive/drive.json b/smart_service/masters/doctype/drive/drive.json index 36cea07..e95d128 100644 --- a/smart_service/masters/doctype/drive/drive.json +++ b/smart_service/masters/doctype/drive/drive.json @@ -21,7 +21,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Drive", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -42,7 +43,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-18 11:48:00.194884", + "modified": "2022-03-28 16:16:40.291574", "modified_by": "Administrator", "module": "Masters", "name": "Drive", diff --git a/smart_service/masters/doctype/fuel/fuel.json b/smart_service/masters/doctype/fuel/fuel.json index 37a04df..9619dc6 100644 --- a/smart_service/masters/doctype/fuel/fuel.json +++ b/smart_service/masters/doctype/fuel/fuel.json @@ -22,7 +22,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Fuel", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -43,7 +44,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-17 19:07:08.832628", + "modified": "2022-03-28 16:16:24.261317", "modified_by": "Administrator", "module": "Masters", "name": "Fuel", diff --git a/smart_service/masters/doctype/service_kilometers/service_kilometers.json b/smart_service/masters/doctype/service_kilometers/service_kilometers.json index b0faa27..9a593df 100644 --- a/smart_service/masters/doctype/service_kilometers/service_kilometers.json +++ b/smart_service/masters/doctype/service_kilometers/service_kilometers.json @@ -9,6 +9,7 @@ "engine": "InnoDB", "field_order": [ "kilometer", + "km_name", "active_status", "myid" ], @@ -21,7 +22,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Kilometer", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -38,11 +40,17 @@ "in_standard_filter": 1, "label": "myID", "set_only_once": 1 + }, + { + "fieldname": "km_name", + "fieldtype": "Data", + "label": "Kilometer", + "read_only": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-11 12:33:08.426297", + "modified": "2022-03-31 15:33:48.468849", "modified_by": "Administrator", "module": "Masters", "name": "Service Kilometers", diff --git a/smart_service/masters/doctype/sub_systems/sub_systems.json b/smart_service/masters/doctype/sub_systems/sub_systems.json index 8d8eca0..3be52e8 100644 --- a/smart_service/masters/doctype/sub_systems/sub_systems.json +++ b/smart_service/masters/doctype/sub_systems/sub_systems.json @@ -21,7 +21,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Sub System Name", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -42,7 +43,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-11 12:40:29.687934", + "modified": "2022-03-28 16:18:17.899428", "modified_by": "Administrator", "module": "Masters", "name": "Sub Systems", diff --git a/smart_service/masters/doctype/systems/systems.json b/smart_service/masters/doctype/systems/systems.json index c39da10..b7001d8 100644 --- a/smart_service/masters/doctype/systems/systems.json +++ b/smart_service/masters/doctype/systems/systems.json @@ -24,7 +24,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "System Name", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -58,7 +59,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-11 12:40:21.114791", + "modified": "2022-03-31 14:49:04.303134", "modified_by": "Administrator", "module": "Masters", "name": "Systems", diff --git a/smart_service/masters/doctype/transmission/transmission.json b/smart_service/masters/doctype/transmission/transmission.json index 4c3daf5..f844342 100644 --- a/smart_service/masters/doctype/transmission/transmission.json +++ b/smart_service/masters/doctype/transmission/transmission.json @@ -21,7 +21,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Transmission", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -42,7 +43,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-11 12:34:18.571139", + "modified": "2022-03-28 16:17:00.779363", "modified_by": "Administrator", "module": "Masters", "name": "Transmission", diff --git a/smart_service/masters/doctype/variant/variant.json b/smart_service/masters/doctype/variant/variant.json index aca4c3c..7906f24 100644 --- a/smart_service/masters/doctype/variant/variant.json +++ b/smart_service/masters/doctype/variant/variant.json @@ -39,7 +39,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Variant", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fetch_from": "vehicle.myid", @@ -101,7 +102,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-03-01 15:06:32.534454", + "modified": "2022-03-31 16:09:20.683902", "modified_by": "Administrator", "module": "Masters", "name": "Variant", diff --git a/smart_service/masters/doctype/vehicle/vehicle.json b/smart_service/masters/doctype/vehicle/vehicle.json index c58dede..34e0184 100644 --- a/smart_service/masters/doctype/vehicle/vehicle.json +++ b/smart_service/masters/doctype/vehicle/vehicle.json @@ -54,7 +54,8 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Vehicle", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "preview", @@ -118,7 +119,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-22 18:11:19.333346", + "modified": "2022-03-28 16:15:54.574158", "modified_by": "Administrator", "module": "Masters", "name": "Vehicle", diff --git a/smart_service/masters/doctype/vehicle/vehicle.py b/smart_service/masters/doctype/vehicle/vehicle.py index 3702537..d2668fd 100644 --- a/smart_service/masters/doctype/vehicle/vehicle.py +++ b/smart_service/masters/doctype/vehicle/vehicle.py @@ -3,10 +3,14 @@ import frappe from frappe.model.document import Document +from PIL import Image +from frappe.utils import cstr +import os class Vehicle(Document): - def validate(self): - pass + def validate(self): + pass + @frappe.whitelist() def update_km_mapping(doc,vehicle,type,skm_initial): ###Insert kilometer in kilometer mapping for added new kilometer @@ -47,3 +51,22 @@ def vehicle_segment(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" select name FROM {0}.`tabVehicle Segment` where (name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) + +@frappe.whitelist() +def image_size(image,doc): + current_db_name = frappe.conf.get("db_name") + site_name = cstr(frappe.local.site) + file_path = "/home/ubuntu/frappe-bench/sites/"+site_name +"/public" + image + size = os.path.getsize(file_path) + img = Image.open(file_path) + width = img.width + height = img.height + if(width > 510 and height > 510): + frappe.db.sql("""delete from `tabFile` where file_url = %s""",image) + frappe.db.commit() + return image + + if(size > 10485760 ): + frappe.db.sql("""delete from `tabFile` where file_url = %s""",image) + frappe.db.commit() + return size diff --git a/smart_service/masters/doctype/vehicle_segment/vehicle_segment.json b/smart_service/masters/doctype/vehicle_segment/vehicle_segment.json index c30954d..54d9249 100644 --- a/smart_service/masters/doctype/vehicle_segment/vehicle_segment.json +++ b/smart_service/masters/doctype/vehicle_segment/vehicle_segment.json @@ -22,7 +22,8 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Vehicle Segment", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fieldname": "active_status", @@ -53,7 +54,7 @@ "icon": "fa fa-car-alt", "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-11 10:34:09.580371", + "modified": "2022-03-31 14:49:18.442598", "modified_by": "Administrator", "module": "Masters", "name": "Vehicle Segment", diff --git a/smart_service/public/css/smart_service.css b/smart_service/public/css/smart_service.css index 1f59e52..b2e8cf9 100644 --- a/smart_service/public/css/smart_service.css +++ b/smart_service/public/css/smart_service.css @@ -110,6 +110,6 @@ h4{ } body{ - font-family: Inter !important; + font-family: inherit !important; /* font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji; */ } diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index 8ff2672..c1c3cc0 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -1,7 +1,7 @@ { "actions": [], "allow_rename": 1, - "autoname": "format: {vehicle}-{language} {version}", + "autoname": "format: {vehicle}-{language} -{creation}", "creation": "2021-11-01 12:28:45.623316", "doctype": "DocType", "editable_grid": 1, @@ -264,7 +264,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2022-03-15 16:00:46.484240", + "modified": "2022-03-28 15:53:18.617801", "modified_by": "Administrator", "module": "Transactions", "name": "Publish", diff --git a/smart_service/transactions/report/audit_report/audit_report.py b/smart_service/transactions/report/audit_report/audit_report.py index 76a6f4e..df5d5d4 100644 --- a/smart_service/transactions/report/audit_report/audit_report.py +++ b/smart_service/transactions/report/audit_report/audit_report.py @@ -59,11 +59,8 @@ def modifyData(dataInput, filterParent): list1 = [] inputData = modifyChildData(dataInput, indent=6, header=0) parentAppend = addParent(filterParent, indent=0, header=1) - sMap, sSize = getParentMap(inputData, 'systems') - systemSize = statusLengthAppend(sSize,'System') - parentAppend[0]['active_status'] = systemSize for pa in parentAppend: @@ -80,7 +77,8 @@ def modifyData(dataInput, filterParent): sys_assets = frappe.db.sql('''SELECT system_asset as description, {0} FROM {1}.`tabSystem Mapping_System Assets` - where parent like '{2}' and systems = '{3}' and language= 'en' order by idx; '''.format(activeStatusQuerycase,current_db_name,list1[0]['procedure_name']+"%",sMapAppend[0]['procedure_name']),as_dict=True) + where parent like '{2}' and systems = '{3}' and language= 'en' order by idx; '''.format(activeStatusQuerycase,current_db_name,list1[0]['procedure_name']+"%", + sMapAppend[0]['procedure_name']),as_dict=True) for sa in sys_assets: list1.append(sa.update({'procedure_name':"System Asset",'indent':2,'header':'','type':'Asset'})) @@ -89,6 +87,7 @@ def modifyData(dataInput, filterParent): val = j['procedure_name'] proc = j['procedure'] procMap, procSize = getParentMap(ssMap[val], 'procedure_name') + print(procMap) procValuesDic = appendToDic3( procMap, procSize, j, indent=3, header=0, procedure=proc) @@ -97,24 +96,22 @@ def modifyData(dataInput, filterParent): list1.append(j) for d in procValuesDic: - list1.append(d) + list1.append(d) for pm in procMap: list1.append({'procedure_name': pm, 'indent': 4,'header':0,'active_status':'','modified':''}) - - step_list,steps_size = getParentMap(procMap[pm], 'step_name') - + step_list,steps_size = getParentMap(procMap[pm], 'step_name') for sl in step_list: list1.append({'procedure_name': sl, 'indent': 5,'header':0,'active_status':'','modified':''}) - for ss in step_list[sl]: ss.update({'procedure_name':ss['content_type']}) list1.append(ss) - appendData = addDuplicateData(list1) appendData = removeDuplicateAndHeader(appendData) return appendData +def print(sts): + frappe.msgprint(str(sts)) def appendToDic1(mapData, indent, header): mapDataAppend = [] @@ -186,7 +183,6 @@ def appendToDic3(mapData, procSize, j, indent, header, procedure): '''select count(step_name) as count, modified as {1} from {0}.`tabProcedure_Details` where parent= '{2}' group by(procedure_name) order by idx;'''.format( current_db_name, colmodified, procedure), as_list=True) - for l in other_step_count: list2.append(l) list1.append(list2) @@ -197,11 +193,12 @@ def appendToDic3(mapData, procSize, j, indent, header, procedure): dateList.append(str(k['modified'])) dateList.sort(key=lambda date: datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")) - if procSize[i] == 1: - stepLength = str(procSize[i]) + " Step" - else: - stepLength = str(procSize[i]) + " Steps" + # if procSize[i] == 1: + # stepLength = str(procSize[i]) + " Step" + # else: + # stepLength = str(procSize[i]) + " Steps" + stepLength = "TEsting" procDict = { 'systems': mapData[u][0]['systems'], 'sub_systems': mapData[u][0]['sub_systems'],