diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py
index 639908f..e775979 100644
--- a/smart_service/apis/master_api.py
+++ b/smart_service/apis/master_api.py
@@ -8,7 +8,6 @@ from frappe.utils import cstr
current_db_name = frappe.conf.get("db_name")
-
@frappe.whitelist()
def masters(args, LSD):
try:
@@ -16,7 +15,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Vehicle",
fields=[
- "vehicle",
+ "name as vehicle",
"vehicle_segment",
"vehicle_segment_id",
"image",
@@ -38,7 +37,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Variant",
fields=[
- "vehicle",
+ "name as vehicle",
"vehicle_segment",
"variant",
"myid as variant_id",
@@ -58,11 +57,11 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Vehicle Segment",
fields=[
- "vehicle_segment",
+ "name as vehicle_segment",
"active_status",
"display_order",
"myid as vehicle_segment_id",
- "modified",
+ "modified"
],
filters={"modified": [">", LSD]},
)
@@ -76,7 +75,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Transmission",
fields=[
- "transmission",
+ "name as transmission",
"active_status",
"myid as transmission_id",
"modified",
@@ -92,7 +91,7 @@ def masters(args, LSD):
elif args == "drive":
api = frappe.db.get_list(
"Drive",
- fields=["drive", "active_status", "myid as drive_id", "modified"],
+ fields=["name as drive", "active_status", "myid as drive_id", "modified"],
filters={"modified": [">", LSD]},
)
for i in api:
@@ -104,7 +103,7 @@ def masters(args, LSD):
elif args == "fuel":
api = frappe.db.get_list(
"Fuel",
- fields=["fuel", "active_status", "myid as fuel_id", "modified"],
+ fields=["name as fuel", "active_status", "myid as fuel_id", "modified"],
filters={"modified": [">", LSD]},
)
for i in api:
@@ -117,7 +116,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Systems",
fields=[
- "system_name",
+ "name as system_name",
"active_status",
"icon_file",
"myid as system_id",
@@ -135,7 +134,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Sub Systems",
fields=[
- "sub_system_name",
+ "name as sub_system_name",
"active_status",
"myid as sub_system_id",
"modified",
@@ -152,7 +151,7 @@ def masters(args, LSD):
api = frappe.db.get_list(
"Service Kilometers",
fields=[
- "kilometer",
+ "name as kilometer",
"active_status",
"myid as service_kilometers_id",
"modified",
@@ -232,6 +231,12 @@ def masters(args, LSD):
return api
+# @frappe.whitelist()
+# def testFile():
+# mime = magic.Magic(mime=True)
+# return mime.from_file("/home/ubuntu/frappe-bench/sites/guidedsmartservice.com/public/files/anydesk.xlsx")
+
+
def labels_json():
labels_lst = frappe.db.sql(
"""SELECT `tabApp Labels`.name as name,`tabApp Labels`.page_name as menu_type, `tabApp Labels`.english_label as element, `tabApp Labels`.language as lang, `tabApp Labels`.label as label, `tabApp Labels`.parent_app_labels as parent FROM {0}.`tabApp Labels` order by name asc""".format(
diff --git a/smart_service/fixtures/client_script.json b/smart_service/fixtures/client_script.json
index c18fbf9..406294c 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-31 21:28:50.644218",
+ "modified": "2022-04-01 17:55:07.595180",
"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 + \"HTML Tag | \" + \"How to tag <...>\" + \" | Result |
\" ;\n html = html + \"Bold | \" + \"<b>Using a 10 mm socket.</b>\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"Break | \" + \"Using a <br>10 mm socket.\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"Italic | \" + \"<i>Using a 10 mm socket.</i>\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"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.
|
\" ;\n html = html + \"Ordered List | \" + \"<ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol>\" + \" | - Using a 10 mm socket.
- the steering fluid line.
|
\" ;\n html = html + \"
\";\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 \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 + \"\" + row.parent + \" | \" +\"\" + row.procedure + \" |
\";\n });\n html = html + \"
\";\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 + \"- \" + array_row + \"
\";\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 + \"HTML Tag | \" + \"How to tag <...>\" + \" | Result |
\" ;\n html = html + \"Bold | \" + \"<b>Using a 10 mm socket.</b>\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"Break | \" + \"Using a <br>10 mm socket.\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"Italic | \" + \"<i>Using a 10 mm socket.</i>\" + \" | Using a 10 mm socket. |
\" ;\n html = html + \"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.
|
\" ;\n html = html + \"Ordered List | \" + \"<ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol>\" + \" | - Using a 10 mm socket.
- the steering fluid line.
|
\" ;\n html = html + \"
\";\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 \n var regex = /[@#$%^*+\\\\[\\]{}`~:\\\\|\\?]+/;\n for (var i=0;iContent: Only letters, numbers and - ,'<>_()!=/; are allowed.\"));\n frappe.validated = false;\n }\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 + \"\" + row.parent + \" | \" +\"\" + row.procedure + \" |
\";\n });\n html = html + \"
\";\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 + \"- \" + array_row + \"
\";\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"
},
{
@@ -121,12 +121,12 @@
"doctype": "Client Script",
"dt": "Vehicle",
"enabled": 1,
- "modified": "2022-03-31 21:30:20.162466",
+ "modified": "2022-04-01 17:49:19.910831",
"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 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}",
+ "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 2048*1080.'),\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"
},
{
@@ -264,12 +264,12 @@
"doctype": "Client Script",
"dt": "Systems",
"enabled": 1,
- "modified": "2022-03-31 21:29:58.745214",
+ "modified": "2022-04-01 17:49:44.957537",
"name": "Systems-Form",
"parent": null,
"parentfield": null,
"parenttype": null,
- "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});",
+ "script": "frappe.ui.form.on('Systems', {\r\n \r\n\tvalidate: function(frm) {\r\n\t var file = frm.doc.icon_file;\r\n\t\tif (frm.doc.icon_file) {\r\n\t\t\tfrappe.call({\r\n\t\t\t\tmethod: \"smart_service.masters.doctype.systems.systems.image_size\",\r\n\t\t\t\targs: {\r\n\t\t\t\t\t\"image\": frm.doc.icon_file,\r\n\t\t\t\t\t\"doc\": frm.doc.name\r\n\t\t\t\t},\r\n\t\t\t\tcallback: function (r) {\r\n\t\t\t\t\tconsole.log(\"return callback\" + r.message)\r\n\t\t\t\tif(r.message){\r\n\t\t\t\t\tif(r.message == frm.doc.icon_file){\r\n\t\t\t\t\t\tfrm.doc.icon_file = '';\r\n\t\t\t\t\t\tcur_frm.refresh_field('icon_file');\r\n\t\t\t\t\t\tfrappe.show_alert({\r\n\t\t\t\t\t\t\tmessage: __('Max Dimesions are 2048*1080.'),\r\n\t\t\t\t\t\t\tindicator: 'yellow'\r\n\t\t\t\t\t\t}, 10);\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\tfrm.doc.icon_file = '';\r\n\t\t\t\t\t\tcur_frm.refresh_field('icon_file');\r\n\t\t\t\t\t\tfrappe.show_alert({\r\n\t\t\t\t\t\t\tmessage: __('Max Image Size is 10MB.'),\r\n\t\t\t\t\t\t\tindicator: 'yellow'\r\n\t\t\t\t\t\t}, 10);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t}\r\n\t \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"
},
{
diff --git a/smart_service/masters/doctype/systems/systems.json b/smart_service/masters/doctype/systems/systems.json
index b7001d8..e691b82 100644
--- a/smart_service/masters/doctype/systems/systems.json
+++ b/smart_service/masters/doctype/systems/systems.json
@@ -42,6 +42,7 @@
"label": "Icon File"
},
{
+ "depends_on": "eval:doc.icon_file",
"fieldname": "icon_preview",
"fieldtype": "Image",
"label": "Icon Preview",
@@ -59,7 +60,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2022-03-31 14:49:04.303134",
+ "modified": "2022-04-01 13:01:57.103930",
"modified_by": "Administrator",
"module": "Masters",
"name": "Systems",
diff --git a/smart_service/masters/doctype/systems/systems.py b/smart_service/masters/doctype/systems/systems.py
index e576cf0..95d1e0d 100644
--- a/smart_service/masters/doctype/systems/systems.py
+++ b/smart_service/masters/doctype/systems/systems.py
@@ -1,8 +1,54 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
-# import frappe
+import frappe
from frappe.model.document import Document
+from PIL import Image
+from frappe.utils import cstr
+import os
class Systems(Document):
- pass
+ def validate(self):
+ pass
+@frappe.whitelist()
+def image_size(image,doc):
+ current_db_name = frappe.conf.get("db_name")
+ doc = frappe.get_doc("Systems",doc)
+ 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()
+ a = frappe.db.sql("""select name from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image))
+ frappe.msgprint(str(a))
+ return image
+ if(size > 10485760 ):
+ frappe.db.sql("""delete from `tabFile` where file_url = %s""",image)
+ frappe.db.commit()
+ return size
+
+@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 size > 10485760000:
+ # frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image))
+ # frappe.db.commit()
+ # return size
+
+ if (width > 2048 or height > 1080):
+ frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image))
+ frappe.db.commit()
+ return image
+
+
\ No newline at end of file
diff --git a/smart_service/masters/doctype/vehicle/vehicle.json b/smart_service/masters/doctype/vehicle/vehicle.json
index 34e0184..03f0065 100644
--- a/smart_service/masters/doctype/vehicle/vehicle.json
+++ b/smart_service/masters/doctype/vehicle/vehicle.json
@@ -58,6 +58,7 @@
"set_only_once": 1
},
{
+ "depends_on": "eval:doc.image",
"fieldname": "preview",
"fieldtype": "Image",
"label": "Preview",
@@ -119,7 +120,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2022-03-28 16:15:54.574158",
+ "modified": "2022-04-01 17:41:13.606316",
"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 d2668fd..f6df794 100644
--- a/smart_service/masters/doctype/vehicle/vehicle.py
+++ b/smart_service/masters/doctype/vehicle/vehicle.py
@@ -61,12 +61,15 @@ def image_size(image,doc):
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
+
+ # if size > 1048576 :
+ # frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image))
+ # frappe.db.commit()
+ # return size
+
+ if width > 2048 and height > 1080:
+ frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image))
+ frappe.db.commit()
+ return image
+
+
diff --git a/smart_service/transactions/report/audit_report/audit_report.py b/smart_service/transactions/report/audit_report/audit_report.py
index df5d5d4..4a461ae 100644
--- a/smart_service/transactions/report/audit_report/audit_report.py
+++ b/smart_service/transactions/report/audit_report/audit_report.py
@@ -40,7 +40,6 @@ def getData(filters):
and substring(`tabProcedure_Details`.parent, -2) = 'en'
order by `tabSystem Mapping_Sub System`.systems ,`tabSystem Mapping_Sub System`.sub_systems,`procedure`,idx;
""".format(current_db_name, fil), as_dict=True)
-
filterData = filters.variant_mapping
if filterData != None and len(data) > 0:
data = modifyData(data, filterData)
@@ -57,7 +56,7 @@ def statusLengthAppend(dicVal,parameter):
def modifyData(dataInput, filterParent):
list1 = []
- inputData = modifyChildData(dataInput, indent=6, header=0)
+ inputData = modifyChildData(dataInput, indent=5, header=0)
parentAppend = addParent(filterParent, indent=0, header=1)
sMap, sSize = getParentMap(inputData, 'systems')
systemSize = statusLengthAppend(sSize,'System')
@@ -87,21 +86,19 @@ 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)
procLength = statusLengthAppend(procValuesDic,'Procedure')
j['active_status'] = j['active_status'] + ' / ' + procLength
list1.append(j)
-
- for d in procValuesDic:
- list1.append(d)
- for pm in procMap:
- list1.append({'procedure_name': pm, 'indent': 4,'header':0,'active_status':'','modified':''})
+
+ for pm in procMap:
step_list,steps_size = getParentMap(procMap[pm], 'step_name')
+ stepLength = statusLengthAppend(steps_size,'Step')
+ list1.append({'procedure_name': pm, 'indent': 3,'header':0,'active_status':stepLength,'modified':''})
for sl in step_list:
- list1.append({'procedure_name': sl, 'indent': 5,'header':0,'active_status':'','modified':''})
+ list1.append({'procedure_name': sl, 'indent': 4,'header':0,'active_status':'','modified':''})
for ss in step_list[sl]:
ss.update({'procedure_name':ss['content_type']})
list1.append(ss)
@@ -110,8 +107,6 @@ def modifyData(dataInput, filterParent):
appendData = removeDuplicateAndHeader(appendData)
return appendData
-def print(sts):
- frappe.msgprint(str(sts))
def appendToDic1(mapData, indent, header):
mapDataAppend = []
@@ -193,12 +188,11 @@ 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 len(mapData[u]) ==1:
+ stepLength = str(len(mapData[u])) + " Step"
+ else:
+ stepLength = str(len(mapData[u])) + " Steps"
- stepLength = "TEsting"
procDict = {
'systems': mapData[u][0]['systems'],
'sub_systems': mapData[u][0]['sub_systems'],