Browse Source

Kilometer mapping duplicate button

master
venkataakhil 1 year ago
parent
commit
ee57b518ca
  1. 19
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  2. 32
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

19
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js

@ -56,6 +56,9 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
validate: function (frm) { validate: function (frm) {
if (frm.doc.__unsaved == 1){
frm.doc.workflow_state = "Draft";
}
frm.doc.kilometer_filter = "All"; frm.doc.kilometer_filter = "All";
if (frm.doc.kilometer_filter == "All") { if (frm.doc.kilometer_filter == "All") {
@ -69,7 +72,7 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
refresh: function (frm) { refresh: function (frm) {
//custom button //custom duplicate button
frm.add_custom_button(__("Duplicate Data"), function () { frm.add_custom_button(__("Duplicate Data"), function () {
let d = new frappe.ui.Dialog({ let d = new frappe.ui.Dialog({
title: 'Choose the variant', title: 'Choose the variant',
@ -86,9 +89,7 @@ frappe.ui.form.on('Kilometer Mapping', {
secondary_action_label: "No", secondary_action_label: "No",
primary_action_label: 'Yes', primary_action_label: 'Yes',
primary_action(values) { primary_action(values) {
console.log(values.variant);
if (values.variant) { if (values.variant) {
console.log("calling")
cur_frm.refresh_fields("config_kilometer"); cur_frm.refresh_fields("config_kilometer");
frappe.call({ frappe.call({
"method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer", "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer",
@ -97,10 +98,15 @@ frappe.ui.form.on('Kilometer Mapping', {
"docname": frm.doc.name "docname": frm.doc.name
}, },
callback: function (r) { callback: function (r) {
if (r.message && r.message.length > 0) { if (r.message && r.message['status'] == "success") {
cur_frm.refresh_fields("config_kilometer"); cur_frm.refresh_fields("config_kilometer");
frm.save() frm.save()
frm.refresh()
frappe.show_alert({
message: __('Saved'),
indicator: 'green'
}, 5);
cur_frm.reload_doc();
} }
} }
}) })
@ -118,7 +124,8 @@ frappe.ui.form.on('Kilometer Mapping', {
d.show(); d.show();
setTimeout(function mysam() { setTimeout(function mysam() {
$('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the <b>kilometer mapping</b>?</p>') $('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the <b>kilometer mapping</b>?</p>')
}, 300); }
, 300);
}).css({ "color": "#fff", "background-color": "red" });; }).css({ "color": "#fff", "background-color": "red" });;
//end //end

32
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -4,8 +4,9 @@
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
import sys import sys
from frappe import _
sys.tracebacklimit=0 sys.tracebacklimit=0
current_db_name = frappe.conf.get("db_name")
class KilometerMapping(Document): class KilometerMapping(Document):
def onload(self): def onload(self):
###Kilometer mapping config table idx allignment ###Kilometer mapping config table idx allignment
@ -14,10 +15,9 @@ class KilometerMapping(Document):
for x in self.get("config_kilometer"): for x in self.get("config_kilometer"):
idx += 1 idx += 1
x.idx = idx x.idx = idx
@frappe.whitelist() @frappe.whitelist()
def get_system(doc): def get_system(doc):
current_db_name = frappe.conf.get("db_name")
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True) system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True)
if system_map: if system_map:
for s in system_map: for s in system_map:
@ -36,6 +36,22 @@ def get_subsystem(doc):
return sub_system return sub_system
@frappe.whitelist()
def update_duplicate_km(doc,kilometer):
km = frappe.get_doc("Kilometer Mapping",doc)
output = frappe.db.sql("""select kilometer,mat,sub_systems,row_name from `tabKilometer Mapping_Items` where parent = '{0}' and kilometer = '{1}' order by kilometer""".format(doc,kilometer),as_dict=True)
# frappe.msgprint(str(output))
for data in output:
# frappe.msgprint(str(data['mat']))
km.append('duplicate_kilometer_mapping_items', {
'kilometer': data['kilometer'],
'mat': data['mat'],
'sub_systems': data['sub_systems'],
'row_name': data['row_name']
})
km.save(ignore_permissions=True)
@frappe.whitelist() @frappe.whitelist()
@ -50,3 +66,13 @@ def get_config_kilometer(doc,docname):
frappe.db.commit() frappe.db.commit()
return {"status":"success"} return {"status":"success"}
# @frappe.whitelist()
# def km_filter(parent = None , record = None, km = None):
# if record == "All":
# km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by length(kilometer),kilometer;""",as_dict = 1)
# else:
# km_filters =frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" and kilometer ="{km}" order by length(kilometer),kilometer """,as_dict = 1)
# return km_filters
Loading…
Cancel
Save