@ -10,35 +10,25 @@ cur_frm.fields_dict['variant_mapping'].get_query = function (doc, cdt, cdn) {
}
}
} ;
} ;
} ;
} ;
var selected_module = ''
var selected_module = ''
cur_frm . fields_dict [ 'vehicle' ] . get_query = function ( doc , cdt , cdn ) {
cur_frm . fields_dict [ 'vehicle' ] . get_query = function ( doc , cdt , cdn ) {
return { query : "smart_service.masters.doctype.vehicle.vehicle.vehicle_filter" , } ;
return { query : "smart_service.masters.doctype.vehicle.vehicle.vehicle_filter" , } ;
} ;
} ;
let lang_set_first_time = true ;
let lang_set_first_time = true ;
frappe . ui . form . on ( 'Publish Test' , {
frappe . ui . form . on ( 'Publish Test' , {
// publish_module:function(frm){
// if(frm.doc.publish_module=='Automotive'){
// selected_module=1
// }
// else{
// selected_module=0
// }
// },
onload : function ( frm ) {
onload : function ( frm ) {
// $('[data-route="Form/Publish Test/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish")
// $('[data-route="Form/Publish Test/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish")
if ( frm . doc . docstatus == 0 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module == 'Others' ) {
if ( frm . doc . docstatus == 0 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module == 'Others' ) {
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Internal Publish" )
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Internal Publish" )
}
}
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" && frm . doc . publish_module == 'Others' ) {
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" && frm . doc . publish_module == 'Others' ) {
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
}
}
if ( frm . doc . status = "Published" && frm . doc . publish_module == 'Others' ) {
if ( frm . doc . status = "Published" && frm . doc . publish_module == 'Others' ) {
frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
frm . refresh_field ( 'repair_checksheet_publish' )
frm . refresh_field ( 'repair_checksheet_publish' )
@ -86,252 +76,252 @@ frappe.ui.form.on('Publish Test', {
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" ) {
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" ) {
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
$ ( '[data-route="Form/Publish Test/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
}
}
if ( frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . publish_module == 'Automotive' ) {
cur_frm . set_df_property ( 'system_mapping' , "read_only" , 1 ) ;
cur_frm . set_df_property ( 'system_mapping' , "read_only" , 1 ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . system_mapping . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . system_mapping . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . variant_mapping_assets . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
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-all-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete_all_rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-move-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . publish_documents . grid . wrapper . find ( '.grid-append-row' ) . 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' } ) ;
}
}
}
} )
}
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
if ( frm . doc . docstatus === 1 && frm . doc . publish_status == 'To Publish' && frappe . user . has_role ( '_Publisher' ) ) {
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
frm . add_custom_button ( __ ( 'Publish' ) , function ( ) {
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
frappe . confirm ( 'Are you sure you want to Publish?' ,
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
( ) => {
frm . fields_dict . variant_mapping_assets . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
// action to perform if Yes is selected
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type ) {
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-all-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete_all_rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-move-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . publish_documents . grid . wrapper . find ( '.grid-append-row' ) . 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 ( {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.global_publish" ,
method : 'smart_service.transactions.doctype.publish.publish.cal_ver' ,
args : {
args : {
"doc" : frm . doc . name ,
vehicle : frm . doc . vehicle ,
lang : frm . doc . language ,
publish_type : frm . doc . publish_type ,
doc : frm . doc . name
} ,
} ,
callback : function ( r ) {
callback : ( r ) => {
cur_frm . reload_doc ( ) ;
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",
method : "smart_service.apis.publish_api.new_publish" ,
args : {
"args" : frm . doc . name ,
"publish_type" : frm . doc . publish_type ,
"vehicle" : frm . doc . vehicle ,
"language" : frm . doc . language ,
"version" : frm . doc . version
} ,
callback : function ( r ) {
// if (r.message[0]) {
frm . set_value ( 'publish_status' , 'Published' ) ;
frm . page . clear_primary_action ( "Publish" ) ;
frm . set_value ( 'actual_published_date' , frappe . datetime . nowdate ( ) ) ;
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.update_procedure_value" ,
args : {
"name" : frm . doc . name ,
"file_path" : r . message [ 1 ] ,
} ,
callback : ( r ) => {
// frm.save('Update');
}
} )
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
message : __ ( '<b>Successfully Published:</b> ' + r . message [ 1 ] ) ,
primary_action : {
action ( values ) {
frm . save ( 'Update' ) ;
}
}
} ) ;
// }
// else {
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Not Successfully Published:</b> ' + r.message[1]),
// // primary_action: {
// // action(values) {
// // frm.save('Update');
// // }
// // }
// });
// }
// if (r.message != "Failed to save file") {
// frm.set_value('publish_status', 'Published');
// frm.set_value('actual_published_date', frappe.datetime.nowdate());
// frappe.call({
// method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
// args: {
// "name": frm.doc.name,
// "file_path": r.message,
// },
// callback: (r) => {
// // frm.save('Update');
// }
// })
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Successfully Published:</b> ' + r.message),
// primary_action: {
// action(values) {
// 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 ( ) {
let added = 0 ;
let 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 ) {
let 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 ;
}
}
} ) ;
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
}
if ( dulicate === false ) {
let 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 === 1 && frm . doc . publish_status == 'To Publish' && frappe . user . has_role ( '_Publisher' ) ) {
}
frm . add_custom_button ( __ ( 'Publish' ) , function ( ) {
if ( frm . doc . docstatus === 0 && frm . doc . publish_status == 'To Publish' ) {
frappe . confirm ( 'Are you sure you want to Publish?' ,
frm . get_field ( 'variant_mapping_assets' ) . grid . add_custom_button ( __ ( 'Add to Publish' ) , function ( ) {
( ) => {
let added = 0 ;
// action to perform if Yes is selected
frm . doc . variant_mapping_assets . forEach ( row => {
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type ) {
if ( row . active_status == "Active" || row . active_status == "Inactive" ) {
frappe . call ( {
let dulicate = false ;
method : 'smart_service.transactions.doctype.publish.publish.cal_ver' ,
if ( frm . doc . publish_documents ) {
args : {
frm . doc . publish_documents . forEach ( publishrow => {
vehicle : frm . doc . vehicle ,
if ( frm . doc . variant_mapping == publishrow . variant_mapping &&
lang : frm . doc . language ,
row . category == publishrow . asset_category && row . attach_file == publishrow . attach_file ) {
publish_type : frm . doc . publish_type ,
dulicate = true ;
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",
method : "smart_service.apis.publish_api.new_publish" ,
args : {
"args" : frm . doc . name ,
"publish_type" : frm . doc . publish_type ,
"vehicle" : frm . doc . vehicle ,
"language" : frm . doc . language ,
"version" : frm . doc . version
} ,
callback : function ( r ) {
// if (r.message[0]) {
frm . set_value ( 'publish_status' , 'Published' ) ;
frm . page . clear_primary_action ( "Publish" ) ;
frm . set_value ( 'actual_published_date' , frappe . datetime . nowdate ( ) ) ;
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.update_procedure_value" ,
args : {
"name" : frm . doc . name ,
"file_path" : r . message [ 1 ] ,
} ,
callback : ( r ) => {
// frm.save('Update');
}
} )
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
message : __ ( '<b>Successfully Published:</b> ' + r . message [ 1 ] ) ,
primary_action : {
action ( values ) {
frm . save ( 'Update' ) ;
}
}
} ) ;
// }
// else {
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Not Successfully Published:</b> ' + r.message[1]),
// // primary_action: {
// // action(values) {
// // frm.save('Update');
// // }
// // }
// });
// }
// if (r.message != "Failed to save file") {
// frm.set_value('publish_status', 'Published');
// frm.set_value('actual_published_date', frappe.datetime.nowdate());
// frappe.call({
// method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
// args: {
// "name": frm.doc.name,
// "file_path": r.message,
// },
// callback: (r) => {
// // frm.save('Update');
// }
// })
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Successfully Published:</b> ' + r.message),
// primary_action: {
// action(values) {
// frm.save('Update');
// }
// }
// });
// } else {
// frappe.msgprint('Publish Failed')
// }
}
} ) ;
}
}
} ,
} ) ;
} )
}
if ( dulicate === false ) {
let 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 ;
}
}
}
} , ( ) => {
// action to perform if No is selected
} ) ;
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
if ( added ) { frappe . msgprint ( __ ( added + " Doc(s) Added" ) ) ; }
} else if ( frm . doc . publish_status == 'Published' ) {
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
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 ( ) {
let added = 0 ;
let 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 ) {
let 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 ) {
let 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" ) ) ; }
frm . fields_dict . variant_mapping_assets . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
}
} ) ;
if ( frm . doc . docstatus == 1 ) {
frm . fields_dict . system_mapping . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
$ ( ".grid-buttons" ) . hide ( ) ;
}
}
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 ( ) {
let added = 0 ;
frm . doc . variant_mapping_assets . forEach ( row => {
if ( row . active_status == "Active" || row . active_status == "Inactive" ) {
let 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 ) {
let 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 ( ) ;
}
if ( frm . doc . docstatus == 1 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module == 'Others' ) {
}
if ( frm . doc . docstatus == 1 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module == 'Others' ) {
frm . add_custom_button ( __ ( 'Global Publish' ) , function ( ) {
frm . add_custom_button ( __ ( 'Global Publish' ) , function ( ) {
frappe . call ( {
frappe . call ( {
method : "smart_service.phase_2.doctype.publish_test.publish_test.generate_global_publish" ,
method : "smart_service.phase_2.doctype.publish_test.publish_test.generate_global_publish" ,
@ -340,7 +330,7 @@ frappe.ui.form.on('Publish Test', {
} ,
} ,
callback : function ( r ) {
callback : function ( r ) {
if ( r . message . status == "success" ) {
if ( r . message . status == "success" ) {
window . location . href = r . message . url + "/app/publish-test" + "/" + r . message . message
window . location . href = r . message . url + "/app/publish-test" + "/" + r . message . message
}
}
}
}
@ -348,62 +338,17 @@ frappe.ui.form.on('Publish Test', {
} ) . addClass ( "btn-primary" ) ;
} ) . addClass ( "btn-primary" ) ;
}
}
// if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher') && frm.doc.publish_module=='Others') {
// frm.add_custom_button(__('Global Publish'), function () {
// 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.phase_2.doctype.publish_test.publish_test.repair_checksheet_publish',
// args: {
// vehicle: frm.doc.vehicle,
// language: frm.doc.language,
// publish_type: frm.doc.publish_type,
// release_description:frm.doc.release_description,
// vehicle_id:frm.doc.vehicle_id,
// variant:frm.doc.variant_mapping
// },
// callback: (r) => {
// if(r.message[0]==1){
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Successfully Published:</b> ' + r.message[1]),
// primary_action: {
// action(values) {
// frm.save('Update');
// }
// }
// });
// }
// },
// })
// }
// }, () => {
// // 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);
// }
} ,
} ,
validate : function ( frm ) {
validate : function ( frm ) {
if ( frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . publish_module == 'Automotive' ) {
let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/ ;
let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/ ;
if ( regex . test ( frm . doc . release_description ) === true ) {
if ( regex . test ( frm . doc . release_description ) === true ) {
frm . doc . release_description = '' ;
frm . doc . release_description = '' ;
frm . refresh_fields ( ) ;
frm . refresh_fields ( ) ;
frappe . msgprint ( __ ( "<b>Publish Description:</b> Only letters, numbers and <b> / - () & , ' : </b> are allowed." ) ) ;
frappe . msgprint ( __ ( "<b>Publish Description:</b> Only letters, numbers and <b> / - () & , ' : </b> are allowed." ) ) ;
}
}
if ( frm . doc . vehicle && frm . doc . release_description && frm . fields_dict . publish_documents . grid . grid_rows . length === 0 ) {
if ( frm . doc . vehicle && frm . doc . release_description && frm . fields_dict . publish_documents . grid . grid_rows . length === 0 ) {
frappe . msgprint ( __ ( "No item selected to Publish" ) ) ;
frappe . msgprint ( __ ( "No item selected to Publish" ) ) ;
frappe . validated = false ;
frappe . validated = false ;
@ -415,9 +360,9 @@ frappe.ui.form.on('Publish Test', {
}
}
//check for atleast one data to publish
//check for atleast one data to publish
if ( frm . doc . publish_module == 'Others' && ! frm . doc . hasOwnProperty ( 'repair_checksheet_publish' ) ) {
if ( frm . doc . publish_module == 'Others' && ! frm . doc . hasOwnProperty ( 'repair_checksheet_publish' ) ) {
frappe . throw ( 'No Data Found To Publish' )
frappe . throw ( 'No Data Found To Publish' )
}
}
} ,
} ,
@ -459,7 +404,7 @@ frappe.ui.form.on('Publish Test', {
} ,
} ,
km_active_status : function ( frm ) {
km_active_status : function ( frm ) {
if ( frm . doc . variant_mapping && frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . variant_mapping && frm . doc . publish_module == 'Automotive' ) {
frappe . show_alert ( {
frappe . show_alert ( {
message : __ ( 'Please wait until variant mapping details are loaded.' ) ,
message : __ ( 'Please wait until variant mapping details are loaded.' ) ,
indicator : 'yellow'
indicator : 'yellow'
@ -467,7 +412,7 @@ frappe.ui.form.on('Publish Test', {
}
}
if ( frm . doc . km_active_status === "" || frm . doc . km_active_status === null ) { return ; }
if ( frm . doc . km_active_status === "" || frm . doc . km_active_status === null ) { return ; }
let filter = frm . doc . variant_mapping + "-" + frm . doc . language + "-SM" ;
let filter = frm . doc . variant_mapping + "-" + frm . doc . language + "-SM" ;
if ( frm . doc . variant_mapping_status == "Active" && frm . doc . km_active_status == "Active" && frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . variant_mapping_status == "Active" && frm . doc . km_active_status == "Active" && frm . doc . publish_module == 'Automotive' ) {
frappe . call ( {
frappe . call ( {
"method" : "smart_service.transactions.doctype.publish.publish.get_system" ,
"method" : "smart_service.transactions.doctype.publish.publish.get_system" ,
"args" : {
"args" : {
@ -540,7 +485,7 @@ frappe.ui.form.on('Publish Test', {
} )
} )
} else {
} else {
if ( frm . doc . variant_mapping_status && frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . variant_mapping_status && frm . doc . publish_module == 'Automotive' ) {
frappe . msgprint ( {
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
title : __ ( 'Notification' ) ,
indicator : 'red' ,
indicator : 'red' ,
@ -551,7 +496,7 @@ frappe.ui.form.on('Publish Test', {
} ,
} ,
add_variant_mapping_to_publish : function ( frm ) {
add_variant_mapping_to_publish : function ( frm ) {
let dulicate = false ;
let dulicate = false ;
if ( frm . doc . publish_documents && frm . doc . publish_module == 'Automotive' ) {
if ( frm . doc . publish_documents && frm . doc . publish_module == 'Automotive' ) {
frm . doc . publish_documents . forEach ( publishrow => {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping && publishrow . systems === undefined && publishrow . sub_systems === undefined && publishrow . procedure === undefined ) {
if ( frm . doc . variant_mapping == publishrow . variant_mapping && publishrow . systems === undefined && publishrow . sub_systems === undefined && publishrow . procedure === undefined ) {
dulicate = true ;
dulicate = true ;
@ -559,7 +504,7 @@ frappe.ui.form.on('Publish Test', {
} ) ;
} ) ;
frappe . msgprint ( "Variant Mapping already added" ) ;
frappe . msgprint ( "Variant Mapping already added" ) ;
}
}
if ( dulicate === false && frm . doc . publish_module == 'Automotive' ) {
if ( dulicate === false && frm . doc . publish_module == 'Automotive' ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . variant_mapping = frm . doc . variant_mapping ;
child . item_category = "Variant Mapping" ;
child . item_category = "Variant Mapping" ;
@ -570,8 +515,8 @@ frappe.ui.form.on('Publish Test', {
km_report : function ( frm , cdt , cdn ) {
km_report : function ( frm , cdt , cdn ) {
frappe . set_route ( "query-report" , 'Kilometer Mapping' , { 'kilometer_mapping' : frm . doc . kilometer_mapping } ) ;
frappe . set_route ( "query-report" , 'Kilometer Mapping' , { 'kilometer_mapping' : frm . doc . kilometer_mapping } ) ;
} ,
} ,
after_save : function ( frm ) {
after_save : function ( frm ) {
frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
frm . refresh_field ( 'repair_checksheet_publish' )
frm . refresh_field ( 'repair_checksheet_publish' )
} ,
} ,
@ -596,29 +541,29 @@ frappe.ui.form.on('Publish Test', {
}
}
} ) ;
} ) ;
if ( frm . doc . vehicle === undefined || frm . doc . vehicle === null && frm . doc . publish_module == 'Automotive' ) { return ; }
if ( frm . doc . vehicle === undefined || frm . doc . vehicle === null && frm . doc . publish_module == 'Automotive' ) { return ; }
$ ( "[data-fieldname=variant_mapping]" ) . focus ( ) ;
$ ( "[data-fieldname=variant_mapping]" ) . focus ( ) ;
if ( frm . doc . vehicle ) {
if ( frm . doc . vehicle ) {
frm . set_df_property ( 'vehicle' , 'read_only' , 1 ) ;
frm . set_df_property ( 'vehicle' , 'read_only' , 1 ) ;
}
}
//other modules-Repair Checksheet
//other modules-Repair Checksheet
if ( frm . doc . publish_module == 'Others' ) {
if ( frm . doc . publish_module == 'Others' ) {
if ( frm . doc . repair_checksheet_publish && frm . doc . repair_checksheet_publish . length > 0 ) {
if ( frm . doc . repair_checksheet_publish && frm . doc . repair_checksheet_publish . length > 0 ) {
content_flag = 1
content_flag = 1
cur_frm . clear_table ( "repair_checksheet_publish" ) ;
cur_frm . clear_table ( "repair_checksheet_publish" ) ;
cur_frm . refresh_fields ( 'repair_checksheet_publish' ) ;
cur_frm . refresh_fields ( 'repair_checksheet_publish' ) ;
}
}
add_to_publish ( frm )
add_to_publish ( frm )
}
}
} ,
} ,
language : function ( frm ) {
language : function ( frm ) {
if ( frm . doc . publish_module == 'Others' ) {
if ( frm . doc . publish_module == 'Others' ) {
add_to_publish ( frm )
add_to_publish ( frm )
}
}
if ( ! lang_set_first_time ) {
if ( ! lang_set_first_time ) {
frappe . confirm ( 'This will clear all the data, are you sure you want to proceed?' ,
frappe . confirm ( 'This will clear all the data, are you sure you want to proceed?' ,
@ -633,7 +578,7 @@ frappe.ui.form.on('Publish Test', {
} , ( ) => {
} , ( ) => {
// action to perform if No is selected
// action to perform if No is selected
} ) ;
} ) ;
} else { lang_set_first_time = false ; }
} else { lang_set_first_time = false ; }
} ,
} ,
auto_version_update : function ( frm ) {
auto_version_update : function ( frm ) {
@ -669,13 +614,13 @@ frappe.ui.form.on('Publish_Temp Doc', {
} ,
} ,
} )
} )
function add_to_publish ( frm ) {
function add_to_publish ( frm ) {
frappe . call ( {
frappe . call ( {
method : "smart_service.phase_2.doctype.publish_test.publish_test.get_service_repair" ,
method : "smart_service.phase_2.doctype.publish_test.publish_test.get_service_repair" ,
args : { vehicle : frm . doc . vehicle , language_label : frm . doc . language , publish_type : frm . doc . publish_type } ,
args : { vehicle : frm . doc . vehicle , language_label : frm . doc . language , publish_type : frm . doc . publish_type } ,
callback : function ( r ) {
callback : function ( r ) {
if ( r . message ) {
if ( r . message ) {
cur_frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
cur_frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
var records = r . message
var records = r . message
debugger
debugger
records . map ( v => {
records . map ( v => {
@ -691,7 +636,7 @@ function add_to_publish(frm){
childTable . my_id = v [ 'my_id' ] ;
childTable . my_id = v [ 'my_id' ] ;
childTable . lang_myid = v [ 'lang_myid' ] ;
childTable . lang_myid = v [ 'lang_myid' ] ;
} )
} )
cur_frm . refresh_fields ( "repair_checksheet_publish" ) ;
cur_frm . refresh_fields ( "repair_checksheet_publish" ) ;
}
}
}
}