Browse Source

modules fix

version2
venkataakhil 1 year ago
parent
commit
22069d2824
  1. 28
      smart_service/apis/v2/master.py
  2. 8
      smart_service/masters/doctype/app_labels/app_labels.js
  3. 37
      smart_service/phase_2/doctype/feature_finder/feature_finder.js
  4. 17
      smart_service/phase_2/doctype/feature_finder/feature_finder.json
  5. 1
      smart_service/phase_2/doctype/feature_finder/feature_finder.py
  6. 4
      smart_service/phase_2/doctype/feature_finder_category_master/feature_finder_category_master.json
  7. 4
      smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json
  8. 4
      smart_service/phase_2/doctype/feature_finder_specification_master/feature_finder_specification_master.json
  9. 4
      smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json
  10. 8
      smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json
  11. 4
      smart_service/phase_2/doctype/repair_service_master/repair_service_master.json
  12. 4
      smart_service/phase_2/doctype/repair_service_master_mapping/repair_service_master_mapping.json
  13. 2
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  14. 10
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  15. 2
      smart_service/phase_2/doctype/training_information/training_information.js
  16. 4
      smart_service/phase_2/doctype/training_information/training_information.json
  17. 4
      smart_service/phase_2/doctype/training_information_master/training_information_master.json
  18. 1475
      smart_service/transactions/doctype/publish/publish.js
  19. 4
      smart_service/transactions/doctype/publish/publish.json
  20. 229
      smart_service/transactions/doctype/publish/publish.py

28
smart_service/apis/v2/master.py

@ -55,15 +55,15 @@ def get_repair_service_mapping(vehicle, language):
try:
repair_service_details = []
if language == 'en':
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id from
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id,keywords from
`tabRepair Service Mapping` where vehicle = '{vehicle}' and language = '{language}'; """, as_dict=1)
else:
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,translated_check_list_name as check_list_name,active_status,
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,translated_check_list_name as check_list_name,active_status,keywords,
display_order,my_id from `tabRepair Service Mapping` where vehicle = '{vehicle}' and
language = '{language}'; """, as_dict=1)
for d in repair_service_details:
d['complaint'] = frappe.db.sql(f""" select complaint,remedial_action_ok,remedial_action_not_ok,idx as display_order,active_status from
d['complaint'] = frappe.db.sql(f""" select complaint,remedial_action_ok,remedial_action_not_ok,idx as display_order from
`tabRepair Service Child` where parent = '{d['name']}' order by display_order ;""", as_dict=1)
return True, repair_service_details
@ -77,6 +77,7 @@ def get_feature_finder(vehicle, variant, language):
feature_finder_details = []
if language == 'en':
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff.keywords,ff.sop_name,
ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status,
ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on
ff.features_names = ffm.feature_name
@ -85,6 +86,7 @@ def get_feature_finder(vehicle, variant, language):
""", as_dict=1)
else:
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff.keywords,ff.sop_name,
ff.translated_feature_name as feature_name,ff.feature_category,
ff.display_order,ff.active_status,ffm.feature_pdf as pdf from `tabFeature Finder` ff
left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name
@ -93,32 +95,32 @@ def get_feature_finder(vehicle, variant, language):
for f in feature_finder_details:
f['disclaimer'] = frappe.db.sql(f'''
SELECT name,content,active_status,idx as display_order FROM `tabFeature Finder Disclaimer`
SELECT name,content,idx as display_order FROM `tabFeature Finder Disclaimer`
where parent = '{str(f['vehicle'])+ str('-')+ str(f['feature_name']) +str('-')+str(f['language'])}';
''', as_dict=1)
sop_images = frappe.db.sql(f""" select image,idx as display_order,active_status from `tabFeature Finder Images` where
sop_images = frappe.db.sql(f""" select image,idx as display_order from `tabFeature Finder Images` where
parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1)
sop_content = frappe.db.sql(f"""select content,idx as display_order, active_status from `tabFeature Finder Content`
sop_content = frappe.db.sql(f"""select content,idx as display_order from `tabFeature Finder Content`
where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1)
sop_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification`
sop_specification = frappe.db.sql(f"""select specification,value,idx as display_order from `tabFeature Finder Specification`
where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1)
f['sop'] = {'content': sop_content, 'images': sop_images,
'specificaton': sop_specification}
'specificaton': sop_specification,'sop_name':f['sop_name']}
post_vin_data = frappe.db.sql(f'''select name,idx as display_order,post_vin_cutoff_name,post_vin_cutoff_id
from `tabPost Vin Cutoff ID` where parent = '{f['name']}';''', as_dict=1)
for p in post_vin_data:
vin_content = frappe.db.sql(f"""select content,idx as display_order, active_status from `tabFeature Finder Content`
vin_content = frappe.db.sql(f"""select content,idx as display_order from `tabFeature Finder Content`
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1)
vin_images = frappe.db.sql(f""" select image,idx as display_order,active_status from `tabFeature Finder Images` where
vin_images = frappe.db.sql(f""" select image,idx as display_order from `tabFeature Finder Images` where
parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1)
vin_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification`
vin_specification = frappe.db.sql(f"""select specification,value,idx as display_order from `tabFeature Finder Specification`
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1)
p['content'] = vin_content
p['images'] = vin_images
@ -133,7 +135,7 @@ def get_feature_finder(vehicle, variant, language):
@frappe.whitelist(methods=["POST"], allow_guest=1)
def get_training_information(vehicle, language):
try:
training_information = frappe.db.sql(f"""select name,vehicle,category,topic,language,active_status from`tabTraining Information`
training_information = frappe.db.sql(f"""select name,vehicle,category,topic,language,active_status,keywords from`tabTraining Information`
where vehicle = "{vehicle}" and language = "{language}"; """, as_dict=1)
for t in training_information:
@ -224,7 +226,7 @@ def new_publish1():
@frappe.whitelist(methods=['POST'], allow_guest=1)
def get_special_tool_information(vehicle):
try:
special_tool_details = frappe.db.sql(f''' select name,vehicle,category,sub_category,display_order, my_id from `tabSpecial Tool Information`
special_tool_details = frappe.db.sql(f''' select name,vehicle,category,sub_category,display_order, my_id,keywords from `tabSpecial Tool Information`
where vehicle="{vehicle}";''', as_dict=1)
for s in special_tool_details:
s['tool_usage_content'] = frappe.db.sql(f'''select idx as 'display_order',image,content,video,asset_type,active_status from `tabMST Information Assets`

8
smart_service/masters/doctype/app_labels/app_labels.js

@ -1,6 +1,6 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
var regex = /[!@#$%^&*()]+/;
frappe.ui.form.on('App Labels', {
is_group: function (frm) {
@ -39,7 +39,7 @@ frappe.ui.form.on('App Labels', {
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/]+/;
// var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/]+/;
if (frm.doc.english_label) {
if (regex.test(frm.doc.english_label) === true) {
frappe.throw(__("<b>English Label :</b> Only letters, numbers and <b> - , </b> are allowed."));
@ -66,7 +66,7 @@ frappe.ui.form.on('App Labels', {
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/?]+/;
// var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/?]+/;
if (frm.doc.page_name) {
if (regex.test(frm.doc.page_name) === true) {
frappe.throw(__("<b>Page Name :</b> Only letters, numbers and <b> -,</b> are allowed."));
@ -93,7 +93,7 @@ frappe.ui.form.on('App Labels', {
frappe.throw(__("Just a <b>.</b> is not prescribed!"));
frappe.validated = false;
}
var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/]+/;
// var regex = /[!@#$%^&*()+\=\[\]{};`~'"\\|.<>\/]+/;
if (frm.doc.label) {
if (regex.test(frm.doc.label) === true) {
frappe.throw(__("<b>Translated Label :</b> Only letters, numbers and <b> -,</b> are allowed."));

37
smart_service/phase_2/doctype/feature_finder/feature_finder.js

@ -16,21 +16,21 @@ frappe.ui.form.on('Feature Finder', {
set_display_order(frm)
show_images(frm)
var is_sop =1
if(frm.doc.post_vin_cutoff_id_tab && frm.doc.post_vin_cutoff_id_tab.length>0){
frm.doc.post_vin_cutoff_id_tab.map(v=>{
if(v.post_vin_cutoff_name=="SOP"){
is_sop=0
}
})
// var is_sop =1
// if(frm.doc.post_vin_cutoff_id_tab && frm.doc.post_vin_cutoff_id_tab.length>0){
// frm.doc.post_vin_cutoff_id_tab.map(v=>{
// if(v.post_vin_cutoff_name=="SOP"){
// is_sop=0
// }
// })
}
if(is_sop==1){
var childTable = cur_frm.add_child("post_vin_cutoff_id_tab");
childTable.post_vin_cutoff_name="SOP"
// }
// if(is_sop==1){
// var childTable = cur_frm.add_child("post_vin_cutoff_id_tab");
// childTable.post_vin_cutoff_name="SOP"
cur_frm.refresh_fields("post_vin_cutoff_id_tab");
}
// cur_frm.refresh_fields("post_vin_cutoff_id_tab");
// }
},
@ -170,6 +170,7 @@ frappe.ui.form.on('Feature Finder', {
language: frm.doc.language,
}
}).then(records => {
console.log(records,"records")
if (records.length) {
frappe.db.set_value('Feature Finder', records[0].name, {
display_order: original_display_order
@ -221,7 +222,9 @@ function set_display_order_child(doctype_name, values) {
}
function show_images(frm) {
var res = $(cur_frm.fields_dict.image_html.wrapper).empty();
if (cur_frm.doc.feature_finder_images && cur_frm.doc.feature_finder_images.length > 0) {
var feature_finder_images_ = frm.doc.feature_finder_images.filter(o => o.feature_type == frm.doc.tab_ref)
if (cur_frm.doc.feature_finder_images && cur_frm.doc.feature_finder_images.length > 0 && feature_finder_images_.length>0) {
var img_html = ""
img_html += "<div style='height: 300px;overflow-y: auto;overflow-x: hidden;border:1px solid var(--table-border-color);margin: 5px 0px 10px 0px;'><div style='padding: 5px;' class='row'>"
cur_frm.doc.feature_finder_images.map(val =>{
@ -242,7 +245,12 @@ function custom_tab_html(frm) {
var res = $(cur_frm.fields_dict.test_html.wrapper).empty();
var ret = '<div class="main"><div class="custom_tab style="border:1px solid var(--table-border-color);"><ul class="nav nav-tabs" role="tablist">'
ret += '<li class="nav-item">'
if(frm.doc.sop_name){
ret += '<a class="nav-link active" id="SOP" data-toggle="tab" role="tab" value="SOP">'+ frm.doc.sop_name+'</a>'
}else{
ret += '<a class="nav-link active" id="SOP" data-toggle="tab" role="tab" value="SOP">SOP</a>'
}
ret += '</li>'
if (frm.doc.post_vin_cutoff_id_tab && frm.doc.post_vin_cutoff_id_tab.length > 0) {
@ -1124,7 +1132,6 @@ function set_display_order(frm) {
filters: {
"variant": cur_frm.doc.variant,
"language": frm.doc.language,
"feature_name": frm.doc.feature_name,
// "feature_type":frm.doc.feature_type
}
}).then(count => {

17
smart_service/phase_2/doctype/feature_finder/feature_finder.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[\"Administrator\"]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{variant}-{features_names}-{language}",
@ -19,7 +21,8 @@
"features_names",
"translated_feature_name",
"feature_category",
"keyword",
"sop_name",
"keywords",
"section_break_u9bx1",
"image_html",
"create_feature_finder_images",
@ -125,7 +128,6 @@
{
"fieldname": "specification",
"fieldtype": "Table",
"hidden": 1,
"label": "Specification",
"options": "Feature Finder Specification"
},
@ -196,14 +198,19 @@
"label": "Tab Ref"
},
{
"fieldname": "keyword",
"fieldname": "keywords",
"fieldtype": "Small Text",
"label": "Keyword"
"label": "Keywords"
},
{
"fieldname": "sop_name",
"fieldtype": "Data",
"label": "SOP Name"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 17:00:59.504036",
"modified": "2023-09-15 10:05:47.926994",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Feature Finder",

1
smart_service/phase_2/doctype/feature_finder/feature_finder.py

@ -24,6 +24,7 @@ class FeatureFinder(Document):
def validate(self):
try:
self.sop_name = self.sop_name.strip()
if self.is_new():
self.tab_ref = "SOP"
if self.variant and self.language and self.feature_name:

4
smart_service/phase_2/doctype/feature_finder_category_master/feature_finder_category_master.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{feature_name}",
@ -47,7 +49,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 16:53:55.837109",
"modified": "2023-09-04 17:40:56.588347",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Feature Finder Category Master",

4
smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{vehicle}-{feature_name}-{language}",
@ -75,7 +77,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 16:55:39.666635",
"modified": "2023-09-04 17:44:36.498919",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Feature Finder Master",

4
smart_service/phase_2/doctype/feature_finder_specification_master/feature_finder_specification_master.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{specification}",
@ -42,7 +44,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-29 16:08:19.671934",
"modified": "2023-09-04 17:40:40.990485",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Feature Finder Specification Master",

4
smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{vehicle}-{variant}-{language}-{publish_type}",
@ -141,7 +143,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-29 15:46:05.524052",
"modified": "2023-09-04 17:40:33.938964",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Module Publish Mapping",

8
smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json

@ -17,6 +17,7 @@
"display_order",
"column_break_azh0p",
"language",
"keywords",
"section_break_ecyyc",
"description",
"my_id",
@ -122,11 +123,16 @@
"fieldtype": "Int",
"hidden": 1,
"label": "Vehicle Id"
},
{
"fieldname": "keywords",
"fieldtype": "Small Text",
"label": "Keywords"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 17:04:14.589456",
"modified": "2023-09-04 10:18:54.190500",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Repair Service Mapping",

4
smart_service/phase_2/doctype/repair_service_master/repair_service_master.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"autoname": "format:{repairservicename}",
"creation": "2023-07-20 17:52:46.159091",
@ -50,7 +52,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-14 18:39:29.097473",
"modified": "2023-09-04 17:40:20.862739",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Repair Service Master",

4
smart_service/phase_2/doctype/repair_service_master_mapping/repair_service_master_mapping.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{vehicle}-{check_list_name}-{language}",
@ -107,7 +109,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-29 13:55:00.538663",
"modified": "2023-09-04 17:40:49.193155",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Repair Service Master Mapping",

2
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -63,7 +63,7 @@ function set_display_order(frm){
}
frappe.db.count('Special Tool Information',{
filters: {
"vehicle": frm.doc.variant
"vehicle": frm.doc.vehicle,
}
})
.then(count => {

10
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{vehicle}-{category}-{sub_category}",
@ -16,6 +18,7 @@
"sub_category",
"column_break_whk88",
"display_order",
"keywords",
"my_id",
"section_break_e91wx",
"tool_usage_content"
@ -96,11 +99,16 @@
"fieldtype": "Select",
"label": "Active Status",
"options": "Active\nInactive"
},
{
"fieldname": "keywords",
"fieldtype": "Small Text",
"label": "Keywords"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 17:06:34.665767",
"modified": "2023-09-15 10:35:02.922534",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Special Tool Information",

2
smart_service/phase_2/doctype/training_information/training_information.js

@ -31,7 +31,7 @@ function set_display_order(frm){
filters: {
"variant": cur_frm.doc.variant,
"language": frm.doc.language,
"feature_name": frm.doc.feature_name,
"vehicle": frm.doc.vehicle,
}
})
.then(count => {

4
smart_service/phase_2/doctype/training_information/training_information.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{vehicle}-{category}-{topic}-{language}",
@ -106,7 +108,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 17:11:02.486348",
"modified": "2023-09-04 17:41:29.001031",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Training Information",

4
smart_service/phase_2/doctype/training_information_master/training_information_master.json

@ -1,4 +1,6 @@
{
"_comments": "[]",
"_liked_by": "[]",
"actions": [],
"allow_rename": 1,
"autoname": "format:{category}-{topic}",
@ -48,7 +50,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-01 17:10:00.219314",
"modified": "2023-09-04 17:40:09.769420",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Training Information Master",

1475
smart_service/transactions/doctype/publish/publish.js

File diff suppressed because it is too large

4
smart_service/transactions/doctype/publish/publish.json

@ -319,7 +319,7 @@
"fieldname": "publish_module",
"fieldtype": "Select",
"label": "Module",
"options": "\nAutomotive System\nFeature Finder\nRepair service",
"options": "Automotive System\nFeature Finder\nRepair service",
"reqd": 1
},
{
@ -357,7 +357,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-08-28 10:37:21.374827",
"modified": "2023-09-04 12:02:32.394888",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Publish",

229
smart_service/transactions/doctype/publish/publish.py

@ -1,5 +1,7 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
from deepdiff import DeepDiff
import pandas as pd
import copy
import sys
from html import unescape
@ -13,7 +15,6 @@ from frappe.utils import logger
current_db_name = frappe.conf.get("db_name")
sys.tracebacklimit = 0
site_name = cstr(frappe.local.site)
import pandas as pd
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public" + "/files" + "/json_files" + "/phase2"
@ -22,12 +23,15 @@ frappe.utils.logger.set_log_level("DEBUG")
success_reponse = {"status": 1, "data": "", "message": ""}
failure_reponse = {"status": 0, "data": "", "error": ""}
module_name = 'feature_finder'
exisitng_var = []
new_variant = []
class Publish(Document):
def validate(self):
self.published_date = str(date.today())
self.published_by = frappe.session.user
# Selected variant and kilometer mapping details list
variant = []
for vm in self.get('publish_documents'):
@ -37,7 +41,7 @@ class Publish(Document):
# variant.append(vm.variant_mapping)
if vm.variant_mapping not in variant:
variant.append(vm.variant_mapping)
if self.publish_module=='Feature Finder' and self.feature_finder_publish_docs:
if self.publish_module == 'Feature Finder' and self.feature_finder_publish_docs:
for vm in self.get('feature_finder_publish_docs'):
if vm.variant not in variant:
variant.append(vm.variant)
@ -95,56 +99,6 @@ class Publish(Document):
# update_publish_mapping(
# self.vehicle, v, self.language, self.publish_module)
def onload1(self):
current_db_name = frappe.conf.get("db_name")
# To validate updated procedure status
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,
p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro where p.parent = '{1}' and
p.procedure_link = pro.name and p.procedure_link is not null""".format(current_db_name, self.name), as_dict=1)
l = len(procedure_status)
if procedure_status and self.publish_status == "Published":
for x in procedure_status:
for y in self.get("publish_documents"):
if y.procedure_link:
if x.procedure_link == y.procedure_link and y.update_procedure_status != y.procedure_status:
y.update_procedure_status = x.workflow_state
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """, (
x.workflow_state, self.name, x.procedure_link))
frappe.db.commit()
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status:
y.update_procedure_status = x.workflow_state
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s""", (
x.workflow_state, self.name, x.procedure_link))
frappe.db.commit()
if y.procedure_status == "Publish Ready":
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and not y.excluded_global:
y.excluded_global = "1"
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and x.workflow_state == "Draft" and y.procedure_status != "Publish Ready":
y.excluded_internal = "1"
y.save()
frappe.db.commit()
# Update system and variant mapping ststus
if self.publish_status == "Published" and self.publish_type == "Global":
current_db_name = frappe.conf.get("db_name")
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = "{1}"; """.format(
current_db_name, self.name), as_dict=True)
for global_name in global_publish:
update_mapping(self.variant_mapping, global_name.name)
u_id = frappe.get_all(
"User", filters={"name": frappe.session.user}, fields=["username"])
if u_id:
for i in u_id:
name = i.username
if not self.published_by and self.publish_status == "Published":
self.published_by = str(name)
frappe.db.set_value(
"Publish", self.name, "published_by", str(name))
frappe.db.commit()
def on_cancel(self):
# Published document should not allow to cancel
if self.publish_status == "Published":
@ -204,25 +158,26 @@ def update_procedure(vehicle, lang, publish_type, doc):
# Generate Publish versions
def update_publish_mapping(vehicle, variant, language, module,publish_type):
def update_publish_mapping(vehicle, variant, language, module, publish_type):
frappe.set_user('Administrator')
if module == 'Repair service':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"language": language,
"publish_type":publish_type
"publish_type": publish_type
}, fields=['name'])
if len(pub_data)>0:
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.db.sql(f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""",as_dict=1)
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""", as_dict=1)
frappe.db.commit()
else:
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"variant": variant,
"language": language,
"publish_type":publish_type
"publish_type": publish_type
}, fields=['name'])
if pub_data:
@ -255,11 +210,17 @@ def update_publish_mapping(vehicle, variant, language, module,publish_type):
@frappe.whitelist()
def cal_ver(vehicle, lang, publish_type, doc):
def cal_ver(vehicle, lang, publish_type, doc, publish_module):
update_procedure(vehicle, lang, publish_type, doc)
current_db_name = frappe.conf.get("db_name")
doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}";"""
if publish_module == 'Automotive System':
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}"
and publish_module = 'Automotive System';"""
.format(vehi=vehicle, lang=lang))
else:
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}"
and publish_module != 'Automotive System';"""
.format(vehi=vehicle, lang=lang))
v = 0.0
if publish_type == 'Global':
@ -334,16 +295,16 @@ def global_publish(doc):
@frappe.whitelist()
def generate_global_publish(name,module_name):
def generate_global_publish(name, module_name):
try:
res = frappe.get_doc("Publish", name)
if module_name=='Feature Finder':
if module_name == 'Feature Finder':
ret = frappe.get_doc({
"doctype": "Publish",
"vehicle": res.vehicle,
"publish_type": "Global",
"language": res.language,
"variant_mapping_details":res.variant_mapping_details,
"variant_mapping_details": res.variant_mapping_details,
"publish_status": 'To Publish',
"release_description": res.release_description,
"publish_module": res.publish_module,
@ -355,7 +316,7 @@ def generate_global_publish(name,module_name):
"vehicle": res.vehicle,
"publish_type": "Global",
"language": res.language,
"variant_mapping_details":res.variant_mapping,
"variant_mapping_details": res.variant_mapping,
"publish_status": 'To Publish',
"release_description": res.release_description,
"publish_module": res.publish_module,
@ -583,19 +544,22 @@ def get_service_repair(vehicle,
select * from `tabRepair Service Mapping` where vehicle = '{vehicle}' and language='{language_label}' and published = 0;
''', as_dict=1)
return data
def create_df(data_set):
feature_finder_tmp=json.dumps(data_set)
feature_finder_tmp = json.dumps(data_set)
df = pd.DataFrame(json.loads(feature_finder_tmp))
filter_group=df.groupby('variant')
keys=filter_group.groups.keys()
res={}
filter_group = df.groupby('variant')
keys = filter_group.groups.keys()
res = {}
for i in keys:
res[i]=(filter_group.get_group(i))
res1={}
for key,value in res.items():
res1[key]=value.to_dict('records')
res[i] = (filter_group.get_group(i))
res1 = {}
for key, value in res.items():
res1[key] = value.to_dict('records')
return res1
@frappe.whitelist()
def get_feature_finder(vehicle=None, variant=None, language_label=None):
try:
@ -715,13 +679,15 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
create_publish_folders(folder_url)
file_path = folder_url + "/" + publish_type + "/" + \
vehicle.replace(' ', '-') + '-feature_finder' + '.json'
global_file_path=folder_url + "/" + "Global" + "/" + \
global_file_path = folder_url + "/" + 'Global' + "/" + \
vehicle.replace(' ', '-') + '-feature_finder' + '.json'
'''Append Published Data to Json'''
logger.info(
f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}')
'''update existing global json file'''
if os.path.isfile(file_path) and publish_type == 'Internal':
if os.path.isfile(global_file_path) and publish_type == 'Internal':
with open(global_file_path) as f:
published_data = json.load(f)
for i in parent:
@ -731,10 +697,18 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
publish_repair_checksheet = 1
feature_finder_tmp.append(
feature_finder['data'][0])
feature_finder_tmp=create_df(feature_finder_tmp)
vehi_data = compare_get_data( {'data': published_data['data']}, {'data': feature_finder_tmp})
feature_finder_tmp = create_df(feature_finder_tmp)
vehi_data = compare_get_data({'data': published_data['data']}, {
'data': feature_finder_tmp})
if vehi_data:
find_distinct = set(exisitng_var)
new_variant_name = [
x for x in new_variant if x not in find_distinct]
vehi_data = add_new_val(
vehi_data, new_variant_name, feature_finder_tmp)
elif os.path.isfile(file_path) and publish_type == 'Global':
frappe.msgprint(str('called'))
with open(global_file_path) as f:
published_data = json.load(f)
for i in parent:
@ -744,8 +718,15 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
publish_repair_checksheet = 1
feature_finder_tmp.append(
feature_finder['data'][0])
feature_finder_tmp=create_df(feature_finder_tmp)
vehi_data = compare_get_data( {'data': published_data['data']}, {'data': feature_finder_tmp})
feature_finder_tmp = create_df(feature_finder_tmp)
vehi_data = compare_get_data({'data': published_data['data']}, {
'data': feature_finder_tmp})
if vehi_data:
find_distinct = set(exisitng_var)
new_variant_name = [
x for x in new_variant if x not in find_distinct]
vehi_data = add_new_val(
vehi_data, new_variant_name, feature_finder_tmp)
else:
for i in parent:
feature_finder = feature_finder_data(
@ -762,7 +743,7 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
feature_finder_tmp = get_latest_data(
{'data': feature_finder_tmp}, {'data': []})
vehi_data=create_df(feature_finder_tmp)
vehi_data = create_df(feature_finder_tmp)
""" Save publish file """
vehicle_data['data'] = vehi_data
@ -808,6 +789,7 @@ def get_latest_data(prev_data, latest_data):
except Exception as e:
frappe.throw(str(e))
def compare_get_data(prev_data, latest_data):
try:
logger_file = 'compare'
@ -815,60 +797,89 @@ def compare_get_data(prev_data, latest_data):
allow_site=True, file_count=100)
logger.info(
f"start compare data")
final_dic={}
final_dic=prev_data.copy()
for key,value in final_dic["data"].items():
for i in value:
if i['active_status']=="Inactive":
value.remove(i)
for key,value in latest_data["data"].items():
for i in value:
if i['active_status']=="Inactive":
value.remove(i)
#compare old & new json
for key,values in latest_data["data"].items():
final_dic = {}
final_dic = prev_data.copy()
# for key,value in latest_data["data"].items():
# for i in value:
# if i['active_status']=="Inactive":
# value.remove(i)
# compare old & new json
for key, values in latest_data["data"].items():
for i in latest_data["data"][key]:
check_key({key:i},final_dic["data"],'')
check_key({key: i}, final_dic["data"], '')
# for key,value in final_dic["data"].items():
# for i in value:
# if i['active_status']=="Inactive":
# value.remove(i)
logger.info(
f"End of compare data"+str(final_dic['data']))
return final_dic['data']
except Exception as e:
logger.error(str(e))
frappe.throw(str(e))
def check_key(key_name, old_data, type=None):
try:
frappe.msgprint(str(key_name))
logger_file = 'check key'
logger = frappe.logger(logger_file,
allow_site=True, file_count=100)
logger.info(
f"start of key data")
new_dict=[]
for key,val in key_name.items():
new_dict_lst = []
new_dict = {}
for key, val in key_name.items():
if key in old_data:
if val['name'] in old_data:
for old_key,old_val in old_data.items():
for old_key, old_val in old_data.items():
for i in old_val:
if val['name'] in old_val :
if old_key == key and val['name'] == i['name']:
i.update(val)
if val['name'] in i.values():
exisitng_var.append(val['name'])
cmp = DeepDiff(i, val)
if cmp.get('values_changed'):
indx = old_data[key].index(i)
old_data[key][indx] = val
else:
old_data[key].append(val)
indx = old_data[key].index(i)
old_data[key][indx] = val
else:
if val['name'] not in new_variant:
new_variant.append(val['name'])
else:
new_dict.append(val)
old_data[key]=new_dict
new_dict.update(val)
new_dict_lst.append(new_dict)
old_data[key] = new_dict_lst
# for key,val in key_name.items():
# if key in old_data:
# if val['name'] in old_data:
# for old_key,old_val in old_data.items():
# for i in old_val:
# if val['name'] in old_val :
# if old_key == key and val['name'] == i['name']:
# i.update(val)
# else:
# old_data[key].append(val)
# else:
# new_dict.append(val)
# old_data[key]=new_dict
logger.info(f"end of key data"+str(key_name))
except Exception as e:
logger.error(str(e))
return str(e)
def add_new_val(old_data, new_val_variant, dt_new):
for dt_key, dt_val in dt_new.items():
for i in dt_val:
if i['name'] in new_val_variant:
old_data[dt_key].append(i)
return old_data
def repair_checksheet_data(vehicle=None, language=None,
publish_type=None, parent=None):
try:
@ -880,6 +891,7 @@ def repair_checksheet_data(vehicle=None, language=None,
repair_service_details = frappe.db.sql(f"""select vehicle,vehicle_id,
name,language,check_list_name,
keywords,
active_status,display_order,my_id
from `tabRepair Service Mapping`
where vehicle = '{vehicle}'
@ -917,6 +929,7 @@ def feature_finder_data(vehicle=None, language=None,
feature_finder_details = []
if language == 'en':
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff.keywords,
ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status,
ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on
ff.features_names = ffm.feature_name
@ -927,6 +940,7 @@ def feature_finder_data(vehicle=None, language=None,
logger.info(feature_finder_details)
else:
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff.keywords,
ff.translated_feature_name as feature_name,ff.feature_category,
ff.display_order,ff.active_status,ffm.feature_pdf as pdf from `tabFeature Finder` ff
left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name
@ -995,7 +1009,8 @@ def max_publish_new_module(doc):
def cal_ver_new_module(vehicle, lang, publish_type, doc):
current_db_name = frappe.conf.get("db_name")
doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}" and publish_module!="Automotive System";"""
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}" and
publish_module!="Automotive System";"""
.format(vehi=vehicle, lang=lang))
v = 0.0
if publish_type == 'Global':

Loading…
Cancel
Save