Browse Source

Kilometer mapping duplicat feature

master
venkataakhil 1 year ago
parent
commit
107fde3738
  1. 120
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  2. 16
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

120
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js

@ -56,6 +56,67 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
validate: function (frm) { validate: function (frm) {
// //custom button
// frm.add_custom_button(__("Duplicate Data"), function () {
// let d = new frappe.ui.Dialog({
// title: 'Choose the variant',
// fields: [
// {
// label: 'Variant',
// fieldname: 'variant',
// fieldtype: 'Link',
// options: "Kilometer Mapping"
// },
// {
// label: '',
// fieldname: 'content_html',
// fieldtype: 'HTML',
// },
// ],
// size: 'small',
// secondary_action_label: "No",
// primary_action_label: 'Yes',
// primary_action(values) {
// console.log(values);
// if (values) {
// if (frm.doc.config_kilometer && frm.doc.config_kilometer.length > 0) {
// cur_frm.clear_table("config_kilometer");
// cur_frm.refresh_fields('config_kilometer');
// }
// cur_frm.refresh_fields("config_kilometer");
// frappe.call({
// "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer",
// "args": {
// "doc": values.variant,
// "docname": frm.doc.name
// },
// callback: function (r) {
// if (r.message && r.message.length > 0) {
// cur_frm.refresh_fields("config_kilometer");
// frm.save()
// frm.refresh()
// }
// }
// })
// d.hide();
// }
// },
// secondary_action(values) {
// d.hide();
// }
// });
// d.show();
// var res = $(d.fields_dict.content_html.wrapper).empty();
// var ret = "<p>Upload the Kilometer</p>"
// res.append(ret)
// }).css({ "color": "#fff", "background-color": "red" });;
// //end
frm.doc.kilometer_filter = "All"; frm.doc.kilometer_filter = "All";
if (frm.doc.kilometer_filter == "All") { if (frm.doc.kilometer_filter == "All") {
frm.get_field('config_kilometer').grid.static_rows = false; frm.get_field('config_kilometer').grid.static_rows = false;
@ -68,6 +129,65 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
refresh: function (frm) { refresh: function (frm) {
//custom button
// frm.add_custom_button(__("Duplicate Data"), function () {
// let d = new frappe.ui.Dialog({
// title: 'Choose the variant',
// fields: [
// {
// label: 'Kilometer Mapping',
// fieldname: 'variant',
// fieldtype: 'Link',
// options: "Kilometer Mapping",
// reqd: 1
// }
// ],
// size: 'small',
// secondary_action_label: "No",
// primary_action_label: 'Yes',
// primary_action(values) {
// console.log(values.variant);
// if (values.variant) {
// console.log("calling")
// cur_frm.refresh_fields("config_kilometer");
// frappe.call({
// "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer",
// "args": {
// "doc": values.variant,
// "docname": frm.doc.name
// },
// callback: function (r) {
// if (r.message && r.message.length > 0) {
// cur_frm.refresh_fields("config_kilometer");
// frm.save()
// frm.refresh()
// }
// }
// })
// d.hide();
// }
// else {
// d.hide()
// }
// },
// secondary_action(values) {
// d.hide();
// }
// });
// d.show();
// setTimeout(function mysam() {
// console.log("jiiii", $('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the kilometer mapping?</p>'))
// $('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the <b>kilometer mapping</b>?</p>')
// }
// , 300);
// // var res = $(d.fields_dict.content_html.wrapper).empty();
// // var ret="<p>Are you sure to update the kilometer mapping ?</p>"
// // res.append(ret)
// }).css({ "color": "#fff", "background-color": "red" });;
//end
if (frm.doc.kilometer_filter == "All") { if (frm.doc.kilometer_filter == "All") {
frm.get_field('config_kilometer').grid.static_rows = false; frm.get_field('config_kilometer').grid.static_rows = false;
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {

16
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -34,3 +34,19 @@ def get_subsystem(doc):
doc = frappe.get_doc("System Mapping",s.name) doc = frappe.get_doc("System Mapping",s.name)
sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True) sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True)
return sub_system return sub_system
@frappe.whitelist()
def get_config_kilometer(doc,docname):
res = frappe.db.sql(f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""",as_dict=1)
ress = frappe.get_doc("Kilometer Mapping",docname)
ress.config_kilometer = []
for d in res:
ress.append("config_kilometer",d)
ress.add_comment(text=_("data added"+str(res)))
ress.save()
frappe.db.commit()
return {"status":"success"}

Loading…
Cancel
Save