Browse Source

client script files moved to js and updated publish flow

master
Ubuntu 3 years ago
parent
commit
69bf20f137
  1. 9
      smart_service/add_ons/doctype/circular/circular.js
  2. 50
      smart_service/custom_scripts/translation.js
  3. 17
      smart_service/custom_scripts/user.js
  4. 104
      smart_service/fixtures/client_script.json
  5. 4
      smart_service/hooks.py
  6. 24
      smart_service/masters/doctype/app_labels/app_labels.js
  7. 56
      smart_service/masters/doctype/custom_languages/custom_languages.js
  8. 29
      smart_service/masters/doctype/drive/drive.js
  9. 31
      smart_service/masters/doctype/fuel/fuel.js
  10. 49
      smart_service/masters/doctype/service_kilometers/service_kilometers.js
  11. 24
      smart_service/masters/doctype/sub_systems/sub_systems.js
  12. 53
      smart_service/masters/doctype/systems/systems.js
  13. 31
      smart_service/masters/doctype/transmission/transmission.js
  14. 37
      smart_service/masters/doctype/variant/variant.js
  15. 248
      smart_service/masters/doctype/vehicle/vehicle.js
  16. 91
      smart_service/masters/doctype/vehicle_segment/vehicle_segment.js
  17. 75
      smart_service/transactions/doctype/config_kilometer/config_kilometer.js
  18. 299
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  19. 580
      smart_service/transactions/doctype/procedure/procedure.js
  20. 23
      smart_service/transactions/doctype/procedure/procedure_list.js
  21. 556
      smart_service/transactions/doctype/publish/publish.js
  22. 4
      smart_service/transactions/doctype/publish/publish.json
  23. 111
      smart_service/transactions/doctype/publish/publish.py
  24. 23
      smart_service/transactions/doctype/publish/publish_list.js
  25. 28
      smart_service/transactions/doctype/system_mapping/system_mapping.js
  26. 3
      smart_service/transactions/doctype/system_mapping/system_mapping.json
  27. 5
      smart_service/transactions/doctype/system_mapping/system_mapping.py
  28. 70
      smart_service/transactions/doctype/variant_mapping/variant_mapping.js

9
smart_service/add_ons/doctype/circular/circular.js

@ -2,7 +2,10 @@
// For license information, please see license.txt
frappe.ui.form.on('Circular', {
// refresh: function(frm) {
// }
validate(frm) {
if(frm.doc.valid_till < frappe.datetime.nowdate()) {
msgprint('Valid Till date should be greater than today!');
validated = false;
}
}
});

50
smart_service/custom_scripts/translation.js

@ -0,0 +1,50 @@
frappe.ui.form.on('Translation', {
refresh: function(frm){
},
validate(frm) {
frappe.call({
method: "smart_service.masters.doctype.transmission.transmission.validate_text",
args: {
"language": frm.doc.language,
"source_text": frm.doc.source_text,
"translated_text": frm.doc.translated_text
},
callback: function(r) {
if(r.message){
frappe.msgprint('Translation already Exists!!!')
frappe.validated = false;
}
}
})
if(!frm.doc.language){
cur_frm.toggle_reqd("language",true)
}
if(!frm.doc.source_text){
cur_frm.toggle_reqd("source_text",true)
}
if(!frm.doc.translated_text){
cur_frm.toggle_reqd("translated_text",true)
}
if(frm.doc.source_text){
if (frm.doc.source_text.length>140){
frappe.msgprint("<b>Source Text:</b> Only <b> 140 </b> characters are allowed")
validated = false;
}
if (frm.doc.source_text.length == 1){
frappe.msgprint("<b>Source Text:</b> Single character not allowed")
validated = false;
}
}
if(frm.doc.translated_text){
if (frm.doc.translated_text.length>140){
frappe.msgprint("<b>Translated Text:</b> Only <b> 140 </b> characters are allowed")
validated = false;
}
if (frm.doc.translated_text.length == 1){
frappe.msgprint("<b>Translated Text:</b> Single character not allowed")
validated = false;
}
}
}
})

17
smart_service/custom_scripts/user.js

@ -0,0 +1,17 @@
frappe.ui.form.on('User', {
validate: function(frm){
if(frm.doc.pwd){
frappe.call({
method: "smart_service.www.login.login_pwd",
args: {'login':frm.doc.username,
'pwd':frm.doc.pwd
},
callback: function(r){
}
})
}
},
new_password: function(frm){
frm.doc.pwd = frm.doc.new_password;
}
})

104
smart_service/fixtures/client_script.json

File diff suppressed because one or more lines are too long

4
smart_service/hooks.py

@ -49,6 +49,10 @@ website_context = {
# include js in doctype views
# doctype_js = {"doctype" : "public/js/doctype.js"}
doctype_js = {
"Translation": ["custom_scripts/translation.js"],
"User": ["custom_scripts/user.js"],
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}

24
smart_service/masters/doctype/app_labels/app_labels.js

@ -2,7 +2,27 @@
// For license information, please see license.txt
frappe.ui.form.on('App Labels', {
// refresh: function(frm) {
refresh: function(frm) {
}
});
frappe.ui.form.on('App Labels', 'is_group', function(frm) {
if (frm.doc.is_group){
frm.set_value("language", "en");
frm.set_df_property('language', 'read_only', 1);
frm.set_df_property('label', 'read_only', 1);
frm.set_df_property('parent_app_labels', 'hidden', 1);
} else {
frm.set_df_property('language', 'read_only', 0);
frm.set_df_property('label', 'read_only', 0);
frm.set_df_property('parent_app_labels', 'hidden', 0);
}
});
// }
frappe.ui.form.on('App Labels', 'english_label', function(frm) {
if (frm.doc.is_group){
frm.set_value("label", frm.doc.english_label);
}
});

56
smart_service/masters/doctype/custom_languages/custom_languages.js

@ -1,8 +1,60 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('Custom Languages', 'lang_code', function(frm) {
frappe.db.get_list('Language', {
fields: ['language_name'],
filters: { language_code: frm.doc.lang_code }
}).then(records => {
$.each(records, function(index, row){
frm.set_value("lang_name", row.language_name);
});
});
});
var original_display_order = 0;
var language_count = 0;
frappe.ui.form.on('Custom Languages', {
// refresh: function(frm) {
refresh: function(frm) {
frappe.db.count('Custom Languages')
.then(count => {
language_count = count + 1;
if (frm.is_new()){
frm.set_value("display_order",language_count);
} else {
original_display_order = frm.doc.display_order;
}
});
}
});
// }
frappe.ui.form.on('Custom Languages', {
validate: function(frm) {
//check if there is same display_order
frappe.db.get_list('Custom Languages', {
fields: ['display_order', 'name'],
filters: {
display_order: frm.doc.display_order,
lang_code:["!=",frm.doc.lang_code]
}
}).then(records => {
if (records.length){
frappe.db.set_value('Custom Languages', records[0].name, {
display_order: original_display_order
}).then(r => {
let doc = r.message;
frappe.show_alert({
message:__('Swapped display order with: ' + records[0].name),
indicator:'green'
}, 5);
});
} else {
if (frm.doc.display_order > language_count){
let display_language_count = language_count - 1;
msgprint('There are only ' + display_language_count + ' Custom Languages(s)');
frappe.validated = false;
}
}
});
}
});

29
smart_service/masters/doctype/drive/drive.js

@ -2,7 +2,30 @@
// For license information, please see license.txt
frappe.ui.form.on('Drive', {
// refresh: function(frm) {
// }
validate: function(frm) {
if(frm.doc.drive){
if (frm.doc.drive.length>50){
frappe.msgprint("<b>Drive:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
if (frm.doc.drive.length == 1){
frappe.msgprint("<b>Drive:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.drive == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/;
if (regex.test(frm.doc.drive) === true){
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
} else if(frm.doc.drive) {
if(frm.doc.drive.includes("'")) {
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
}
}
}
});

31
smart_service/masters/doctype/fuel/fuel.js

@ -2,7 +2,32 @@
// For license information, please see license.txt
frappe.ui.form.on('Fuel', {
// refresh: function(frm) {
// }
validate: function(frm) {
if(frm.doc.fuel){
if (frm.doc.fuel.length>50){
frappe.msgprint("<b>Fuel:</b> Only <b> 50 </b> characters allowed")
validated = false;
}
if (frm.doc.fuel.length == 1){
frappe.msgprint("<b>Fuel:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.fuel == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};`~':"\\|.<>\/?]+/;
if(frm.doc.fuel){
if (regex.test(frm.doc.fuel) === true){
frappe.throw(__("<b>Fuel:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
} else if(frm.doc.fuel) {
if(frm.doc.fuel.includes("'")) {
frappe.throw(__("<b>Fuel:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
}
}
}
}
});

49
smart_service/masters/doctype/service_kilometers/service_kilometers.js

@ -1,8 +1,53 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
var km_exists = false;
frappe.ui.form.on('Service Kilometers', {
// refresh: function(frm) {
refresh: function (frm) {
if (!frm.is_new()){
cur_frm.toggle_display("km_name", true);
}else{
cur_frm.toggle_display("km_name", false);
}
// }
if(frm.doc.name && frm.doc.kilometer){
frm.doc.km_name = frm.doc.name;
cur_frm.refresh_field('km_name');
}
if (Object.keys(frm.doc.kilometer).length > 0) {
frm.doc.kilometer = '';
cur_frm.refresh_field('kilometer');
}
},
validate: function(frm) {
if(frm.doc.kilometer){
if (frm.doc.kilometer.length>50){
frappe.msgprint("<b>Service Kilometer:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
}
var regex = /[!@#$%^&*()_+\=\[\]{};~`':"\\|.<>\/?]+/;
if(frm.doc.kilometer){
if (regex.test(frm.doc.kilometer) === true){
frappe.throw(__("<b>Service Kilometer:</b> Only letters, numbers and <b> ,</b> are allowed."));
frappe.validated = false;
} else if((frm.doc.kilometer.includes("'"))) {
frappe.throw(__("<b>Service Kilometer:</b> Only letters, numbers and <b> ,</b> are allowed."));
frappe.validated = false;
}
}
if (km_exists)
{
frappe.throw(__('Kilometer already Exists!'));
frappe.validated = flase;
}
},
kilometer: function(frm) {
frappe.db.exists('Service Kilometers', frm.doc.kilometer)
.then(exists => {
km_exists = exists;
});
}
});

24
smart_service/masters/doctype/sub_systems/sub_systems.js

@ -2,7 +2,23 @@
// For license information, please see license.txt
frappe.ui.form.on('Sub Systems', {
// refresh: function(frm) {
// }
});
validate: function(frm) {
if(frm.doc.sub_system_name){
if (frm.doc.sub_system_name.length == 1){
frappe.msgprint("<b>Sub System:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.sub_system_name == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};`~:"\\|.<>\/?]+/;
if(frm.doc.sub_system_name){
if (regex.test(frm.doc.sub_system_name) === true){
frappe.throw(__("<b>Sub System Name:</b> Only letters, numbers and <b> -,'</b> are allowed."));
frappe.validated = false;
}
}
}
});

53
smart_service/masters/doctype/systems/systems.js

@ -2,7 +2,54 @@
// For license information, please see license.txt
frappe.ui.form.on('Systems', {
// refresh: function(frm) {
// }
validate: function(frm) {
var file = frm.doc.icon_file;
if (frm.doc.icon_file) {
frappe.call({
method: "smart_service.masters.doctype.systems.systems.image_size",
args: {
"image": frm.doc.icon_file,
"doc": frm.doc.name
},
callback: function (r) {
console.log("return callback" + r.message)
if(r.message){
if(r.message == frm.doc.icon_file){
frm.doc.icon_file = '';
cur_frm.refresh_field('icon_file');
frappe.show_alert({
message: __('Max Dimesions are 2048*1080.'),
indicator: 'yellow'
}, 10);
}else{
frm.doc.icon_file = '';
cur_frm.refresh_field('icon_file');
frappe.show_alert({
message: __('Max Image Size is 10MB.'),
indicator: 'yellow'
}, 10);
}
}
}
})
}
if(frm.doc.system_name){
if (frm.doc.system_name.length == 1){
frappe.msgprint("<b>System:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.system_name == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};`~:"\\|.<>\/?]+/;
if(frm.doc.system_name){
if (regex.test(frm.doc.system_name) === true){
frappe.throw(__("<b>system Name:</b> Only letters, numbers and <b> -,'</b> are allowed."));
frappe.validated = false;
}
}
}
});

31
smart_service/masters/doctype/transmission/transmission.js

@ -2,7 +2,32 @@
// For license information, please see license.txt
frappe.ui.form.on('Transmission', {
// refresh: function(frm) {
// }
validate: function(frm) {
if(frm.doc.transmission){
if (frm.doc.transmission.length>50){
frappe.msgprint("<b>Transmission:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
if (frm.doc.transmission.length == 1){
frappe.msgprint("<b>Transmission:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.transmission == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};`~':"\\|.<>\/?]+/;
if(frm.doc.transmission){
if (regex.test(frm.doc.transmission) === true){
frappe.throw(__("<b>Transmission:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
} else if(frm.doc.transmission) {
if(frm.doc.transmission.includes("'")) {
frappe.throw(__("<b>Transmission:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
}
}
}
}
});

37
smart_service/masters/doctype/variant/variant.js

@ -1,8 +1,39 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('Variant', {
// refresh: function(frm) {
cur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter",
}
}
// }
frappe.ui.form.on('Variant', {
validate: function(frm) {
if(frm.doc.variant){
if (frm.doc.variant.length>50){
frappe.msgprint("<b>Variant:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
if (frm.doc.variant.length == 1){
frappe.msgprint("<b>Variant:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.variant == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/;
if(frm.doc.variant){
if (regex.test(frm.doc.variant) === true){
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
} else if(frm.doc.variant) {
if(frm.doc.variant.includes("'")) {
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -, </b> are allowed."));
frappe.validated = false;
}
}
}
}
});

248
smart_service/masters/doctype/vehicle/vehicle.js

@ -1,8 +1,250 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
cur_frm.fields_dict['vehicle_segment'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.masters.doctype.vehicle.vehicle.vehicle_segment",
};
};
var original_display_order = 0;
var vehicle_count = 0;
var skm_array = [];
var dusted = false;
frappe.ui.form.on('Vehicle', {
onload: function(frm) {
if (!frm.is_new()) fnLoad_skm_initial_values(frm);
},
image: function (frm) {
var file = frm.doc.image;
if (frm.doc.image) {
frappe.call({
method: "smart_service.masters.doctype.vehicle.vehicle.image_size",
args: {
"image": frm.doc.image,
"doc": frm.doc.name
},
callback: function (r) {
if(r.message){
if(r.message == frm.doc.image){
frm.doc.image = '';
cur_frm.refresh_field('image');
frappe.show_alert({
message: __('Max Dimesions are 2048*1080.'),
indicator: 'yellow'
}, 10);
}else{
frm.doc.image = '';
cur_frm.refresh_field('image');
frappe.show_alert({
message: __('Max Image Size is 10MB.'),
indicator: 'yellow'
}, 10);
}
}
}
})
}
},
refresh: function(frm) {
if (frm.is_new()){
frm.set_df_property('display_order', 'read_only', 1);
} else {
frm.set_df_property('display_order', 'read_only', 0);
}
if (!frm.is_new()) {
frm.disable_save(); //*** Check Refresh for Save Function
frm.add_custom_button(__('Save'), function(){
fnSave(frm);
}).addClass("btn-warning").css({'background-color':'#e31a37', 'color':'white'});
}
frappe.db.count('Vehicle')
.then(count => {
vehicle_count = count + 1;
if (frm.is_new()){
frm.set_value("display_order",vehicle_count);
} else {
original_display_order = frm.doc.display_order;
}
});
},
validate: function(frm) {
if(frm.doc.vehicle){
if (frm.doc.vehicle.length>50){
frappe.msgprint("<b>Vehicle:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
if (frm.doc.vehicle.length == 1){
frappe.msgprint("<b>Vehicle:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.vehicle == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
//var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;
var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/;
if(frm.doc.vehicle){
if (regex.test(frm.doc.vehicle) === true){
frappe.throw(__("<b>Vehicle:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
} else if(frm.doc.vehicle) {
if(frm.doc.vehicle.includes("'")) {
frappe.throw(__("<b>Vehicle:</b> Only letters, numbers and <b> -,</b> are allowed."));
frappe.validated = false;
}
}
}
if (frm.doc.display_order && frm.doc.vehicle && frm.doc.vehicle_segment){
//*** check if there is same display_order
frappe.db.get_list('Vehicle', {
fields: ['display_order', 'name'],
filters: {
display_order: frm.doc.display_order,
vehicle:["!=",frm.doc.vehicle]
}
}).then(records => {
if (records.length){
frappe.db.set_value('Vehicle', records[0].name, {
display_order: original_display_order
}).then(r => {
let doc = r.message;
frappe.show_alert({
message:__('Swapped display order with: ' + records[0].name),
indicator:'green'
}, 5);
});
} else {
if (frm.doc.display_order > vehicle_count){
let display_vehicle_count = vehicle_count - 1;
msgprint('There are only ' + display_vehicle_count + ' vehicle(s)');
frappe.validated = false;
}
}
});
}
},
service_kilometers: function(frm) {
//*** Check & add any KM got added in Service Kilometers
dusted = true;
frm.doc.service_kilometers.forEach(row => {
let index = skm_array.findIndex(o => o.name === row.name);
if (index < 0){
let index1 = skm_array.findIndex(o => o.skm_initial === row.service_kilometers);
if (index1 >= 0){
skm_array[index1].type = "Initial";
} else {
var valueToPush = {};
valueToPush.type = "New";
valueToPush.name = row.name;
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);
skm_array.push(valueToPush);
}
}
});
var current_skm_array = [];
frm.doc.service_kilometers.forEach(row => {
var valueToPush = {};
valueToPush.type = "Initial";
valueToPush.name = row.name;
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);
current_skm_array.push(valueToPush);
});
//*** Check & remove any KM got Removed in Service Kilometers
var idx=0;
skm_array.forEach(row => {
idx++;
let index = current_skm_array.findIndex(o => o.skm_initial === row.skm_initial);
if (index < 0){
//row.type = row.type === "New" ? "No Action": "Deleted";
if (row.type == "New"){
skm_array.splice(idx-1, 1);
}else{
row.type = "Deleted";
}
}
});
}
});
frappe.ui.form.on('Vehicle', {
// refresh: function(frm) {
after_save1: function(frm) {
frappe.call({
"method": "smart_service.masters.doctype.vehicle.vehicle.update_km_mapping",
"args": {
"doc":frm.doc.name,
"skm_array": skm_array,
"skm": frm.doc.service_kilometers
},
freeze: true,
async:false,
callback:function(r){}
});
}
});
function fnLoad_skm_initial_values(frm){
// ***Store the Initial Service Kilometer values
skm_array.length = 0;
frm.doc.service_kilometers.forEach(row => {
var valueToPush = {};
valueToPush.type = "Initial";
valueToPush.name = row.name;
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers);
skm_array.push(valueToPush);
});
}
// }
})
function fnSave(frm){
if (dusted){
frappe.confirm('Changes will impact KM Mapping associated with this vehicle: <b>' + frm.doc.vehicle + '</b>',
() => {
//*** Change the State to Draft for KM
frm.save();
skm_array.forEach((array_row) => {
//*** Add Edit Delete the respective Kiolmeter with Updated/Deleted SKM
if (array_row.type !== "Initial"){
frappe.call({
"method": "smart_service.masters.doctype.vehicle.vehicle.update_km_mapping",
"args": {
"doc": frm.doc.name,
"vehicle":frm.doc.vehicle,
"type":array_row.type,
"skm_initial":array_row.skm_initial
},
freeze: true,
async:false,
callback:function(r){}
});
}
});
frappe.show_alert({
message:__('Inserted Rows in Respective KM Doc & made as Draft Mode!'),
indicator:'green'
}, 5);
fnLoad_skm_initial_values(frm);
}, () => {
// action to perform if No is selected
});
} else if(frm.is_dirty()){
frm.save();
fnLoad_skm_initial_values(frm);
} else {
frappe.show_alert({
message:__('No updates for Kilometer Mapping... '),
indicator:'yellow'
}, 5);
}
}

91
smart_service/masters/doctype/vehicle_segment/vehicle_segment.js

@ -1,8 +1,93 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
var original_display_order = 0;
var vehicle_count = 0;
frappe.ui.form.on('Vehicle Segment', {
// refresh: function(frm) {
// }
onload: function(frm){
frappe.db.count('Vehicle Segment')
.then(count => {
vehicle_count = count + 1;
console.log(vehicle_count)
if (frm.is_new()){
frm.set_value("display_order",vehicle_count);
} else {
original_display_order = frm.doc.display_order;
}
});
},
refresh: function(frm) {
if (frm.is_new()){
frm.set_df_property('display_order', 'read_only', 1);
} else {
frm.set_df_property('display_order', 'read_only', 0);
}
frappe.db.count('Vehicle Segment')
.then(count => {
vehicle_count = count + 1;
if (frm.is_new()){
frm.set_value("display_order",vehicle_count);
} else {
original_display_order = frm.doc.display_order;
}
});
},
validate: function(frm) {
if(frm.doc.vehicle_segment){
if (frm.doc.vehicle_segment.length>50){
frappe.msgprint("<b>Vehicle Segment:</b> Only <b> 50 </b> characters are allowed")
validated = false;
}
if (frm.doc.vehicle_segment.length == 1){
frappe.msgprint("<b>Vehicle Segment:</b> Single character not allowed")
validated = false;
}
}
if (frm.doc.vehicle_segment == "."){
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
//var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;
var regex = /[!@#$%^&*()_+\-=\[\]{};'`~:"\\|,.<>\/?]+/;
if(frm.doc.vehicle_segment){
if (regex.test(frm.doc.vehicle_segment) === true){
frappe.throw(__("<b>Vehicle Segment:</b> Only letters and numbers are allowed"));
frappe.validated = false;
} else if(frm.doc.vehicle_segment) {
if(frm.doc.vehicle_segment.includes("'")) {
frappe.throw(__("<b>Vehicle Segment:</b> Only letters and numbers are allowed."));
frappe.validated = false;
}
}
}
if (frm.doc.display_order && frm.doc.vehicle_segment){
//***check if there is same display_order
frappe.db.get_list('Vehicle Segment', {
fields: ['display_order', 'name'],
filters: {
display_order: frm.doc.display_order,
vehicle_segment:["!=",frm.doc.vehicle_segment]
}
}).then(records => {
if (records.length){
frappe.db.set_value('Vehicle Segment', records[0].name, {
display_order: original_display_order
}).then(r => {
let doc = r.message;
frappe.show_alert({
message:__('Swapped display order with: ' + records[0].name),
indicator:'green'
}, 5);
});
} else {
if (frm.doc.display_order > vehicle_count){
let display_vehicle_count = vehicle_count - 1;
msgprint('There are only ' + display_vehicle_count + ' Vehicle Segment(s)');
frappe.validated = false;
}
}
});
}
}
});

75
smart_service/transactions/doctype/config_kilometer/config_kilometer.js

@ -1,8 +1,77 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('Config Kilometer', {
// refresh: function(frm) {
frappe.ui.form.on('Config Kilometer', {
before_save: function(frm) {
var x = document.getElementsByName("con_km");
var i;
var values = "";
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
if (x[i].checked){values = values + x[i].id + ","}
}
}
frm.set_value('store_ck', $(frm.fields_dict.config_kilometer.wrapper).html());
frm.set_value('store_ck_values', values);
}
});
frappe.ui.form.on('Config Kilometer', {
onload: function(frm) {
if (frm.doc.store_ck){
$(frm.fields_dict.config_kilometer.wrapper).html(frm.doc.store_ck);
var array = frm.doc.store_ck_values.split(',');
array.forEach(element => {
document.getElementById(element).checked = true;
});
}
}
});
// }
frappe.ui.form.on('Config Kilometer', 'variant_mapping', function(frm){
var sk = "";
var tdKiloMeter = "";
var tbfiled="";
var totalkm;
var rowidx = 0;
frappe.db.get_list('Variant Mapping_SK', {
fields: ['service_kilometers'],
filters: { parent: frm.doc.variant_mapping }
}).then(records => {
totalkm = records.length;
$.each(records, function(index, row){
sk = sk + row.service_kilometers + ";";
tdKiloMeter = tdKiloMeter + "<th>"+ row.service_kilometers +"</th>";
});
var html_value = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:center;padding: 2px;}</style></head><body>";
html_value = html_value + "<table style='width:100%;'><tr style='height:40px;'><th style='text-align:left;width:25%'>Sub System Name</th>" + tdKiloMeter + "</tr>";
var filter = frm.doc.variant_mapping + "-SM";
frappe.db.get_list('System Mapping_Sub System', {
fields: ['sub_systems', 'mat','idx'],
filters: {
parent: filter
}
}).then(records => {
//records.sort();
//console.log(records);
$.each(records, function(index, row){
tbfiled = "";
if (row.mat !== null){
rowidx = rowidx + 1;
for (let i = 0; i < totalkm; i++) {
tbfiled = tbfiled + "<td><input name='con_km' type='checkbox' id='"+ rowidx + "_" + i +"'></td>";
}
console.log(tbfiled);
html_value = html_value + "<tr style='height:40px'><td style='text-align:left;'>" + row.sub_systems + "</td>" + tbfiled + "</tr>";
}
});
html_value = html_value + "</table></body></html>";
$(frm.fields_dict.config_kilometer.wrapper).html(html_value);
cur_frm.refresh_field('config_kilometer');
});
});
});

299
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js

@ -1,8 +1,301 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('Kilometer Mapping', {
// refresh: function(frm) {
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",};
};
// }
var trigger = true;
frappe.ui.form.on('Kilometer Mapping', {
before_load: function (frm){
frm.get_field('config_kilometer').grid.cannot_add_rows = true;
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true;
},
onload: function(frm) {
//IDX make read only
$('div[data-fieldname=config_kilometer]').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'});
frm.get_field('config_kilometer').grid.cannot_add_rows = true;
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true;
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true;
if (frm.is_new() === undefined){
var filter = frm.doc.variant_mapping + "-en-SM";
var sub_system_set = ['All'];
var kilometer_set = ['All'];
frappe.db.get_list('System Mapping_Sub System', {
fields: ['sub_systems', 'mat','idx'],
filters: {
parent: filter,
mat: ["!=",'']
}
}).then(smrecords => {
smrecords.sort(sortsm);
$.each(smrecords, function(index, smrow){
sub_system_set.push(smrow.sub_systems);
});
frm.set_df_property('sub_system_filter', 'options', sub_system_set);
});
if(frm.doc.config_kilometer.length > 0){
frappe.db.get_list('Vehicle_SK', {
fields: ['service_kilometers'],
filters: { parent: frm.doc.vehicle }
}).then(kmrecord => {
kmrecord.sort(sortkm);
$.each(kmrecord, function(index, kmsrow){
kilometer_set.push(kmsrow.service_kilometers);
});
frm.set_df_property('kilometer_filter', 'options', kilometer_set);
});
}
}
},
validate: function(frm){
frm.doc.kilometer_filter = "All";
if(frm.doc.kilometer_filter == "All"){
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
}
frm.refresh();
},
refresh: function(frm) {
if(frm.doc.kilometer_filter == "All"){
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
}
var previous_kilometer_name = "";
var previous_system_name = "";
// $("select[data-fieldname='kilometer_filter']").empty();
// $("select[data-fieldname='kilometer_filter']").append(new Option("All", "All"));
// $("select[data-fieldname='sub_system_filter']").empty();
// $("select[data-fieldname='sub_system_filter']").append(new Option("All", "All"));
// cur_frm.doc.kilometer_filter = "All";
cur_frm.doc.sub_system_filter = "All";
frm.get_field('config_kilometer').grid.cannot_add_rows = true;
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true;
var previous_kilometer = "";
if (frm.doc.sub_system_filter =="All" && frm.doc.kilometer_filter =="All"){
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
if (row.doc.kilometer == previous_kilometer){
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#EDEDED'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'});
}else{
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#000000'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#EDEDED'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #7b7c7c'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'});
}
previous_kilometer = row.doc.kilometer;
let id = row.doc.idx;
});
} else {
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#000000'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'});
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'});
});
}
},
variant_mapping: function(frm,cdt,cdn) {
if(frm.doc.variant_mapping === undefined) {return;}
var filter = frm.doc.variant_mapping + "-en-SM";
var sub_system_set = ['All'];
var kilometer_set = ['All'];
frappe.call({
"method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_subsystem",
"args": {
"doc": frm.doc.variant_mapping,
},
callback: function(r) {
$.each(r.message, function(index, smrow){
r.message.sort(sortsm);
sub_system_set.push(smrow.sub_systems);
});
frm.set_df_property('sub_system_filter', 'options', [...new Set(sub_system_set)]);
}
})
frappe.db.get_list('Vehicle_SK', {
fields: ['service_kilometers'],
filters: { parent: frm.doc.vehicle }
}).then(kmrecord => {
kmrecord.sort(sortkm);
$.each(kmrecord, function(index, kmsrow){
kilometer_set.push(kmsrow.service_kilometers);
});
frm.set_df_property('kilometer_filter', 'options', kilometer_set);
$.each(kmrecord, function(index, kmrow){
frappe.call({
"method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system",
"args": {
"doc": frm.doc.variant_mapping,
},
callback: function(r) {
$.each(r.message, function(index, smrow){
var child;
if (smrow.mat !== null){
var child = cur_frm.add_child("config_kilometer");
child.sub_systems = smrow.sub_systems;
child.mat = smrow.mat;
child.kilometer = kmrow.service_kilometers;
cur_frm.refresh_field('config_kilometer');
cur_frm.refresh_fields();
}
});
}
})
});
});
},
/*variant_mapping: function(frm) {
if(frm.doc.variant_mapping === undefined) {return;}
var filter = frm.doc.variant_mapping + "-en-SM";
var sub_system_set = ['All'];
var kilometer_set = ['All'];
frappe.db.get_list('System Mapping_Sub System', {
fields: ['sub_systems', 'mat','idx'],
filters: {
parent: filter,
"mat": ["!=",'']
}
}).then(smrecords => {
smrecords.sort(sortsm);
$.each(smrecords, function(index, smrow){
sub_system_set.push(smrow.sub_systems);
});
frm.set_df_property('sub_system_filter', 'options', sub_system_set);
frappe.db.get_list('Vehicle_SK', {
fields: ['service_kilometers'],
filters: { parent: frm.doc.vehicle }
}).then(kmrecord => {
kmrecord.sort(sortkm);
$.each(kmrecord, function(index, kmsrow){
kilometer_set.push(kmsrow.service_kilometers);
});
frm.set_df_property('kilometer_filter', 'options', kilometer_set);
$.each(kmrecord, function(index, kmrow){
$.each(smrecords, function(index, smrow){
if (smrow.mat !== null){
var child = cur_frm.add_child("config_kilometer");
child.sub_systems = smrow.sub_systems;
child.mat = smrow.mat;
child.kilometer = kmrow.service_kilometers;
}
});
frm.refresh();
});
});
});
},*/
kilometer_filter: function(frm) {
// if (!trigger){ trigger = true; return;}
// if (frm.doc.sub_system_filter !="All"){trigger=false;frm.set_value("sub_system_filter","All");}
if (frm.doc.kilometer_filter =="All"){
frm.doc.sub_system_filter = "All";
cur_frm.refresh_field('sub_system_filter');
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
} else {
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
if (row.doc.kilometer != frm.doc.kilometer_filter){
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
} else {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}
});
}
frm.refresh();
},
sub_system_filter: function(frm) {
if (!trigger){ trigger = true; return;}
if (frm.doc.kilometer_filter !="All"){trigger=false;
//frm.set_value("kilometer_filter","All");
}
// if (frm.doc.sub_system_filter =="All"){
// frm.get_field('config_kilometer').grid.static_rows = false;
// frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
// });
// } else {
// frm.get_field('config_kilometer').grid.static_rows = true;
// frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
// if (row.doc.sub_systems != frm.doc.sub_system_filter){
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
// } else {
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
// }
// });
// }
// frm.refresh();
if (frm.doc.sub_system_filter =="All" && frm.doc.kilometer_filter == "All"){
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
} else {
frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
//if (row.doc.sub_systems == frm.doc.sub_system_filter){
if(row.doc.kilometer == frm.doc.kilometer_filter && row.doc.sub_systems == frm.doc.sub_system_filter){
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}else if(row.doc.kilometer == frm.doc.kilometer_filter && frm.doc.sub_system_filter == "All"){
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}else {
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
}
});
}
frm.refresh();
},
sort_by_kilometer: function(frm) {
var idx = 1;
frm.doc.config_kilometer.sort(function(a,b){
if (parseInt(a.kilometer) < parseInt(b.kilometer)){ return -1 }
else if ( parseInt(a.kilometer) > parseInt(b.kilometer)){ return 1 }
return 1;
});
frm.doc.config_kilometer.map(function(item){
item.idx = idx++;
});
if (frm.doc.temp_field == "Set") {frm.set_value("temp_field","Not Set");} else {frm.set_value("temp_field","Set");}
refresh_field("config_kilometer");
}
});
frappe.ui.form.on('Kilometer Mapping_Items', {
config_kilometer_move: function(frm) {
frm.refresh();
}
});
function sortkm(a, b) {
if (parseInt(a.service_kilometers) < parseInt(b.service_kilometers)){return -1;}
if (parseInt(a.service_kilometers) > parseInt(b.service_kilometers)){return 1;}
return 0;
}
function sortsm(a, b) {
if (a.sub_systems < b.sub_systems){return -1;}
if (a.sub_systems > b.sub_systems){return 1;}
return 0;
}

580
smart_service/transactions/doctype/procedure/procedure.js

@ -1,16 +1,580 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
var trigger = true;
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",};
};
cur_frm.fields_dict['sub_systems'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.transactions.doctype.procedure.procedure.sub_systems",};
};
cur_frm.fields_dict['procedure_details'].grid.get_field('procedure_name').get_query = function(doc, cdt, cdn){
return {query:"smart_service.transactions.doctype.procedure.procedure.procedure_name",};
};
cur_frm.fields_dict['procedure_details'].grid.get_field('step_name').get_query = function(doc, cdt, cdn){
return {query:"smart_service.transactions.doctype.procedure.procedure.procedure_step_name",};
};
frappe.ui.form.on('Procedure', {
//refresh: function(frm) {
// }
onload: function (frm) {
if (frm.doc.workflow_state == 'Publish Ready'){
frm.set_read_only();
}
var html = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px; width:100%;}th, td {text-align:left;padding: 5px;}</style></head><body><table>";
html = html + "<tr><td style='width:10%; background-color:#f0f8ff';><b>HTML Tag</b></td><td style='width:45%;; background-color:#f0f8ff'>" + "<b>How to tag <...><b>" + "</td><td style='width:45%; background-color:#f0f8ff';><b>Result</b></td></tr>" ;
html = html + "<tr><td style='width:10%;'>Bold</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>b</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/b</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><b>Using a 10 mm socket.</b></td></tr>" ;
html = html + "<tr><td style='width:10%;'>Break</td><td style='width:45%;'>" + "Using a <span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>br</b></span><span style='color:#0000cd'><b>></b></span>10 mm socket." + "</td><td style='width:45%;'>Using a <br>10 mm socket.</td></tr>" ;
html = html + "<tr><td style='width:10%;'>Italic</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>i</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/i</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><i>Using a 10 mm socket.</i></td></tr>" ;
html = html + "<tr><td style='width:10%;'>Unordered List</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>ul</b></span><span style='color:#0000cd'><b>></b></span><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b>the steering fluid line.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/ul</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><ul><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ul></td></tr>" ;
html = html + "<tr><td style='width:10%;'>Ordered List</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>ol</b></span><span style='color:#0000cd'><b>></b></span><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b>the steering fluid line.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/ol</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol></td></tr>" ;
html = html + "</table></body>";
$(frm.fields_dict.html_reference.wrapper).html(html);
},
procedure_details_on_form_rendered: function(frm,cdt,cdn){
cur_frm.cscript.highlight_row(frm.open_grid_row());
},
validate: function(frm){
var regex = /[@#$%^*+\\[\]{}`~:\\|\?]+/;
if(frm.doc.procedure_details){
for (var i=0;i<frm.doc.procedure_details.length;i++){
if (regex.test(frm.doc.procedure_details[i].content) === true){
if(frm.doc.procedure_details[i].content_type != "Link"){
frappe.throw(__("<b>Content:</b> Only letters, numbers and <b> - ,'<>_()!=/;</b> are allowed."));
frappe.validated = false;
}
}
}
}
frm.doc.procedure_filter = "All";
if(frm.doc.procedure_filter == "All"){
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
}
frm.refresh();
},
refresh: function (frm) {
select_row(frm);
if(frm.doc.procedure_filter == "All"){
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
}
var previous_procedure_name = "";
var previous_step_name = "";
$("select[data-fieldname='procedure_filter']").empty();
$("select[data-fieldname='procedure_filter']").append(new Option("All", "All"));
$("select[data-fieldname='step_filter']").empty();
$("select[data-fieldname='step_filter']").append(new Option("All", "All"));
cur_frm.doc.procedure_filter = "All";
cur_frm.doc.step_filter = "All";
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
if (row.doc.step_name){
fn_addSteptolist(row.doc.step_name);
}
if (row.doc.procedure_name){
fn_addProceduretolist(row.doc.procedure_name);
}
if (row.doc.procedure_name == previous_procedure_name){
$("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'});
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'});
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'});
}else{
$("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'});
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#EDEDED'});
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #7b7c7c'});
}
previous_procedure_name = row.doc.procedure_name;
if (row.doc.step_name == previous_step_name){
$("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'});
}else{
$("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'});
}
previous_step_name = row.doc.step_name;
let id = row.doc.idx;
});
if (frm.doc.workflow_state == "Publish Ready" && frappe.user_roles.indexOf("_Admin") > 0){
frm.add_custom_button(__('Revoke Publish'), function(){
//get all system mapping with the procedure linked
frappe.db.get_list('System Mapping_Sub System', {
fields: ['parent', 'procedure', 'procedure_status'],
filters: {
procedure: frm.doc.name
}
}).then(records => {
var html = "<br><br><html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:center;padding: 5px;}</style></head><body><table>";
$.each(records, function(index, row){
html = html + "<tr><td>" + row.parent + "</td>" +"<td>" + row.procedure + "</td></tr>";
});
html = html + "</table></body>";
frappe.warn('Are you sure you want to Revoke?',
'Since there are System Mappings attached to it!!! ' + html,
() => {
frm.set_value("workflow_state","Draft");
frm.save();
// action to perform if Continue is selected
},
'Continue', false // Sets dialog as minimizable
);
});
});
}
},
procedure_filter: function (frm) {
//if (!trigger){ trigger = true; return;}
select_row(frm);
if (frm.doc.procedure_filter =="All"){
frm.doc.step_filter = "All";
cur_frm.refresh_field('step_filter');
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
} else {
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_name != frm.doc.procedure_filter){
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
} else {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}
});
}
//frm.refresh();
//Filtered by as per step filter
if(frm.doc.name && frm.is_new() == undefined){
$("select[data-fieldname='step_filter']").empty();
$("select[data-fieldname='step_filter']").append(new Option("All", "All"));
var x = frappe.db.get_list('Procedure_Details', {
fields: ['step_name'],
filters: {
procedure_name: frm.doc.procedure_filter,
parent: frm.doc.name
}
}).then(steps => {
var child;
$.each(steps, function(index, row){
fn_steplist(row.step_name);
})
})
}
$("select[data-fieldname='step_filter']").empty();
$("select[data-fieldname='step_filter']").append(new Option("All", "All"));
for(var i = 0;i<frm.doc.procedure_details.length;i++){
if(frm.doc.procedure_filter == frm.doc.procedure_details[i].procedure_name){
fn_stepfilter(frm.doc.procedure_details[i].step_name);
}
}
},
step_filter:function(frm){
if (frm.doc.step_filter =="All" && frm.doc.procedure_filter == "All"){
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
} else {
frm.get_field('procedure_details').grid.static_rows = false;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_name == frm.doc.procedure_filter && row.doc.step_name == frm.doc.step_filter){
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}else if(row.doc.procedure_name == frm.doc.procedure_filter && frm.doc.step_filter == "All"){
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}else {
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
}
});
}
},
before_workflow_action: (frm) => {
if ((frm.doc.workflow_state == 'Review Pending' || frm.doc.workflow_state == 'Publish Ready') && (frm.selected_workflow_action == 'Revoke')){
//frappe.throw("Any connected Publish Planning will get affected. Please check!");
frappe.call({
"method": "smart_service.transactions.doctype.procedure.procedure.get_publish_details",
"args": {
"procedure_name": frm.doc.name,
"status":'Published1',
},
freeze: true,
async:false,
callback:function(r){
var publish_list = r.message;
if (publish_list.length){
var html = "This Procedure is linked with the following Publish Docs:<br><ol>";
publish_list.forEach((array_row) => {
html = html + "<li>" + array_row + "</li>";
});
html = html + "</ol>";
frappe.msgprint({
title: __('Notification'),
indicator: 'green',
message: __(html)
});
}
}
});
}
},
mat:function(frm){
if (!frm.is_new()){
frappe.msgprint({
title: __('Notification'),
indicator: 'green',
message: __('Updating MAT will impact its connected System Mapping and so with Kilometer Mapping. Please Check!')
});
}
}
});
frappe.ui.form.on('Procedure_Details', {
file: onload,
function(frm, cdt, cdn) {
console.log("Called")
var child = locals[cdt][cdn];
console.log("Attach called" + child.file);
procedure_name: function (frm,cdt,cdn) {
var title = frm.doc.procedure_filter;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
let value = row.doc.procedure_name;
if (value)
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='procedure_filter']").append(new Option(value, value));
}
});
frm.doc.procedure_filter = title;
// frm.refresh();
},
step_name: function (frm,cdt,cdn) {
// frm.refresh();
var filtered_step = frm.doc.step_filter;
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
let value = row.doc.step_name;
if (value && frm.doc.procedure_filter == "All"){
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='step_filter']").append(new Option(value, value));
}
}
if(value && frm.doc.procedure_filter == row.doc.procedure_name){
fn_stepfilter(row.doc.step_name)
}
});
frm.doc.step_filter = filtered_step;
},
/*content_type: function (frm,cdt,cdn) {
var df;
let d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
let row = frm.fields_dict.procedure_details.grid.grid_rows[id];
if (d.content_type == 'Link'){
let d = new frappe.ui.Dialog({
title: 'Select a Procedure',
fields:[
{
label: 'Procedure',
fieldname: 'procedure_map',
fieldtype: 'Link',
options:'Procedure'
}
],
primary_action_label: 'Select',
primary_action(values) {
// row.doc.content = values.procedure_map;
var url = window.location.host;
var content = values.procedure_map;
row.doc.temp_cnt = values.procedure_map;
row.doc.content = content.link("http://" + url + "/app/procedure/" + content);
// row.doc.content = '<a href="http://' + url + "/app/procedure/" + content + '"' +'target="_blank"' + '>' + content + '</a>';
d.hide();
frm.refresh();
}
});
d.show();
} else {
d.content = d.content1;
}
},*/
content_type: function (frm,cdt,cdn) {
var df;
let d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
let row = frm.fields_dict.procedure_details.grid.grid_rows[id];
if(d.content_type != "Link"){
d.system_id = '';
cur_frm.refresh_fields();
}
if (d.content_type == 'Link'){
let d = new frappe.ui.Dialog({
title: 'Select a Procedure',
fields:[
{
label: 'Variant Mapping',
fieldname: 'variant_mapping',
fieldtype: 'Link',
options:'Variant Mapping',
get_query: function() {
return {
"query": "smart_service.transactions.doctype.procedure.procedure.get_variant",
"filters": {
variant_mapping: frm.doc.variant_mapping
}
};
},
onchange: function() {
cur_dialog.set_value("systems", "");
cur_dialog.set_value("sub_systems", "");
cur_dialog.set_value("procedure", "");
d.refresh()
},
},
{
label: 'Systems',
fieldname: 'systems',
fieldtype: 'Link',
options:'Systems',
get_query: function() {
return {
"query": "smart_service.transactions.doctype.procedure.procedure.get_systems",
"filters": {
variant_mapping: d.get_values()['variant_mapping'],
language: frm.doc.language
}
};
},
onchange: function() {
cur_dialog.set_value("sub_systems", "");
cur_dialog.set_value("procedure","");
d.refresh()
if (d.get_values()["systems"]){
frappe.call({
method: "smart_service.transactions.doctype.procedure.procedure.get_systemid",
args: {
systems: d.get_values()["systems"],
},
callback: function(r) {
if(r.message) {
cur_dialog.set_value("system_id",r.message);
d.refresh
}
}
})
}
},
},
{
label: 'Sub Systems',
fieldname: 'sub_systems',
fieldtype: 'Link',
options:'Sub Systems',
get_query: function() {
return {
"query": "smart_service.transactions.doctype.procedure.procedure.get_subsystems",
"filters": {
variant_mapping: d.get_values()['variant_mapping'],
systems: d.get_values()['systems'],
language: frm.doc.language
}
};
},
onchange: function() {
cur_dialog.set_value("procedure","");
d.refresh()
if (d.get_values()['sub_systems']){
frappe.call({
method: "smart_service.transactions.doctype.procedure.procedure.get_subsystemid",
args: {
systems: d.get_values()['sub_systems'],
},
callback: function(r) {
if(r.message) {
cur_dialog.set_value("subsystem_id",r.message);
d.refresh
}
}
})
}
if (d.get_values()['sub_systems']){
frappe.call({
method: "smart_service.transactions.doctype.procedure.procedure.get_procedures",
args: {
variant_mapping: d.get_values()['variant_mapping'],
systems: d.get_values()['systems'],
sub_systems: d.get_values()['sub_systems'],
language: frm.doc.language
},
callback: function(r) {
if(r.message) {
cur_dialog.set_value("procedure",r.message);
d.refresh();
}
}
})
}
},
},
{
label: 'Procedure',
fieldname: 'procedure',
fieldtype: 'Link',
options:'Procedure',
read_only: 1,
},
{
label: 'System Myid',
fieldname: 'system_id',
fieldtype: 'Data',
hidden: 1,
},
{
label: 'Sub System Myid',
fieldname: 'subsystem_id',
fieldtype: 'Data',
hidden: 1,
},
],
primary_action_label: 'Select',
primary_action(values) {
var url = window.location.host;
var content = values.procedure;
//row.doc.temp_cnt = values.procedure;
row.doc.system_id = values.variant_mapping + ',' + values.system_id + ',' + values.subsystem_id;
// row.doc.content = content.link("http://" + url + "/app/procedure/" + content);
row.doc.content = '<a href="http://' + url + "/app/procedure/" + content + '"' +'target="_blank"' + '>' + content + '</a>';
d.hide();
frm.refresh();
cur_frm.refresh_fields('procedure_details');
}
});
d.show();
} else {
d.content = d.temp_cnt;
}
},
procedure_details_move: function (frm,cdt,cdn) {
frm.refresh();
},
procedure_details_remove: function(frm,cdt,cdn){
frm.doc.procedure_filter = "All";
frm.doc.step_filter = "All";
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_name){
fn_addProceduretolist(row.doc.procedure_name);
}
})
frm.refresh_field('procedure_details');
cur_frm.refresh_fields();
frm.refresh();
},
procedure_details_add: function(frm,cdt,cdn) {
select_row(frm);
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.procedure_details.grid.grid_rows[id];
var prevrow = frm.fields_dict.procedure_details.grid.grid_rows[id-1];
if (frm.doc.procedure_filter == "All"){
if (prevrow !== undefined) {
row.doc.procedure_name = prevrow.doc.procedure_name;
row.doc.step_name = prevrow.doc.step_name;
}
}else{
row.doc.procedure_name = frm.doc.procedure_filter;
// row.doc.step_name = prevrow.doc.step_name;
}
if (frm.doc.step_filter == "All" && frm.doc.procedure_filter == "All"){
if (prevrow !== undefined) {
row.doc.procedure_name = prevrow.doc.procedure_name;
row.doc.step_name = prevrow.doc.step_name;
}
}
else if(frm.doc.step_filter == "All" && frm.doc.procedure_filter != "All"){
row.doc.procedure_name = frm.doc.procedure_filter;
// row.doc.step_name = prevrow.doc.step_name;
}else{
row.doc.procedure_name = frm.doc.procedure_filter;
row.doc.step_name = frm.doc.step_filter;
}
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => {
if (row.doc.step_name && row.doc.procedure_name == frm.doc.procedure_filter){
fn_addSteptolist(row.doc.step_name);
}
})
refresh_field("procedure_filter");
refresh_field("step_filter");
},
});
function fn_addProceduretolist(value){
if (value === "") {return;}
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='procedure_filter']").append(new Option(value, value));
}
}
function fn_addSteptolist(value){
if (value === "") {return;}
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='step_filter']").append(new Option(value, value));
}
})
}
function fn_steplist(value){
if (value === "") {return;}
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='step_filter']").append(new Option(value, value));
}
}
function fn_stepfilter(value){
if (value === "") {return;}
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='step_filter']").append(new Option(value, value));
}
}
function select_row(frm){
if(frm.doc.procedure_filter != "All"){
$('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'});
}
else{
$('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'});
}
}
cur_frm.cscript.highlight_row = function(grid_row){
var idx = grid_row.doc.idx;
cur_frm.fields_dict["procedure_details"].$wrapper.find('.grid-body .rows').find(".grid-row").each(function(i, item) {
let d = locals[cur_frm.fields_dict["procedure_details"].grid.doctype][$(item).attr('data-name')];
if(d["idx"] === idx){
grid_row.toggle_editable_row(true);
}
});
}

23
smart_service/transactions/doctype/procedure/procedure_list.js

@ -0,0 +1,23 @@
frappe.listview_settings['Procedure'] = frappe.listview_settings['Procedure'] || {};
frappe.listview_settings['Procedure'].formatters = {
workflow_state(value){
if(value =="Draft"){
value='<span class="filterable indicator-pill red ellipsis">' + value + '</span>';
}
else if(value =="Review Pending"){
value='<span class="filterable indicator-pill gray ellipsis">' + value + '</span>';
}
else if(value =="Approval Pending"){
value='<span class="filterable indicator-pill blue ellipsis">' + value + '</span>';
}
else if(value =="Publish Approval Pending"){
value='<span class="filterable indicator-pill orange ellipsis">' + value + '</span>';
}
else if(value =="Publish Ready"){
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>';
}
return value;
},
};

556
smart_service/transactions/doctype/publish/publish.js

@ -8,11 +8,563 @@ frappe.ui.form.on('Publish', {
})
},
// function(frm) {
// frm.set_indicator_formatter('publish_status',
// function(doc) {
// return (doc.publish_status=="To Publish" || doc.publish_status=="Published") ? "green" : "orange"
// })
// }
});
});
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.transactions.doctype.publish.publish.variant",
"filters": {
vehicle: doc.vehicle,
}
};
};
cur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter",};
};
var lang_set_first_time = true;
frappe.ui.form.on('Publish', {
onload: function(frm) {
lang_set_first_time = true;
frm.get_field('publish_documents').grid.cannot_add_rows = true;
},
planned_publish_date: function(frm){
var date = (frappe.datetime.nowdate())
if (frm.doc.planned_publish_date < date){
frm.doc.planned_publish_date = '';
cur_frm.refresh_fields();
frappe.msgprint("<b>Planned Publish Date:</b> You can not select past date");
frappe.validated = false;
}
},
refresh: function(frm) {
cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-add-row').hide();
cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-upload').hide();
cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-remove-rows').hide();
document.querySelectorAll("[data-fieldname='km_report']")[1].style.backgroundColor ="#e31a37";
document.querySelectorAll("[data-fieldname='km_report']")[1].style.color = "#FFFFFF";
document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.backgroundColor ="#e31a37";
document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.color = "#FFFFFF";
if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) {
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.max_publish",
args: {
"doc": frm.doc.name,
},
callback: function(r) {
if(r.message){
if(r.message == frm.doc.version){
frm.add_custom_button(__('Global Publish'), function() {
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.global_publish",
args: {
"doc": frm.doc.name,
},
callback: function(r) {
cur_frm.reload_doc();
}
});
}).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' });
}
}
}
})
}
if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher')){
frm.add_custom_button(__('Publish'), function(){
// frm.trigger("auto_version_update");
frappe.confirm('Are you sure you want to Publish?',
() => {
// action to perform if Yes is selected
if(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){
frappe.call({
method: 'smart_service.transactions.doctype.publish.publish.cal_ver',
args: {
vehicle: frm.doc.vehicle,
lang:frm.doc.language,
publish_type:frm.doc.publish_type,
doc:frm.doc.name
},
callback: (r) => {
frm.set_value('version',r.message);
cur_frm.refresh_field('version')
// },
// });
// }
if(frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish'){
frappe.call({
method: "smart_service.apis.publish_api.api_procedure",
// async:false,
args: {
"args":frm.doc.name,
"vehicle": frm.doc.vehicle,
"language":frm.doc.language,
"version":frm.doc.version
},
callback: function(r) {
if(r.message != "Failed to save file"){
frm.set_value('publish_status','Published');
frm.set_value('actual_published_date',frappe.datetime.nowdate());
// frm.set_value('published_link',r.message)
frappe.msgprint({
title: __('Notification'),
message: __('Successfully Published' + r.message),
primary_action:{
action(values) {
// frm.save('Update');
// frappe.call({
// method: "smart_service.transactions.doctype.publish.publish.update_procedure",
// // async:false,
// args: {
// vehicle: frm.doc.vehicle,
// lang:frm.doc.language,
// publish_type:frm.doc.publish_type,
// doc:frm.doc.name
// },
// callback: function(r) {
// }
// })
frm.save('Update');
}
}
});
}else{
frappe.msgprint('Publish Failed')
}
}
});
}
},
})
}
}, () => {
// action to perform if No is selected
});
}).addClass("btn-warning").css({'background-color':'#f5b0cd', 'color':'black'});
} else if(frm.doc.publish_status == 'Published'){
frm.set_read_only();
frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);
}
if(frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish'){
frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function() {
var added = 0;
var topublish = [];
if (frm.doc.publish_type =='Global'){topublish = ['Publish Ready'];}else{topublish = ['Review Pending','Publish Ready','Approval Pending'];}
frm.doc.system_mapping.forEach(row => {
if (topublish.indexOf(row.procedure_status) > -1){
var dulicate = false;
if (frm.doc.publish_documents){
frm.doc.publish_documents.forEach(publishrow => {
if (frm.doc.variant_mapping == publishrow.variant_mapping &&
row.systems == publishrow.system &&
row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link){
dulicate = true;
}
});
}
if (dulicate === false){
var child = cur_frm.add_child("publish_documents");
child.variant_mapping = frm.doc.variant_mapping;
child.system = row.systems;
child.sub_system = row.sub_systems;
child.procedure_link = row.procedure;
child.procedure_status = row.procedure_status;
child.update_procedure_status = row.procedure_status;
child.item_category = "System Mapping";
child.variant = frm.doc.variant;
refresh_field("publish_documents");
added += 1;
}
}
});
if (added){frappe.msgprint(__(added + " Doc(s) Added"));}
else{frappe.msgprint(__("No Doc Added"));}
});
// }
frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');
}
if(frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish'){
frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function() {
var added = 0;
var topublish = [];
frm.doc.variant_mapping_assets.forEach(row => {
if (row.active_status == "Active" || row.active_status == "Inactive"){
var dulicate = false;
if (frm.doc.publish_documents){
frm.doc.publish_documents.forEach(publishrow => {
if (frm.doc.variant_mapping == publishrow.variant_mapping &&
row.category == publishrow.asset_category && row.attach_file == publishrow.attach_file){
dulicate = true;
}
});
}
if (dulicate === false){
var child = cur_frm.add_child("publish_documents");
child.variant_mapping = frm.doc.variant_mapping;
child.asset_category = row.category;
child.item_category = "Variant Mapping Assets";
child.variant = frm.doc.variant;
child.attach_file = row.attach_file;
refresh_field("publish_documents");
added += 1;
}
}
});
if (added){frappe.msgprint(__(added + " Doc(s) Added"));}
else{frappe.msgprint(__("No Doc Added"));}
});
frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');
}
if(frm.doc.docstatus == 1){
$(".grid-buttons").hide();
}
},
validate: function(frm) {
if (frm.fields_dict.publish_documents.grid.grid_rows.length === 0){
frappe.msgprint(__("No item selected to Publish"));
frappe.validated = false;
}
if (frm.doc.planned_publish_date < frappe.datetime.get_today()) {
frappe.msgprint(__("<b>Planned Publish Date:</b> You can not select past date"));
frappe.validated = false;
}
},
before_cancel: function(frm) {
if (frm.doc.publish_status == 'Published'){
//frappe.throw(__('You can not <b>cancel</b> a Published Document!'));
//frappe.validated = false;
}
},
variant_mapping:function(frm){
// frappe.show_alert({
// message:__('Please wait until variant mapping details are loaded.'),
// indicator:'yellow'
// }, 5);
frappe.db.get_value('Variant Mapping', { name: frm.doc.variant_mapping }, ['fuel', 'transmission', 'drive'], (r) => {
frm.doc.variant = r.fuel + ',' + r.transmission + ',' + r.drive;
cur_frm.refresh_field('variant');
})
var km_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM";
frappe.db.get_value('Kilometer Mapping', {name: km_name}, 'workflow_state' , (r) =>{
if(r.workflow_state == "Draft"){
frm.doc.kilometer_mapping = '';
frm.doc.variant_mapping = '';
frm.doc.system_mapping = '';
frm.doc.variant_mapping_status = '';
frm.refresh_field('kilometer_mapping');
frm.refresh_field('variant_mapping');
frm.refresh_field('system_mapping');
frappe.msgprint("System Mapping details cannot be loaded due to kilometer mapping in draft state");
frappe.validated = false;
}
else{
if (frm.doc.variant_mapping === undefined) {return;}
frm.set_value('system_mapping', null);
frm.set_value('variant_mapping_assets', null);
frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-KM")
.then(exists => {
if (exists){
frm.set_value("kilometer_mapping",frm.doc.variant_mapping + "-" + frm.doc.language + "-KM");
frm.refresh_field('kilometer_mapping')
} else {
// frm.set_value("kilometer_mapping",null);
frm.set_value("km_active_status","Not Configured!");
}
});
}
})
},
km_active_status:function(frm){
if(frm.doc.variant_mapping){
frappe.show_alert({
message:__('Please wait until variant mapping details are loaded.'),
indicator:'yellow'
}, 5);
}
if(frm.doc.km_active_status === "" || frm.doc.km_active_status === null) {return;}
var filter = frm.doc.variant_mapping + "-" + frm.doc.language + "-SM";
if (frm.doc.variant_mapping_status == "Active" && frm.doc.km_active_status == "Active") {
frappe.call({
"method": "smart_service.transactions.doctype.publish.publish.get_system",
"args": {
"doc": frm.doc.variant_mapping,
"name": filter
},
callback: function(r) {
$.each(r.message, function(index, row) {
var child;
child = cur_frm.add_child("system_mapping");
child.systems = row.systems;
child.sub_systems = row.sub_systems;
child.active_status = row.active_status;
child.symptom = row.symptom;
child.component = row.component;
child.estimate_time = row.estimate_time;
child.rts = row.rts;
child.mat = row.mat;
//child.cover_image = row.cover_image;
child.procedure = row.procedure;
child.procedure_status = row.procedure_status;
cur_frm.refresh_field('system_mapping');
cur_frm.refresh_fields();
})
}
})
frappe.call({
"method": "smart_service.transactions.doctype.publish.publish.get_vm_asset",
"args": {
"doc": frm.doc.variant_mapping,
},
callback: function(r) {
$.each(r.message, function(index, row) {
var child;
child = cur_frm.add_child("variant_mapping_assets");
child.category = row.category;
child.language = row.language;
child.attach_file = row.attach_file;
child.active_status = row.active_status;
cur_frm.refresh_field('variant_mapping_assets');
cur_frm.refresh_fields();
})
}
})
frappe.call({
"method": "smart_service.transactions.doctype.publish.publish.get_sm_asset",
"args": {
"doc": frm.doc.variant_mapping,
"name": filter
},
callback: function(r) {
$.each(r.message, function(index, row) {
var child_row;
child_row = cur_frm.add_child("variant_mapping_assets");
child_row.category = row.systems;
child_row.language = row.language;
child_row.attach_file = row.system_asset;
child_row.active_status = row.active_status;
cur_frm.refresh_field('variant_mapping_assets');
cur_frm.refresh_fields();
})
}
})
/* frappe.db.get_list('System Mapping_Sub System', {
fields: ['systems', 'sub_systems','active_status','symptom','component','estimated_time','rts','mat','procedure','procedure_status'],
filters: { parent: filter,
procedure_is_published: ["=",'0'], }
}).then(records => {
//frm.set_value('system_mapping', null);
var child;
$.each(records, function(index, row){
child = cur_frm.add_child("system_mapping");
child.systems = row.systems;
child.sub_systems = row.sub_systems;
child.active_status = row.active_status;
child.symptom = row.symptom;
child.component = row.component;
child.estimated_time = row.estimated_time;
child.rts = row.rts;
child.mat = row.mat;
//child.cover_image = row.cover_image;
child.procedure = row.procedure;
child.procedure_status = row.procedure_status;
if (row.procedure) {
frappe.call({
"method": "smart_service.transactions.doctype.procedure.procedure.get_doc_status",
"args": {
"docname": row.procedure,
},
async:false,
callback:function(r){
child.procedure_status = r.message; //doc.workflow_state;
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'});}
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'});}
//refresh_field("system_mapping");
}
});
//frappe.db.get_doc('Procedure', row.procedure)
// .then(doc => {
// child.procedure_status = doc.workflow_state;
// 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'});}
// 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'});}
// frm.refresh_field("system_mapping");
// });
}
});
frm.refresh_field('system_mapping');
});
frappe.db.get_list('Variant Mapping_Assets', {
fields: ['category', 'language','active_status','attach_file'],
filters: {
parent: frm.doc.variant_mapping,
language: frm.doc.language,
published: ["=",'0'],
}
}).then(assets => {
var child;
$.each(assets, function(index, row){
//child = cur_frm.add_child("variant_mapping_assets");
// console.log(row.category)
// child.category = row.category;
// child.language = row.language;
//child.attach_file = row.attach_file;
// child.active_status = row.active_status;
});
frappe.db.get_list('System Mapping_System Assets', {
fields: ['systems', 'language','active_status','system_asset'],
filters: {
parent: filter,
published: ["=",'0'],
}
}).then(asset => {
var child_row;
$.each(asset, function(index, row){
child_row = cur_frm.add_child("variant_mapping_assets");
child_row.category = row.systems;
child_row.language = row.language;
child_row.attach_file = row.system_asset;
child_row.active_status = row.active_status;
});
cur_frm.refresh_field('variant_mapping_assets');
})
});*/
} else {
if (frm.doc.variant_mapping_status){
frappe.msgprint({
title: __('Notification'),
indicator: 'red',
message: __('System Mapping & Assets not loaded as the selected Variant/Kilometer Mapping is <b>Inactive or not configured</b>')
});
}
}
},
add_variant_mapping_to_publish:function(frm){
var dulicate = false;
if (frm.doc.publish_documents){
frm.doc.publish_documents.forEach(publishrow => {
if (frm.doc.variant_mapping == publishrow.variant_mapping && publishrow.systems === undefined && publishrow.sub_systems === undefined && publishrow.procedure === undefined){
dulicate = true;
}
});
console.log("first if")
frappe.msgprint("Variant Mapping already added");
}
if (dulicate === false){
console.log("2if")
var child = cur_frm.add_child("publish_documents");
child.variant_mapping = frm.doc.variant_mapping;
child.item_category = "Variant Mapping";
refresh_field("publish_documents");
frappe.msgprint(__(frm.doc.variant_mapping + " Added"));
}
},
km_report: function(frm, cdt, cdn) {
frappe.set_route("query-report", 'Kilometer Mapping', { 'kilometer_mapping': frm.doc.kilometer_mapping });
},
vehicle:function(frm){
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.old_publish",
async:false,
args: {
"vehicle": frm.doc.vehicle,
"language": frm.doc.language
},
callback: function(r) {
if (r.message) {
var vehicle = frm.doc.vehicle;
cur_frm.doc.vehicle = '';
cur_frm.doc.vehicle_status = '';
cur_frm.refresh_field('vehicle');
cur_frm.refresh_field('vehicle_status');
frappe.throw("Already publish record " + r.message + " created for " + vehicle + " vehicle. Please edit already available internal publish!")
}
}
});
if (frm.doc.vehicle === undefined || frm.doc.vehicle === null) {return;}
$("[data-fieldname=variant_mapping]").focus();
if(frm.doc.vehicle){
frm.set_df_property('vehicle', 'read_only', 1);
}
},
language:function(frm){
if (!lang_set_first_time){
frappe.confirm('This will clear all the data, are you sure you want to proceed?',
() => {
// action to perform if Yes is selected
frm.set_value('variant_mapping',null);
frm.set_value('variant_mapping_status',null);
// frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);
frm.set_value('system_mapping', null);
frm.set_value('variant_mapping_assets', null);
frm.set_value('publish_documents', null);
lang_set_first_time = false;
}, () => {
// action to perform if No is selected
});
} else {lang_set_first_time = false;}
},
auto_version_update:function(frm){
if(frm.doc.vehicle && frm.doc.language && frm.doc.publish_type){
frappe.call({
method: 'smart_service.transactions.doctype.publish.publish.cal_ver',
args: {
vehicle: frm.doc.vehicle,
lang:frm.doc.language,
publish_type:frm.doc.publish_type,
doc:frm.doc.name
},
callback: (r) => {
//frm.set_value('version',r.message);
cur_frm.refresh_field('version')
},
error: (r) => {
// on error
}
});
}
},
});

4
smart_service/transactions/doctype/publish/publish.json

@ -57,6 +57,7 @@
"reqd": 1
},
{
"allow_on_submit": 1,
"fieldname": "section_break_5",
"fieldtype": "Section Break"
},
@ -115,6 +116,7 @@
},
{
"allow_bulk_edit": 1,
"allow_on_submit": 1,
"fieldname": "publish_documents",
"fieldtype": "Table",
"label": "Publish Documents",
@ -295,7 +297,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-05-09 18:33:48.793555",
"modified": "2022-05-19 19:00:57.709010",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Publish",

111
smart_service/transactions/doctype/publish/publish.py

@ -20,12 +20,35 @@ class Publish(Document):
self.kilometer_mapping_details = ''
for v in variant:
self.variant_mapping_details = self.variant_mapping_details + str(v) + '\n'
km_mapping_record = frappe.db.sql("""select name from `tabKilometer Mapping` where variant_mapping = %s""",str(v),as_dict=True)
km_mapping_record = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,str(v),self.language),as_dict=True)
for km_mapping in km_mapping_record:
self.kilometer_mapping_details = self.kilometer_mapping_details + str(km_mapping.name) + '\n'
def onload(self):
current_db_name = frappe.conf.get("db_name")
###To validate updated procedure status
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro
where p.parent = '{1}' and p.procedure_link = pro.name and pro.workflow_state != p.procedure_status and p.procedure_link is not null""".format(current_db_name,self.name),as_dict=True)
l = len(procedure_status)
if procedure_status and self.publish_status == "Published":
for x in procedure_status:
for y in self.get("publish_documents"):
if y.procedure_link:
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status:
y.update_procedure_status = x.workflow_state
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where procedure_link = %s""",(x.workflow_state,x.procedure_link))
frappe.db.commit()
if y.procedure_status == "Publish Ready":
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and not y.excluded_global:
y.excluded_global = "1"
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and x.workflow_state == "Draft" and y.procedure_status != "Publish Ready":
y.excluded_internal = "1"
y.save()
frappe.db.commit()
###Update system and variant mapping ststus
if self.publish_status == "Published" and self.publish_type == "Global":
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = '{1}'""".format(current_db_name,self.name),as_dict=True)
for global_name in global_publish:
@ -41,6 +64,7 @@ class Publish(Document):
frappe.db.commit()
def on_cancel(self):
###Published document should not allow to cancel
if self.publish_status == "Published":
frappe.throw('You can not <b>cancel</b> a Published Document!')
@ -71,46 +95,81 @@ class Publish(Document):
# # json.dump(docs_child,f)
# # return json.dump(listProc)
# return docs_child
def update_procedure(vehicle,lang,publish_type,doc):
###To validate updated procedure status
doc = frappe.get_doc("Publish",doc)
current_db_name = frappe.conf.get("db_name")
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro
where p.parent = '{1}' and p.procedure_link = pro.name and pro.workflow_state != p.procedure_status and p.procedure_link is not null""".format(current_db_name,doc.name),as_dict=True)
l = len(procedure_status)
if procedure_status and doc.publish_status == "Published":
for x in procedure_status:
for y in doc.get("publish_documents"):
if y.procedure_link:
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status:
y.update_procedure_status = x.workflow_state
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where procedure_link = %s""",(x.workflow_state,x.procedure_link))
frappe.db.commit()
if y.procedure_status == "Publish Ready":
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and not y.excluded_global:
y.excluded_global = "1"
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and x.workflow_state == "Draft" and y.procedure_status != "Publish Ready":
y.excluded_internal = "1"
y.save()
frappe.db.commit()
if l > 0:
frappe.msgprint(str(l) + ' Procedure Status to be updated, Please check the Publish Documents table.')
if doc.publish_type == "Global":
publish_table = doc.publish_documents
table_len = len(publish_table)
publish_record = frappe.db.sql("""select name from {0}.`tabPublish_Docs` where update_procedure_status != procedure_status and parent = '{1}'""".format(current_db_name,doc.name),as_dict=True)
if publish_record:
len_publish = len(publish_record)
if str(table_len) == str(len_publish):
frappe.throw("There is no item for global publish")
###Generate Publish versions
@frappe.whitelist()
def cal_ver(vehicle,lang,publish_type,doc):
update_procedure(vehicle,lang,publish_type,doc)
current_db_name = frappe.conf.get("db_name")
doc = frappe.get_doc("Publish",doc)
ver = frappe.db.sql("""select max(version),publish_type from {current_db_name}.tabPublish where vehicle = '{vehi}' and language = '{lang}';"""
.format(current_db_name=current_db_name,vehi=vehicle,lang=lang))
v = 0.0
if publish_type == 'Global':
if ver[0][0] == None:
v = 1.0
else:
v= int(float(ver[0][0])) + 1.
v= int(float(ver[0][0])) + 1.0
elif publish_type == 'Internal':
if ver[0][0] == None:
v = 0.1
v = 0.01
else:
v= float(ver[0][0]) + 0.1
v =float("{:.2f}".format(v,1))
v= float(ver[0][0]) + 0.01
#v =float("{:.3f}".format(v,1))
v = "{:.2f}".format(v)
doc.version = v
frappe.db.sql("""update {0}.`tabPublish` set version = '{1}' where name = '{2}'""".format(current_db_name,v,doc.name))
frappe.db.commit()
return v
###Create global publish document for publish ready procedures
@frappe.whitelist()
def global_publish(doc):
doc = frappe.get_doc("Publish",doc)
current_db_name = frappe.conf.get("db_name")
procedure = frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and procedure_status='Publish Ready'""".format(current_db_name,doc.name))
procedure = frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status='Publish Ready'""".format(current_db_name,doc.name))
if not procedure:
frappe.throw("There is no item for global publish")
max_internal_ver = frappe.db.sql('''SELECT max(version) as max_version,name as name FROM {}.tabPublish where vehicle='{}' and language ='{}' and publish_type ='Internal';'''.format(current_db_name,doc.vehicle,doc.language),as_dict=True)
for v in max_internal_ver:
if doc.version < v.max_version:
frappe.throw('Please publish Internal Publish Version ' + v.max_version + ' for ' + v.name)
max_internal_ver = frappe.db.sql('''SELECT max(version) as max_version,name as name,publish_status as p FROM {}.tabPublish where vehicle='{}' and language ='{}' and publish_status = 'To Publish' and publish_type ='Internal';'''.format(current_db_name,doc.vehicle,doc.language),as_dict=True)
if max_internal_ver:
for v in max_internal_ver:
if str(doc.version) < str(v.max_version):
frappe.msgprint('Please publish Internal Publish Version ' + str(v.max_version) + ' for ' + str(v.name))
publish_type = "Global"
publish_record = frappe.new_doc("Publish")
@ -125,14 +184,15 @@ def global_publish(doc):
publish_record.km_active_status = doc.km_active_status
publish_record.variant = doc.variant
for table in doc.get('publish_documents'):
if table.procedure_status == "Publish Ready":
if table.update_procedure_status == "Publish Ready":
publish_table = publish_record.append('publish_documents',{})
publish_table.variant_mapping = table.variant_mapping
publish_table.system = table.system
publish_table.sub_system = table.sub_system
publish_table.procedure_link = table.procedure_link
publish_table.procedure_status = table.procedure_status
publish_record.asset_category = table.asset_category
publish_table.update_procedure_status = table.procedure_status
publish_table.asset_category = table.asset_category
publish_table.item_category = table.item_category
publish_table.variant = table.variant
for asset in doc.get('variant_mapping_assets'):
@ -184,7 +244,7 @@ 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()
###Set filter for latest modified document
@frappe.whitelist()
def get_vm_asset(doc):
doc = frappe.get_doc("Variant Mapping",doc)
@ -198,7 +258,6 @@ def get_sm_asset(doc,name):
doc = frappe.get_doc("System Mapping",s.name)
system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets` where parent = '{1}' and published = '0'""".format(current_db_name,s.name),as_dict=True)
return system_asset
@frappe.whitelist()
def get_system(doc,name):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(current_db_name,doc,name),as_dict=True)
@ -207,3 +266,17 @@ def get_system(doc,name):
doc = frappe.get_doc("System Mapping",s.name)
system = frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True)
return system
@frappe.whitelist()
def max_publish(doc):
doc = frappe.get_doc("Publish",doc)
ver = frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = '{1}' and language = '{2}';""".format(current_db_name,doc.vehicle,doc.language))
if ver:
return ver
@frappe.whitelist()
def variant(doctype, txt, searchfield, start, page_len, filters):
vehicle = filters.get('vehicle')
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status
FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name,vehicle)%{'txt': txt, 'start': start, 'page_len': page_len})

23
smart_service/transactions/doctype/publish/publish_list.js

@ -0,0 +1,23 @@
frappe.listview_settings['Publish'] = frappe.listview_settings['Publish'] || {};
frappe.listview_settings.Publish.formatters = {
publish_status(value){
if(value =="To Publish"){
value='<span class="filterable indicator-pill orange ellipsis">' + value + '</span>';
}
else if(value =="Published"){
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>';
}
return value;
},
publish_type(value){
if(value =="Internal"){
value='<span class="filterable indicator-pill red ellipsis">' + value + '</span>';
}
else if(value =="Global"){
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>';
}
return value;
}
};

28
smart_service/transactions/doctype/system_mapping/system_mapping.js

@ -37,14 +37,14 @@ frappe.ui.form.on('System Mapping', {
});
frm.trigger('fnLoadmat_initial_values');
if (frm.doc.kilometer_mapping !== undefined){
frappe.db.get_doc('Kilometer Mapping', frm.doc.kilometer_mapping)
.then(doc => {
// frm.set_value("km_active_status",doc.active_status);
refresh_field("km_active_status");
});
// if (frm.doc.kilometer_mapping !== undefined){
// frappe.db.get_doc('Kilometer Mapping', frm.doc.kilometer_mapping)
// .then(doc => {
// // frm.set_value("km_active_status",doc.active_status);
// refresh_field("km_active_status");
// });
}
// }
},
validate: function(frm){
if (frm.is_new()) {
@ -203,7 +203,7 @@ frappe.ui.form.on('System Mapping', {
valueToPush.idx = row.idx;
valueToPush.sub_systems = row.sub_systems;
valueToPush.procedure_status = row.procedure_status;
valueToPush.procedure_is_published = row.procedure_is_published;
// valueToPush.procedure_is_published = row.procedure_is_published;
mat_array.push(valueToPush);
});
}
@ -306,7 +306,7 @@ frappe.ui.form.on('System Mapping', {
frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-KM")
.then(exists => {
if (exists){
frm.set_value("kilometer_mapping",frm.doc.variant_mapping + "-" + frm.doc.language + "-KM");
// frm.set_value("kilometer_mapping",frm.doc.variant_mapping + "-" + frm.doc.language + "-KM");
} else {
// frm.set_value("kilometer_mapping",null);
// frm.set_value("km_active_status","Not Configured!");
@ -566,8 +566,8 @@ function fn_mat_updated(frm,cdt,cdn){
if (mat_array[index].mat_initial === null){
mat_array[index].type = "Initial";
if (mat_array[index].procedure_is_published){
row.doc.procedure_status = "Published";
row.doc.procedure_is_published = 1;
// row.doc.procedure_status = "Published";
// row.doc.procedure_is_published = 1;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
row.toggle_editable_row(false);
}
@ -589,8 +589,8 @@ function fn_mat_updated(frm,cdt,cdn){
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
if (mat_array[index].procedure_is_published){
row.doc.procedure_status = "Published";
row.doc.procedure_is_published = 1;
// row.doc.procedure_status = "Published";
// row.doc.procedure_is_published = 1;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
row.toggle_editable_row(false);
}
@ -612,7 +612,7 @@ function fn_mat_updated(frm,cdt,cdn){
valueToPush.systems = row.doc.systems;
valueToPush.sub_systems = row.doc.sub_systems;
valueToPush.procedure_status = row.doc.procedure_status;
valueToPush.procedure_is_published = row.doc.procedure_is_published;
// valueToPush.procedure_is_published = row.doc.procedure_is_published;
mat_array.push(valueToPush);
}
// refresh_field("system_sub_systems");

3
smart_service/transactions/doctype/system_mapping/system_mapping.json

@ -154,6 +154,7 @@
"fieldtype": "Column Break"
},
{
"depends_on": "eval:doc.kilometer_mapping",
"fetch_from": "kilometer_mapping.active_status",
"fieldname": "km_active_status",
"fieldtype": "Data",
@ -171,7 +172,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-03-09 07:27:14.241806",
"modified": "2022-05-23 12:36:15.963982",
"modified_by": "Administrator",
"module": "Transactions",
"name": "System Mapping",

5
smart_service/transactions/doctype/system_mapping/system_mapping.py

@ -24,11 +24,12 @@ class SystemMapping(Document):
self.km_active_status = status.active_status
def validate(self):
###On creation of System Mapping to create Kilometer Mapping record
km = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}'""".format(current_db_name,self.variant_mapping),as_list=True)
km = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,self.variant_mapping,self.language),as_list=True)
if not km:
mat = []
km_record = frappe.new_doc("Kilometer Mapping")
km_record.variant_mapping = self.variant_mapping
km_record.language = self.language
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = '{1}' order by service_kilometers""".format(current_db_name,self.vehicle),as_dict=True)
for service_km in vehicle_sk:
for sys in self.get('system_sub_systems'):
@ -41,7 +42,7 @@ class SystemMapping(Document):
sub_system.sub_systems = sys.sub_systems
sub_system.applicable = 0
mat.append(sys.mat)
km_record.insert(ignore_permissions = True)
km_record.save(ignore_permissions = True)
self.kilometer_mapping = km_record.name
###Should not allow duplicate mat code value
mat_code = []

70
smart_service/transactions/doctype/variant_mapping/variant_mapping.js

@ -1,7 +1,71 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('Variant Mapping', {
//refresh: function(frm) {
// }
cur_frm.fields_dict['variant'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.variant",
}
}
cur_frm.fields_dict['fuel'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.fuel",
}
}
cur_frm.fields_dict['transmission'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.transmission",
}
}
cur_frm.fields_dict['drive'].get_query = function(doc, cdt, cdn) {
return {
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.drive",
}
}
frappe.ui.form.on('Variant Mapping', {
onload: function(frm) {
if (frm.doc.workflow_state == "Publish Ready"){
frm.set_read_only();
}
},
refresh: function(frm) {
if (frm.doc.workflow_state == "Publish Ready" && frappe.user_roles.indexOf("_Admin") > 0){
frm.add_custom_button(__('Revoke Publish'), function(){
//get all system mapping with the procedure linked
frappe.warn('Confirm','Are you sure you want to Revoke?',
() => {
frm.set_value("workflow_state","Draft");
frm.save();
// action to perform if Continue is selected
},
'Continue', false // Sets dialog as minimizable
);
});
}
}
});
function compare(a, b) {
if (parseInt(a.service_kilometers) < parseInt(b.service_kilometers)){return -1;}
if (parseInt(a.service_kilometers) > parseInt(b.service_kilometers)){return 1;}
return 0;
}
frappe.ui.form.on('Variant Mapping', 'variant1', function(frm) {
frm.set_value('service_kilometers', null);
frappe.db.get_list('Vehicle_SK', {
fields: ['service_kilometers'],
filters: { parent: frm.doc.vehicle }
}).then(records => {
var child;
records.sort(compare);
$.each(records, function(index, row){
child = cur_frm.add_child("service_kilometers");
//frappe.model.set_value(child.doctype, child.name, "service_kilometers", row.service_kilometers);
child.service_kilometers = row.service_kilometers;
});
cur_frm.refresh_field('service_kilometers');
});
});
Loading…
Cancel
Save