diff --git a/smart_service/apis/update_validation.py b/smart_service/apis/update_validation.py index ea9ffd2..ec7d494 100644 --- a/smart_service/apis/update_validation.py +++ b/smart_service/apis/update_validation.py @@ -9,6 +9,19 @@ current_db_name = frappe.conf.get("db_name") site_name = cstr(frappe.local.site) base_url = os.path.expanduser("~") + "/frappe-bench/sites/"+site_name+"/public" +def get_parent_map(input_list, parameter): + parentChildMap = {} + for b in input_list: + parentChildMap.setdefault(b[parameter] or None, []).append(b) + list1 = [] + for p in parentChildMap: + da = {"procedure_name": p, 'steps': parentChildMap[p]} + list1.append(da) + for i in parentChildMap[p]: + del i['procedure_name'] + del i['idx'] + + return list1 @frappe.whitelist() def check_all_vehicle_updates(vehicle_list): @@ -25,6 +38,7 @@ def check_all_vehicle_updates(vehicle_list): if publish_type[0][0] != None: for v in vehicle_data: v_id = v['Vehicle'] + current_version = float(v['CurrentVersion']) data1 = frappe.db.sql('''SELECT name,max(version) as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='{}' and vehicle_status='Active' order by version ASC;'''.format(current_db_name, v_id,lang, publish_type[0][0]),as_dict=True) @@ -57,20 +71,6 @@ def check_all_vehicle_updates(vehicle_list): except: return {"isSuccessful": False} -def get_parent_map(input_list, parameter): - parentChildMap = {} - for b in input_list: - parentChildMap.setdefault(b[parameter] or None, []).append(b) - list1 = [] - for p in parentChildMap: - da = {"procedure_name": p, 'steps': parentChildMap[p]} - list1.append(da) - for i in parentChildMap[p]: - del i['procedure_name'] - del i['idx'] - - return list1 - @frappe.whitelist() def check_vehicle_update(vehicle_list): diff --git a/smart_service/fixtures/client_script.json b/smart_service/fixtures/client_script.json index 9a1db52..022ea52 100644 --- a/smart_service/fixtures/client_script.json +++ b/smart_service/fixtures/client_script.json @@ -82,12 +82,12 @@ "doctype": "Client Script", "dt": "Publish", "enabled": 1, - "modified": "2022-03-15 16:01:15.267683", + "modified": "2022-03-21 14:39:16.544555", "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 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.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 child.category = row.category;\n child.language = row.language;\n child.attach_file = row.attach_file;\n child.active_status = row.active_status;\n /*if (row.procedure) {\n frappe.db.get_doc('Procedure', row.procedure)\n .then(doc => {\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 refresh_field(\"system_mapping\");\n });\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 } 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 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});", "view": "Form" }, { @@ -95,12 +95,12 @@ "doctype": "Client Script", "dt": "Kilometer Mapping", "enabled": 1, - "modified": "2022-02-17 12:31:50.463680", + "modified": "2022-03-18 13:47:59.029016", "name": "Kilometer Mapping-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\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 //*** 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\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\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}", + "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\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\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" }, { diff --git a/smart_service/fixtures/notification.json b/smart_service/fixtures/notification.json index 7beceb7..ad45f01 100644 --- a/smart_service/fixtures/notification.json +++ b/smart_service/fixtures/notification.json @@ -56,7 +56,7 @@ "is_standard": 0, "message": "

Hello {{ doc.full_name }},          

\r\n

Welcome to Guided Smart Service CMS !!!         

\r\n

 

\r\n

A new account has been created on {{ doc.creation }}.

\r\n

Your login id is: {{ doc.username }}

\r\n

Role: CMS User        

\r\n
Please use Mahindra credentials for accessing your account.
\r\n
Click on the link below to access the CMS Portal.
\r\n

http://192.168.1.58:81/        

\r\n
Thanks,
\r\n
Smart Service CMS Admin
", "method": null, - "modified": "2022-03-08 10:58:11.969504", + "modified": "2022-03-21 13:39:02.434667", "module": null, "name": "Mahindra User Enabled", "parent": null, @@ -99,7 +99,7 @@ "is_standard": 0, "message": "

Hello Admin,          

\r\n

 

\r\n

The account with the below details has been successfully enabled.         

\r\n

Login ID: {{ doc.username }}

\r\n

Email ID: {{ doc.name }}

\r\n

 

\r\n

The user can now access the account.

\r\n

A welcome mail has been sent to the user as well.        

\r\n
Thanks,
\r\n
Smart Service CMS Admin
", "method": null, - "modified": "2022-03-08 11:08:44.723490", + "modified": "2022-03-21 13:38:54.315513", "module": null, "name": "User Enabled", "parent": null, @@ -115,7 +115,7 @@ "parent": "User Enabled", "parentfield": "recipients", "parenttype": "Notification", - "receiver_by_document_field": "email_id,user_emails", + "receiver_by_document_field": "", "receiver_by_role": "User_Account_Manager" } ], @@ -142,7 +142,7 @@ "is_standard": 0, "message": "

Hello Smart Service User,

\n
New {{doc.publish_type}} publish for {{doc.vehicle}} has been published successfully as {{doc.name}}.
\n

\n
Thanks,
\n
Smart Service CMS Admin
", "method": "smart_service.transactions.doctype.publish.publish.cal_ver", - "modified": "2022-03-17 21:09:52.741600", + "modified": "2022-03-21 13:39:24.317947", "module": null, "name": "Published Notification", "parent": null, @@ -160,10 +160,50 @@ "parenttype": "Notification", "receiver_by_document_field": "", "receiver_by_role": "_AppUser" + }, + { + "bcc": null, + "cc": null, + "condition": null, + "parent": "Published Notification", + "parentfield": "recipients", + "parenttype": "Notification", + "receiver_by_document_field": null, + "receiver_by_role": "_Approver" + }, + { + "bcc": null, + "cc": null, + "condition": null, + "parent": "Published Notification", + "parentfield": "recipients", + "parenttype": "Notification", + "receiver_by_document_field": null, + "receiver_by_role": "_Author" + }, + { + "bcc": null, + "cc": null, + "condition": null, + "parent": "Published Notification", + "parentfield": "recipients", + "parenttype": "Notification", + "receiver_by_document_field": null, + "receiver_by_role": "_Reviewer" + }, + { + "bcc": null, + "cc": null, + "condition": null, + "parent": "Published Notification", + "parentfield": "recipients", + "parenttype": "Notification", + "receiver_by_document_field": null, + "receiver_by_role": "_Publisher" } ], "send_system_notification": 0, - "send_to_all_assignees": 0, + "send_to_all_assignees": 1, "sender": "GSS-CMS", "sender_email": "cms@guidedsmartservice.com", "set_property_after_alert": null, diff --git a/smart_service/transactions/doctype/publish/publish.py b/smart_service/transactions/doctype/publish/publish.py index 5445f8b..afde8de 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -168,3 +168,26 @@ def update_mapping(variant_mapping,doc): sm_item.procedure_is_published = '1' frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(current_db_name,sm.name,variant.system,variant.sub_system)) frappe.db.commit() + +@frappe.whitelist() +def get_vm_asset(doc): + doc = frappe.get_doc("Variant Mapping",doc) + vm_assets = frappe.db.sql("""select category,language,attach_file,active_status from `tabVariant Mapping_Assets` where parent = %s and published = '0'""",doc.name,as_dict=True) + return vm_assets +@frappe.whitelist() +def get_sm_asset(doc): + system_map = frappe.db.sql("""select name from `tabSystem Mapping` where variant_mapping=%s""",doc,as_dict=True) + if system_map: + for s in system_map: + doc = frappe.get_doc("System Mapping",s.name) + system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from `tabSystem Mapping_System Assets` where parent = %s and published = '0'""",s.name,as_dict=True) + return system_asset + +@frappe.whitelist() +def get_system(doc): + system_map = frappe.db.sql("""select name from `tabSystem Mapping` where variant_mapping=%s""",doc,as_dict=True) + if system_map: + for s in system_map: + doc = frappe.get_doc("System Mapping",s.name) + system = frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimated_time,rts,component,mat,procedure_status,`procedure` from `tabSystem Mapping_Sub System` where parent = %s and procedure_is_published = '0'""",s.name,as_dict=True) + return system