diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js index 22c107b..5a5ffd7 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js @@ -13,12 +13,13 @@ frappe.ui.form.on('Kilometer Mapping', { }, onload: function (frm) { + $(document).on('mouseover', function (events) { - $("a:contains(Copy to Clipboard)").css({ 'pointer-events': 'none' }), - $("a:contains(Duplicate)").css({ 'pointer-events': 'none' }); + $("a:contains(Copy to Clipboard)").css({ 'pointer-events': 'none' }) + $("a:contains(Duplicate)").css({ 'pointer-events': 'none' }); }), - //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' }); + //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; @@ -56,6 +57,7 @@ frappe.ui.form.on('Kilometer Mapping', { }, validate: function (frm) { + frm.doc.kilometer_filter = "All"; if (frm.doc.kilometer_filter == "All") { frm.get_field('config_kilometer').grid.static_rows = false; @@ -68,6 +70,65 @@ frappe.ui.form.on('Kilometer Mapping', { }, 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('
Are you sure to update the kilometer mapping?
')) + $('.modal-dialog').find('.custom-actions').html('Are you sure to update the kilometer mapping?
') + } + , 300); + + // var res = $(d.fields_dict.content_html.wrapper).empty(); + // var ret="Are you sure to update the kilometer mapping ?
" + // res.append(ret) + }).css({ "color": "#fff", "background-color": "red" });; + //end + 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) => { @@ -133,7 +194,7 @@ frappe.ui.form.on('Kilometer Mapping', { kilometer_set.push(kmsrow.service_kilometers); }); frm.set_df_property('kilometer_filter', 'options', kilometer_set); - $.each(kmrecord, function (index, kmrow) { + $.each(kmrecord, function (index, kmrow) { frappe.call({ "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system", @@ -180,14 +241,14 @@ frappe.ui.form.on('Kilometer Mapping', { }, kilometer_filter1: function (frm) { - frm.doc.duplicate_kilometer_mapping_items=''; + frm.doc.duplicate_kilometer_mapping_items = ''; frm.refresh_field('duplicate_kilometer_mapping_items'); console.log("call") frappe.call({ "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.update_duplicate_km", "args": { "doc": frm.doc.name, - "kilometer":frm.doc.kilometer_filter + "kilometer": frm.doc.kilometer_filter }, callback: function (r) { cur_frm.reload_doc() @@ -204,13 +265,13 @@ frappe.ui.form.on('Kilometer Mapping', { } 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) => { + 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) => { + 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 && 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") { @@ -227,7 +288,7 @@ frappe.ui.form.on('Kilometer Mapping', { sort_by_kilometer: function (frm) { var idx = 1; frm.doc.config_kilometer.sort(function (a, b) { - if (parseInt(a.kilometer) < parseInt(b.kilometer)) { console.log(a.kilometer +"inside if"+ b.kilometer);return -1 } + if (parseInt(a.kilometer) < parseInt(b.kilometer)) { console.log(a.kilometer + "inside if" + b.kilometer); return -1 } else if (parseInt(a.kilometer) > parseInt(b.kilometer)) { console.log(a.kilometer + "inside else if" + b.kilometer); return 1 } return 1; }); @@ -236,7 +297,7 @@ frappe.ui.form.on('Kilometer Mapping', { 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"); + refresh_field("config_kilometer"); } }); diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index d65ba1a..8c0e962 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -4,6 +4,7 @@ import frappe from frappe.model.document import Document import sys +from frappe import _ sys.tracebacklimit=0 class KilometerMapping(Document): @@ -50,4 +51,20 @@ def update_duplicate_km(doc,kilometer): 'sub_systems': data['sub_systems'], 'row_name': data['row_name'] }) - km.save(ignore_permissions=True) \ No newline at end of file + km.save(ignore_permissions=True) + + + +@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"} + +