Browse Source

system mapping codes moved to py some validations and publish updated

master
Ubuntu 3 years ago
parent
commit
97516ba756
  1. 14
      smart_service/fixtures/client_script.json
  2. 7
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py
  3. 11
      smart_service/transactions/doctype/kilometer_mapping_items/kilometer_mapping_items.json
  4. 43
      smart_service/transactions/doctype/publish/publish.json
  5. 16
      smart_service/transactions/doctype/publish/publish.py
  6. 687
      smart_service/transactions/doctype/system_mapping/system_mapping.js
  7. 61
      smart_service/transactions/doctype/system_mapping/system_mapping.py
  8. 3
      smart_service/transactions/doctype/system_mapping_sub_system/system_mapping_sub_system.json

14
smart_service/fixtures/client_script.json

File diff suppressed because one or more lines are too long

7
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -5,6 +5,13 @@ import frappe
from frappe.model.document import Document
class KilometerMapping(Document):
def onload(self):
###Kilometer mapping config table idx allign
if(self.config_kilometer):
idx = 0
for x in self.get("config_kilometer"):
idx += 1
x.idx = idx
def validate(self):
pass
@frappe.whitelist()

11
smart_service/transactions/doctype/kilometer_mapping_items/kilometer_mapping_items.json

@ -7,7 +7,6 @@
"field_order": [
"kilometer",
"mat",
"systems",
"sub_systems",
"applicable",
"row_name"
@ -42,24 +41,16 @@
"in_list_view": 1,
"label": "Applicable "
},
{
"fieldname": "systems",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Systems",
"read_only": 1
},
{
"fieldname": "row_name",
"fieldtype": "Data",
"hidden": 1,
"label": "Row Name"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-04-23 10:15:25.073732",
"modified": "2022-04-29 11:05:43.931420",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Kilometer Mapping_Items",

43
smart_service/transactions/doctype/publish/publish.json

@ -33,6 +33,10 @@
"column_break_17",
"km_active_status",
"km_workflow_state",
"section_break_27",
"variant_mapping_details",
"column_break_29",
"kilometer_mapping_details",
"system_n_sub_systems",
"system_mapping",
"variant_mapping_assets",
@ -89,7 +93,7 @@
"set_only_once": 1
},
{
"depends_on": "eval:doc.vehicle",
"depends_on": "eval:doc.vehicle && doc.docstatus == 0",
"fieldname": "variant_mapping",
"fieldtype": "Link",
"label": "Variant Mapping",
@ -97,6 +101,7 @@
"read_only_depends_on": "eval:doc.publish_type == \"Global\""
},
{
"depends_on": "eval:doc.docstatus == 0",
"fieldname": "system_n_sub_systems",
"fieldtype": "Section Break",
"label": "System & Sub Systems"
@ -109,6 +114,7 @@
"read_only": 1
},
{
"allow_bulk_edit": 1,
"fieldname": "publish_documents",
"fieldtype": "Table",
"label": "Publish Documents",
@ -125,9 +131,10 @@
{
"fieldname": "section_break_7",
"fieldtype": "Section Break",
"label": "Variant Mapping"
"label": "Vehicle Details"
},
{
"depends_on": "eval:doc.docstatus == 0",
"fieldname": "column_break_9",
"fieldtype": "Column Break"
},
@ -165,6 +172,7 @@
"read_only": 1
},
{
"depends_on": "eval:doc.docstatus == 0 && doc.variant_mapping",
"fetch_from": "variant_mapping.active_status",
"fieldname": "variant_mapping_status",
"fieldtype": "Data",
@ -172,14 +180,14 @@
"read_only": 1
},
{
"depends_on": "eval:doc.variant_mapping && doc.publish_type == \"Internal\"",
"depends_on": "eval:doc.variant_mapping && doc.publish_type == \"Internal\" && doc.docstatus == 0",
"fieldname": "add_variant_mapping_to_publish",
"fieldtype": "Button",
"label": "Add Variant Mapping to Publish",
"read_only_depends_on": "eval:doc.publish_type == \"Global\""
},
{
"depends_on": "eval:doc.variant_mapping",
"depends_on": "eval:doc.variant_mapping && doc.docstatus == 0",
"fieldname": "kilometer_mapping_section",
"fieldtype": "Section Break",
"label": "Kilometer Mapping"
@ -240,7 +248,7 @@
"label": "Global Publish"
},
{
"depends_on": "eval:doc.kilometer_mapping",
"depends_on": "eval:doc.kilometer_mapping && doc.docstatus == 0",
"fieldname": "km_report",
"fieldtype": "Button",
"label": "Kilometer Mapping Report"
@ -254,17 +262,38 @@
"read_only": 1
},
{
"depends_on": "eval:doc.variant_mapping",
"depends_on": "eval:doc.variant_mapping && doc.docstatus == 0",
"fieldname": "variant",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Variant"
},
{
"fieldname": "section_break_27",
"fieldtype": "Section Break",
"label": "Variant & Kilometer Mapping Details"
},
{
"fieldname": "variant_mapping_details",
"fieldtype": "Small Text",
"label": "Variant Mapping List",
"read_only": 1
},
{
"fieldname": "column_break_29",
"fieldtype": "Column Break"
},
{
"fieldname": "kilometer_mapping_details",
"fieldtype": "Small Text",
"label": "Kilometer Mapping List",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-04-18 13:18:44.531763",
"modified": "2022-04-29 15:09:15.597658",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Publish",

16
smart_service/transactions/doctype/publish/publish.py

@ -7,6 +7,22 @@ import json
current_db_name = frappe.conf.get("db_name")
class Publish(Document):
def validate(self):
variant = []
for vm in self.get('publish_documents'):
if vm.variant_mapping in variant:
pass
else:
variant.append(vm.variant_mapping)
self.variant_mapping_details = ''
self.kilometer_mapping_details = ''
for v in variant:
self.variant_mapping_details = self.variant_mapping_details + str(v) + '\n'
km_mapping_record = frappe.db.sql("""select name from `tabKilometer Mapping` where variant_mapping = %s""",str(v),as_dict=True)
for km_mapping in km_mapping_record:
self.kilometer_mapping_details = self.kilometer_mapping_details + str(km_mapping.name) + '\n'
def onload(self):
current_db_name = frappe.conf.get("db_name")
if self.publish_status == "Published" and self.publish_type == "Global":

687
smart_service/transactions/doctype/system_mapping/system_mapping.js

@ -1,10 +1,689 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
frappe.ui.form.on('System Mapping', {
//refresh: function(frm) {
//}
// frappe.ui.form.on('System Mapping', {
// //refresh: function(frm) {
// //}
// after_save: function(frm){
// cur_frm.reload_doc();
// }
// });
var dusted = false;
var sub_system_idx = [];
var mat_array = [];
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) {
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",};
};
cur_frm.fields_dict['system_sub_systems'].grid.get_field('systems').get_query = function(doc, cdt, cdn){
return {query:"smart_service.transactions.doctype.system_mapping.system_mapping.systems",};
};
cur_frm.fields_dict['system_sub_systems'].grid.get_field('procedure').get_query = function(doc, cdt, cdn){
return {query:"smart_service.transactions.doctype.system_mapping.system_mapping.procedure",};
};
frappe.ui.form.on('System Mapping', {
onload: function(frm) {
frm.set_query("systems", "system_sub_systems", function(doc , cdt, cdn) {
return {
"query": "smart_service.transactions.doctype.system_mapping.system_mapping.system_filter",
filters:{
"system_filter": frm.doc.system_filter
}
};
});
frm.set_query("systems", "systems_assets", function(doc , cdt, cdn) {
var system = [];
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
let value = row.doc.systems;
system.push(value);
});
return {
filters: {'system_name': ['in',system],
}
};
});
frm.trigger('fnLoadmat_initial_values');
if (frm.doc.kilometer_mapping !== undefined){
frappe.db.get_doc('Kilometer Mapping', frm.doc.kilometer_mapping)
.then(doc => {
// frm.set_value("km_active_status",doc.active_status);
refresh_field("km_active_status");
});
}
},
validate: function(frm){
if (frm.is_new()) {
if(frm.doc.variant_mapping)
var km_doc_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM";
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM")
.then(smexists => {
if (smexists){
frappe.throw(__('System Mapping already Exists!!!'));
} else {
frappe.db.exists('Kilometer Mapping', km_doc_name)
.then(exists => {
if (exists) {
frm.trigger('fnSave_caller');
} else {
// frappe.call({
// "method": "smart_service.transactions.doctype.system_mapping.system_mapping.create_kilometer",
// "args": {
// "doc": cur_frm.doc.name,
// "doctype": 'Kilometer Mapping',
// "variant_mapping": frm.doc.variant_mapping,
// "language":frm.doc.language
// },
// })
// frappe.db.insert({
// doctype: 'Kilometer Mapping',
// variant_mapping: frm.doc.variant_mapping,
// language:frm.doc.language
// }).then(doc => {
// frm.set_value("kilometer_mapping",doc.name);
// refresh_field("kilometer_mapping");
// frm.trigger('fnSave_caller');
// });
}
});
}
});
} else {
frm.trigger('fnSave_caller');
}
},
after_save: function(frm){
cur_frm.reload_doc();
cur_frm.reload_doc();
},
refresh: function(frm) {
cur_frm.doc.system_filter = "All";
if(frm.doc.system_filter == "All"){
frm.get_field('system_sub_systems').grid.static_rows = false;
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
}
// frm.disable_save(); //*** Check Refresh for Save Function
// frm.add_custom_button(__('Save'), function(){
// // frm.trigger('fnSave');
// }).addClass("btn-warning").css({'background-color':'#e31a37', 'color':'white'});
frm.fields_dict.system_sub_systems.grid.get_field('procedure').get_query = function(doc, cdt, cdn) {
return {
filters:[
['language', '=', frm.doc.language]
]
};
};
frm.trigger('fnsetsystemsfilter');
// Make a Copy of Rows Data for Move Function
sub_system_idx.length = 0;
frm.fields_dict.system_sub_systems.grid.data.forEach((row) => {
sub_system_idx.push(row);
});
},
onload_post_render: function(frm) {
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_is_published == 1){
// row.doc.procedure_status = "Published";
}
if (row.doc.procedure_status == "Publish Ready"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
}else if (row.doc.procedure_status == "Published"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
} else {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'});
}
});
refresh_field("system_sub_systems");
},
variant_mapping: function(frm) {
frm.trigger('fnSet_SM_KM_4_VM');
},
language: function(frm) {
frm.trigger('fnSet_SM_KM_4_VM');
},
system_filter: function(frm) {
if (frm.doc.system_filter == "All"){
frm.get_field('system_sub_systems').grid.static_rows = false;
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
frm.get_field('systems_assets').grid.static_rows = false;
frm.fields_dict.systems_assets.grid.grid_rows.forEach((row) => {
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
});
} else {
frm.get_field('system_sub_systems').grid.static_rows = false;
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
if (row.doc.systems != frm.doc.system_filter){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
} else {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}
});
frm.get_field('systems_assets').grid.static_rows = false;
frm.fields_dict.systems_assets.grid.grid_rows.forEach((row) => {
if (row.doc.systems != frm.doc.system_filter){
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
} else {
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
}
});
}
},
fnsetsystemsfilter: function(frm){
var filtered_systems = frm.doc.system_filter;
$("select[data-fieldname='system_filter']").empty();
$("select[data-fieldname='system_filter']").append(new Option("All", "All"));
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
let value = row.doc.systems;
if (value)
if ($("select[data-fieldname='system_filter'] option[value='" + value + "']").length === 0){
$("select[data-fieldname='system_filter']").append(new Option(value, value));
}
});
frm.doc.system_filter = filtered_systems;
//refresh_field("system_sub_systems");
},
fnLoadmat_initial_values: function(frm){
if (frm.doc.system_sub_systems !== undefined){
mat_array.length = 0;
frm.doc.system_sub_systems.forEach(row => {
// ***Update the Current Procedure Status
if (row.procedure){
frappe.db.get_doc('Procedure', row.procedure)
.then(doc => {
row.procedure_status = doc.workflow_state;
refresh_field("system_sub_systems");
});
}
// ***Store the Initial MAT values
var valueToPush = {};
valueToPush.name = row.name;
valueToPush.type = (frm.is_new() ? "New":"Initial");
valueToPush.mat_initial = (row.mat === undefined ? null:row.mat);
valueToPush.mat_update = (frm.is_new() ? row.mat:null);
valueToPush.idx = row.idx;
valueToPush.sub_systems = row.sub_systems;
valueToPush.procedure_status = row.procedure_status;
valueToPush.procedure_is_published = row.procedure_is_published;
mat_array.push(valueToPush);
});
}
},
fnSave1: function(frm){
//*** Check the respective Kilometer Mapping Document exisits
if (frm.is_new()) {
if(frm.doc.variant_mapping)
var km_doc_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM";
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM")
.then(smexists => {
if (smexists){
frappe.throw(__('System Mapping already Exists!!!'));
} else {
frappe.db.exists('Kilometer Mapping', km_doc_name)
.then(exists => {
if (exists) {
frm.trigger('fnSave_caller');
} else {
// frappe.call({
// "method": "smart_service.transactions.doctype.system_mapping.system_mapping.create_kilometer",
// "args": {
// "doc": cur_frm.doc.name,
// "doctype": 'Kilometer Mapping',
// "variant_mapping": frm.doc.variant_mapping,
// "language":frm.doc.language
// },
// })
// frappe.db.insert({
// doctype: 'Kilometer Mapping',
// variant_mapping: frm.doc.variant_mapping,
// language:frm.doc.language
// }).then(doc => {
// frm.set_value("kilometer_mapping",doc.name);
// refresh_field("kilometer_mapping");
// frm.trigger('fnSave_caller');
// });
}
});
}
});
} else {
frm.trigger('fnSave_caller');
}
},
fnSave_caller: function(frm){
// frappe.validated = false
//*** Construct the change point as HTML
var html = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:left;padding: 5px;}</style></head><body><table>";
$.each(mat_array, function(index, row){
if (row.type !== "Initial"){
html = html + "<tr><td>" + row.sub_systems + "</td><td> MAT " + row.type + ": <b>" + row.mat_update + "</b></td></tr>" ;
dusted = true;
}
});
html = html + "</table></body>";
if (dusted){
// frappe.msgprint('Changes will impact KM Mapping')
// frappe.msgprint('Changes will impact KM Mapping - <b>'+ frm.doc.kilometer_mapping + '</b><br>This Document status will be set to: <b>Draft</b><br><br>Following are the changes updated: <br>' + html,
// () => {
//*** Change the State to Draft for KM
//console.log("Dusted:" + dusted);
//console.log("Is Dirty:" + frm.is_dirty());
frappe.db.set_value('Kilometer Mapping', frm.doc.kilometer_mapping, 'workflow_state', 'Draft')
.then(r => {
dusted = false;//frm.save();
// MOVE THIS CODE TO PY FILE ********* START
mat_array.forEach((array_row) => {
//*** Add Edit Delete the respective Kiolmeter with Updated/Deleted MAT
if (array_row.type !== "Initial"){
frappe.call({
"method": "smart_service.transactions.doctype.system_mapping.system_mapping.update_mat",
"args": {
"doc": cur_frm.doc.name,
"km": frm.doc.kilometer_mapping,
"vehicle": frm.doc.vehicle,
"type": array_row.type,
"idx": array_row.idx,
"systems": array_row.systems,
"sub_systems": array_row.sub_systems,
"mat_initial": array_row.mat_initial, //*** for Deleted
"mat_update": array_row.mat_update, //*** for New, Added & Edited
"km_applicable": 0
},
//freeze: true,
//async:false,
callback:function(r){
frappe.msgprint('Changes will impact KM Mapping - <b>'+ frm.doc.kilometer_mapping + '</b><br>This Document status will be set to: <b>Draft</b><br><br>Following are the changes updated: <br>' + html)
}
});
}
// });
// MOVE THIS CODE TO PY FILE ********* END
// frappe.show_alert({
// message:__('Inserted Rows in KM Doc: ' + frm.doc.kilometer_mapping),
// indicator:'green'
// }, 5);
frm.trigger('fnLoadmat_initial_values');
//frappe.validated = true
// frm.save()
});
}, () => {
// action to perform if No is selected
});
} else if(frm.is_dirty()){
dusted = false;//frm.save();
frm.trigger('fnLoadmat_initial_values');
// } else {
// frappe.show_alert({
// message:__('No updates for Kilometer Mapping... '),
// indicator:'yellow'
// }, 5);
}
},
fnSet_SM_KM_4_VM: function (frm) {
if (frm.doc.variant_mapping === undefined) return;
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM")
.then(smexists => {
if (smexists){
frappe.throw(__('System Mapping already Exists!!!'));
//frm.set_value("variant_mapping",null);
//refresh_field("variant_mapping");
} else {
frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-KM")
.then(exists => {
if (exists){
frm.set_value("kilometer_mapping",frm.doc.variant_mapping + "-" + frm.doc.language + "-KM");
} else {
frm.set_value("kilometer_mapping",null);
frm.set_value("km_active_status","Not Configured!");
}
});
}
});
}
});
frappe.ui.form.on('System Mapping_Sub System', {
before_system_sub_systems_remove: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
let index = mat_array.findIndex(o => o.name === row.doc.name);
if (index >= 0){
if (row.doc.mat !== ""){
mat_array[index].type = "Deleted";
mat_array[index].systems = row.doc.systems;
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
mat_array[index].mat_update = row.doc.mat === '' ? null : row.doc.mat;
}
}
},
system_sub_systems_move: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
var id = d.idx;
var from = id;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
let index = sub_system_idx.findIndex(o => o.name === d.name);
var to = index + 1;
if(from > to) {to = [from, from = to][0];}
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_status == "Publish Ready"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
}else if (row.doc.procedure_status == "Published"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
} else {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'});
}
if (row.doc.idx >= from && row.doc.idx <= to) {
if (row.doc.procedure_is_published == 1){
// row.doc.procedure_status = "Publish Ready";
row.doc.procedure_is_published = 0;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
}
}
});
refresh_field("system_sub_systems");
},
system_sub_systems_add: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
var prevrow = frm.fields_dict.system_sub_systems.grid.grid_rows[id-1];
if (frm.doc.system_filter == "All"){
if (prevrow !== undefined) row.doc.systems = prevrow.doc.systems;
}else{
row.doc.systems = frm.doc.system_filter;
}
},
systems: function (frm,cdt,cdn) {
frm.trigger('fnsetsystemsfilter');
},
system_sub_systems_remove: function(frm,cdt,cdn) {
let index = sub_system_idx.findIndex(o => o.name === cdn);
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => {
if (row.doc.procedure_status == "Publish Ready"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
}else if (row.doc.procedure_status == "Published"){
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
} else {
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'});
}
if (row.doc.idx >= index) {
if (row.doc.procedure_is_published == 1){
// row.doc.procedure_status = "Publish Ready";
row.doc.procedure_is_published = 0;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
}
}
});
frm.refresh();
frm.doc.system_filter = "All";
},
systems: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
sub_systems: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
procedure: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
active_status: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
symptom: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
component: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
estimate_time: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
rts: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
cover_image: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)},
mat: function(frm,cdt,cdn) {
var res_mat = [];
var d = locals[cdt][cdn];
var id = d.idx;
for (var i = 0; i < cur_frm.doc.system_sub_systems.length; i++) {
for (var j = 0; j < res_mat.length; j++) {
var list_mat = res_mat[j];
var cur_mat = cur_frm.doc.system_sub_systems[i].mat;
if((list_mat) && (cur_mat)){
var dup_mat = list_mat.toUpperCase();
var another_dup_mat = cur_mat.toUpperCase()
if(dup_mat == another_dup_mat){
// cur_frm.doc.system_sub_systems[i].mat = '';
//cur_frm.refresh_field('mat')
// cur_frm.refresh_fields();
frappe.throw('You Cannot Select Same MAT ' + cur_mat + ' Multiple Times' + ' in Row no ' + id)
// }
}
}
// if (res_mat[j] == cur_frm.doc.system_sub_systems[i].mat) {
// cur_frm.doc.system_sub_systems[i].mat = '';
// cur_frm.refresh_field('mat')
// cur_frm.refresh_fields();
// frappe.throw('You Cannot Select Same MAT ' + cur_frm.doc.system_sub_systems[i].mat + ' Multiple Times');
// }
}
if (cur_frm.doc.system_sub_systems[i].mat) {
res_mat.push(frm.doc.system_sub_systems[i].mat)
}
}
cur_frm.refresh_fields();
frm.refresh_field("system_sub_systems")
fn_mat_updated(frm,cdt,cdn)
},
sub_systems: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
var procedurename = frm.doc.variant_mapping+"-"+d.sub_systems+"-"+frm.doc.language;
frappe.db.exists('Procedure', procedurename)
.then(exists => {
if (exists){
frappe.db.get_doc('Procedure', procedurename)
.then(doc => {
row.doc.procedure = doc.name;
row.doc.procedure_status = doc.workflow_state;
if (row.doc.estimate_time === undefined) row.doc.estimate_time = doc.estimate_time;
if (row.doc.rts === undefined) row.doc.rts = doc.rts;
if (row.doc.mat === undefined) {row.doc.mat = doc.mat; fn_mat_updated(frm,cdt,cdn)}
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure"]').css({'background-color': '#ffc3c3'});
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
row.toggle_editable_row(false);
refresh_field("system_sub_systems");
});
}else{
row.doc.procedure = "";
row.doc.procedure_status = "";
if(row.doc.mat){
row.doc.mat = '';
fn_mat_updated(frm,cdt,cdn)}
row.toggle_editable_row(false);
refresh_field("system_sub_systems");
frappe.msgprint(__('Procedure to be created or sub-system renamed'));
}
});
var res_system = [];
for (var i = 0; i < frm.doc.system_sub_systems.length; i++) {
for (var j = 0; j < res_system.length; j++) {
var sys = frm.doc.system_sub_systems[i].sub_systems;
if(frm.doc.system_sub_systems[i].sub_systems == res_system[j]){
frm.doc.system_sub_systems[i].sub_systems = '';
frm.refresh_field('sub_Systems')
frm.refresh_fields();
frappe.msgprint('You Cannot Select Same Sub Systems ' + sys + ' Multiple Times');
}
}
if (frm.doc.system_sub_systems[i].sub_systems) {
res_system.push(frm.doc.system_sub_systems[i].sub_systems)
}
}
},
procedure: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
var procedurename = frm.doc.variant_mapping+"-"+d.sub_systems+"-"+frm.doc.language;
if (d.procedure){
frappe.db.exists('Procedure', d.procedure)
.then(exists => {
if (exists){
frappe.db.get_doc('Procedure', d.procedure)
.then(doc => {
row.doc.procedure = doc.name;
row.doc.procedure_status = doc.workflow_state;
row.doc.procedure_is_published = 0;
//if (row.doc.estimated_time === undefined) row.doc.estimated_time = doc.estimated_time;
//if (row.doc.rts === undefined) row.doc.rts = doc.rts;
//if (row.doc.mat === undefined) row.doc.mat = doc.mat;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure"]').css({'background-color': '#ffc3c3'});
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
row.toggle_editable_row(false);
refresh_field("system_sub_systems");
});
}else{
row.doc.procedure = "";
row.doc.procedure_status = "";
row.toggle_editable_row(false);
refresh_field("system_sub_systems");
frappe.throw(__('Procedure to be created or sub-system renamed'));
}
});
} else {
row.doc.procedure_status = "";
row.toggle_editable_row(false);
refresh_field("system_sub_systems");
}
},
});
function fn_updateProceduteStatus(frm,cdt,cdn){
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
if (row.doc.procedure_is_published == 1){
// row.doc.procedure_status = "Publish Ready";
row.doc.procedure_is_published = 0;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'});
row.toggle_editable_row(false);
}
refresh_field("system_sub_systems");
}
function fn_mat_updated(frm,cdt,cdn){
fn_updateProceduteStatus(frm,cdt,cdn);
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id];
let index = mat_array.findIndex(o => o.name === row.doc.name);
if (index >= 0){
mat_array[index].mat_update = row.doc.mat === '' ? null : row.doc.mat;
if (row.doc.mat === ""){
if (mat_array[index].mat_initial === null){
mat_array[index].type = "Initial";
if (mat_array[index].procedure_is_published){
row.doc.procedure_status = "Published";
row.doc.procedure_is_published = 1;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
row.toggle_editable_row(false);
}
} else {mat_array[index].type = "Deleted";
mat_array[index].systems = row.doc.systems;
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
}
} else {
if (mat_array[index].mat_initial === null || mat_array[index].mat_initial == ''){
mat_array[index].type = "Added";
mat_array[index].systems = row.doc.systems;
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
} else {
if (mat_array[index].mat_initial == row.doc.mat){
mat_array[index].type = "Initial";
mat_array[index].systems = row.doc.systems;
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
if (mat_array[index].procedure_is_published){
row.doc.procedure_status = "Published";
row.doc.procedure_is_published = 1;
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'});
row.toggle_editable_row(false);
}
} else {
mat_array[index].type = "Edited";
mat_array[index].systems = row.doc.systems;
mat_array[index].sub_systems = row.doc.sub_systems;
mat_array[index].idx = row.doc.idx;
}
}
}
} else {
var valueToPush = {};
valueToPush.name = row.doc.name;
valueToPush.type = "New";
valueToPush.mat_initial = null;
valueToPush.mat_update = row.doc.mat;
valueToPush.idx = row.doc.idx;
valueToPush.systems = row.doc.systems;
valueToPush.sub_systems = row.doc.sub_systems;
valueToPush.procedure_status = row.doc.procedure_status;
valueToPush.procedure_is_published = row.doc.procedure_is_published;
mat_array.push(valueToPush);
}
refresh_field("system_sub_systems");
}
frappe.ui.form.on('System Mapping_System Assets', {
remarks: function(frm,cdt,cdn){
var child = locals[cdt][cdn];
if(child.active_status == "Active"){
child.remarks = '';
cur_frm.refresh_fields();
frappe.throw("Remarks should not allow for Active status")
}
},
active_status: function(frm,cdt,cdn){
var child = locals[cdt][cdn];
child.remarks = '';
cur_frm.refresh_fields();
},
systems_assets_add: function(frm,cdt,cdn){
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
var row = frm.fields_dict.systems_assets.grid.grid_rows[id];
var prevrow = frm.fields_dict.systems_assets.grid.grid_rows[id-1];
if (frm.doc.system_filter == "All"){
if (prevrow !== undefined) row.doc.systems = prevrow.doc.systems;
}else{
row.doc.systems = frm.doc.system_filter;
}
row.doc.language = frm.doc.language;
cur_frm.refresh_fields();
}
});

61
smart_service/transactions/doctype/system_mapping/system_mapping.py

@ -3,9 +3,44 @@
import frappe
from frappe.model.document import Document
current_db_name = frappe.conf.get("db_name")
class SystemMapping(Document):
current_db_name = frappe.conf.get("db_name")
def onload(self):
current_db_name = frappe.conf.get("db_name")
km = frappe.db.sql("""select name,active_status from {0}.`tabKilometer Mapping` where variant_mapping = '{1}'""".format(current_db_name,self.variant_mapping),as_dict=True)
if km:
for status in km:
self.km_active_status = status.active_status
def validate(self):
current_db_name = frappe.conf.get("db_name")
km = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}'""".format(current_db_name,self.variant_mapping),as_list=True)
if not km:
mat = []
km_record = frappe.new_doc("Kilometer Mapping")
km_record.variant_mapping = self.variant_mapping
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = '{1}' order by service_kilometers""".format(current_db_name,self.vehicle),as_dict=True)
for service_km in vehicle_sk:
for sys in self.get('system_sub_systems'):
if sys.mat:
sub_system = km_record.append('config_kilometer', {})
sub_system.kilometer = str(service_km.service_kilometers)
sub_system.mat = sys.mat
sub_system.systems = sys.systems
sub_system.row_name = sys.idx
sub_system.sub_systems = sys.sub_systems
sub_system.applicable = 0
mat.append(sys.mat)
km_record.insert(ignore_permissions = True)
self.kilometer_mapping = km_record.name
mat_code = []
for sm in self.get('system_sub_systems'):
if str(sm.mat):
if str(sm.mat) in mat_code:
frappe.throw('You Cannot Select Same MAT ' + str(sm.mat) + ' Multiple Times' + ' in Row no ' + str(sm.idx))
else:
mat_code.append(sm.mat)
###If anything change to be set Published flag as 0
current_db_name = frappe.conf.get("db_name")
systems = frappe.db.sql("""select systems,sub_systems,active_status,estimate_time,idx,rts,mat,cover_image,`procedure`
@ -86,21 +121,33 @@ def update_mat(doc,km,vehicle,type,idx,systems,sub_systems,mat_initial,mat_updat
current_db_name = frappe.conf.get("db_name")
mat = mat_update
kilometer_mapping = frappe.get_doc("Kilometer Mapping",km)
mat_code = []
mat_code.append(mat_update)
doc = frappe.get_doc("System Mapping",doc)
# for sm in doc.get('system_sub_systems'):
# if str(sm.mat):
# if str(sm.mat) in mat_code:
# sm.mat = ''
# frappe.throw('You Cannot Select Same MAT ' + str(mat) + ' Multiple Times' + ' in Row no ' + str(idx))
# else:
# mat_code.append(sm.mat)
###Updating MAT in kilometer mapping for edited mat
if type == "Edited":
doc = frappe.get_doc("System Mapping",doc)
subsystem_record = frappe.db.sql("""select systems,sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}'""".format(current_db_name,doc.name),as_dict=True)
for km in kilometer_mapping.get("config_kilometer"):
for sys in subsystem_record:
if str(sys.systems) == str(km.systems) and str(sub_systems) == str(km.sub_systems) and str(idx) == str(km.row_name):
# if str(sys.systems) == str(km.systems) and str(sub_systems) == str(km.sub_systems) and str(idx) == str(km.row_name):
if str(sub_systems) == str(km.sub_systems) and str(idx) == str(km.row_name):
km.mat = str(mat)
km.systems = str(systems)
km.sub_systems = str(sub_systems)
if str(sys.systems) == str(km.systems) and str(idx) == str(km.row_name):
#if str(sys.systems) == str(km.systems) and str(idx) == str(km.row_name):
if str(idx) == str(km.row_name):
km.mat = str(mat)
km.systems = str(systems)
km.sub_systems = str(sub_systems)
km.save()
kilometer_mapping.save()
###Insert MAT in kilometer mappnig for added mat
if mat:
if type == "Added" or type == "New":
@ -114,7 +161,7 @@ def update_mat(doc,km,vehicle,type,idx,systems,sub_systems,mat_initial,mat_updat
sub_system.sub_systems = str(sub_systems)
sub_system.applicable = km_applicable
kilometer_mapping.save()
###Delete kilometer mapping item depends on Sub system
###Delete kilometer mapping item depends on System and Sub system
if type == "Deleted":
for km in kilometer_mapping.get("config_kilometer"):
if km.row_name == str(idx):
@ -155,3 +202,5 @@ def system_filter(doctype, txt, searchfield, start, page_len, filters):
else:
return frappe.db.sql(""" select name FROM {0}.`tabSystems` where
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})

3
smart_service/transactions/doctype/system_mapping_sub_system/system_mapping_sub_system.json

@ -87,6 +87,7 @@
"options": "Procedure"
},
{
"fetch_from": "procedure.workflow_state",
"fieldname": "procedure_status",
"fieldtype": "Data",
"in_list_view": 1,
@ -128,7 +129,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-04-09 15:24:09.686783",
"modified": "2022-04-28 17:57:11.336360",
"modified_by": "Administrator",
"module": "Transactions",
"name": "System Mapping_Sub System",

Loading…
Cancel
Save