Browse Source

Publish variant trigger for refresh

master
administrator 11 months ago
parent
commit
3525146992
  1. 265
      smart_service/transactions/doctype/publish/publish.js
  2. 3
      smart_service/transactions/doctype/publish/publish.py

265
smart_service/transactions/doctype/publish/publish.js

@ -99,6 +99,7 @@ frappe.ui.form.on('Publish', {
frappe.confirm('Are you sure you want to Publish?', frappe.confirm('Are you sure you want to Publish?',
() => { () => {
// action to perform if Yes is selected // action to perform if Yes is selected
frm.remove_custom_button('Publish')
if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type) { if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type) {
frappe.call({ frappe.call({
method: 'smart_service.transactions.doctype.publish.publish.cal_ver', method: 'smart_service.transactions.doctype.publish.publish.cal_ver',
@ -110,7 +111,12 @@ frappe.ui.form.on('Publish', {
}, },
callback: (r) => { callback: (r) => {
frm.set_value('version', r.message); frm.set_value('version', r.message);
cur_frm.refresh_field('version') cur_frm.refresh_field('version');
frm.doc.publish_status = 'Published';
frm.set_value('publish_status', 'Published');
cur_frm.refresh_field('publish_status');
frm.set_value('actual_published_date', frappe.datetime.nowdate());
cur_frm.refresh_field('actual_published_date');
if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish') { if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish') {
frappe.call({ frappe.call({
// method: "smart_service.apis.publish_api.api_procedure", // method: "smart_service.apis.publish_api.api_procedure",
@ -124,9 +130,10 @@ frappe.ui.form.on('Publish', {
}, },
callback: function (r) { callback: function (r) {
// if (r.message[0]) { // 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({ frappe.call({
method: "smart_service.transactions.doctype.publish.publish.update_procedure_value", method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
args: { args: {
@ -135,6 +142,10 @@ frappe.ui.form.on('Publish', {
}, },
callback: (r) => { callback: (r) => {
// frm.save('Update'); // frm.save('Update');
frm.refresh_field('publish_status');
frm.refresh()
cur_frm.reload_doc();
frm.remove_custom_button('Publish')
} }
}) })
frappe.msgprint({ frappe.msgprint({
@ -142,7 +153,7 @@ frappe.ui.form.on('Publish', {
message: __('<b>Successfully Published:</b> ' + r.message[1]), message: __('<b>Successfully Published:</b> ' + r.message[1]),
primary_action: { primary_action: {
action(values) { action(values) {
frm.save('Update'); // frm.save('Update');
} }
} }
}); });
@ -188,6 +199,10 @@ frappe.ui.form.on('Publish', {
} }
}); });
} }
// cur_frm.reload_doc();
frm.remove_custom_button('Publish')
frm.refresh_field('publish_status');
}, },
}) })
} }
@ -200,81 +215,81 @@ frappe.ui.form.on('Publish', {
frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1); frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);
} }
if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') { // if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') {
frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function () { // frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function () {
let added = 0; // let added = 0;
let topublish = []; // let topublish = [];
if (frm.doc.publish_type == 'Global') { topublish = ['Publish Ready']; } else { topublish = ['Review Pending', 'Publish Ready', 'Approval Pending']; } // if (frm.doc.publish_type == 'Global') { topublish = ['Publish Ready']; } else { topublish = ['Review Pending', 'Publish Ready', 'Approval Pending']; }
frm.doc.system_mapping.forEach(row => { // frm.doc.system_mapping.forEach(row => {
if (topublish.indexOf(row.procedure_status) > -1) { // if (topublish.indexOf(row.procedure_status) > -1) {
let dulicate = false; // let dulicate = false;
if (frm.doc.publish_documents) { // if (frm.doc.publish_documents) {
frm.doc.publish_documents.forEach(publishrow => { // frm.doc.publish_documents.forEach(publishrow => {
if (frm.doc.variant_mapping == publishrow.variant_mapping && // if (frm.doc.variant_mapping == publishrow.variant_mapping &&
row.systems == publishrow.system && // row.systems == publishrow.system &&
row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link) { // row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link) {
dulicate = true; // dulicate = true;
} // }
}); // });
} // }
if (dulicate === false) { // if (dulicate === false) {
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.system = row.systems; // child.system = row.systems;
child.sub_system = row.sub_systems; // child.sub_system = row.sub_systems;
child.procedure_link = row.procedure; // child.procedure_link = row.procedure;
child.procedure_status = row.procedure_status; // child.procedure_status = row.procedure_status;
child.update_procedure_status = row.procedure_status; // child.update_procedure_status = row.procedure_status;
child.item_category = "System Mapping"; // child.item_category = "System Mapping";
child.variant = frm.doc.variant; // child.variant = frm.doc.variant;
refresh_field("publish_documents"); // refresh_field("publish_documents");
added += 1; // added += 1;
} // }
} // }
}); // });
if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } // if (added) { frappe.msgprint(__(added + " Doc(s) Added")); }
else { frappe.msgprint(__("No Doc Added")); } // else { frappe.msgprint(__("No Doc Added")); }
}); // });
frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); // 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') { // 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 () { // frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function () {
let added = 0; // let added = 0;
frm.doc.variant_mapping_assets.forEach(row => { // frm.doc.variant_mapping_assets.forEach(row => {
if (row.active_status == "Active" || row.active_status == "Inactive") { // if (row.active_status == "Active" || row.active_status == "Inactive") {
let dulicate = false; // let dulicate = false;
if (frm.doc.publish_documents) { // if (frm.doc.publish_documents) {
frm.doc.publish_documents.forEach(publishrow => { // frm.doc.publish_documents.forEach(publishrow => {
if (frm.doc.variant_mapping == publishrow.variant_mapping && // if (frm.doc.variant_mapping == publishrow.variant_mapping &&
row.category == publishrow.asset_category && row.attach_file == publishrow.attach_file) { // row.category == publishrow.asset_category && row.attach_file == publishrow.attach_file) {
dulicate = true; // dulicate = true;
} // }
}); // });
} // }
if (dulicate === false) { // if (dulicate === false) {
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.asset_category = row.category; // child.asset_category = row.category;
child.item_category = "Variant Mapping Assets"; // child.item_category = "Variant Mapping Assets";
child.variant = frm.doc.variant; // child.variant = frm.doc.variant;
child.attach_file = row.attach_file; // child.attach_file = row.attach_file;
refresh_field("publish_documents"); // refresh_field("publish_documents");
added += 1; // added += 1;
} // }
} // }
}); // });
if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } // if (added) { frappe.msgprint(__(added + " Doc(s) Added")); }
else { frappe.msgprint(__("No Doc 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'); // frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');
} // }
if (frm.doc.docstatus == 1) { // if (frm.doc.docstatus == 1) {
$(".grid-buttons").hide(); // $(".grid-buttons").hide();
} // }
}, },
validate: function (frm) { validate: function (frm) {
let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/; let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/;
@ -328,7 +343,7 @@ frappe.ui.form.on('Publish', {
}); });
} }
}) })
validate_systems(frm);
}, },
km_active_status: function (frm) { km_active_status: function (frm) {
if (frm.doc.variant_mapping) { if (frm.doc.variant_mapping) {
@ -517,3 +532,91 @@ frappe.ui.form.on('Publish_Temp Doc', {
frm.fields_dict.system_mapping.grid.wrapper.find('.grid-insert-row').hide(); frm.fields_dict.system_mapping.grid.wrapper.find('.grid-insert-row').hide();
}, },
}) })
function validate_systems(frm){
if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') {
cur_frm.get_field("system_mapping").grid.wrapper.find('.btn-custom').show();
refresh_field("system_mapping");
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;
}
}
cur_frm.get_field("system_mapping").grid.wrapper.find('.btn-custom').hide();
refresh_field("system_mapping");
});
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') {
cur_frm.get_field("variant_mapping_assets").grid.wrapper.find('.btn-custom').show();
refresh_field("variant_mapping_assets");
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;
}
}
cur_frm.get_field("variant_mapping_assets").grid.wrapper.find('.btn-custom').hide();
refresh_field("variant_mapping_assets");
});
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();
}
}

3
smart_service/transactions/doctype/publish/publish.py

@ -181,8 +181,11 @@ def cal_ver(vehicle, lang, publish_type, doc):
v = float(ver[0][0]) + 0.01 v = float(ver[0][0]) + 0.01
v = "{:.2f}".format(v) v = "{:.2f}".format(v)
doc.version = v doc.version = v
doc.publish_status = 'Published'
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format( frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name)) current_db_name, v, doc.name))
frappe.db.sql("""update {0}.`tabPublish` set publish_status = "Published" where name = "{1}";""".format(
current_db_name, doc.name))
frappe.db.commit() frappe.db.commit()
return v return v

Loading…
Cancel
Save