Browse Source

validation fixes in mst,qwik service and publish

version2
venkata akhil 11 months ago
parent
commit
f228502abb
  1. 54
      smart_service/apis/v2/master.py
  2. 5
      smart_service/phase_2/doctype/instructions/instructions.json
  3. 2
      smart_service/phase_2/doctype/qwik_procedure/qwik_procedure.json
  4. 1
      smart_service/phase_2/doctype/qwik_service/qwik_service.js
  5. 8
      smart_service/phase_2/doctype/qwik_service/qwik_service.py
  6. 5
      smart_service/phase_2/doctype/qwik_service_content/qwik_service_content.json
  7. 21
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  8. 24
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  9. 6
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py
  10. 8
      smart_service/transactions/doctype/publish/publish.js
  11. 184
      smart_service/transactions/doctype/publish/publish.py

54
smart_service/apis/v2/master.py

@ -4,16 +4,39 @@ from urllib import request
import datetime
from frappe import utils
import json
import html
import os
from smart_service.apis.app_user_login import input_validation
from frappe.utils import cstr
site_name = cstr(frappe.local.site)
BASE_URL = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
date_format = "%Y-%m-%d %H:%M:%S.%f"
current_db_name = frappe.conf.get("db_name")
# style="""<style>
# ul {
# margin: 0.75em 0;
# padding: 0 1em;
# list-style: none;
# }
# li:before {
# content: "";
# border-color: transparent #FF0000;
# border-style: solid;
# border-width: 0.35em 0 0.35em 0.45em;
# display: block;
# height: 0;
# width: 0;
# left: -1em;
# top: 0.9em;
# position: relative;
# }
# </style>"""
@frappe.whitelist(methods=["POST"], allow_guest=1)
def get_role_mapping():
@ -172,11 +195,42 @@ def new_publish():
elif module == 'QWIK Service':
flag, data = get_qwik_service(variant, language)
CLEANR = re.compile('<.*?>')
CLEANR_back_slash = re.compile("\"")
ul_html='<ul style="list-style-type: none; padding-left: 0px;"> <span style="width: 0;height: 0;border-top: 9px solid transparent;border-left: 12px solid red;border-bottom: 9px solid transparent;position: absolute;"></span>'
li_html='<li style="margin-left: 25px;padding: 0px 1px 5px 0px;"data-list=\"bullet\">'
cling_li='</li><span style="width: 0;height: 0;border-top: 9px solid transparent;border-left: 12px solid red;border-bottom: 9px solid transparent;position: absolute;"></span>'
cling_last='</ul>'
find_last_ul='<span style="width: 0;height: 0;border-top: 9px solid transparent;border-left: 12px solid red;border-bottom: 9px solid transparent;position: absolute;"></span></ul>'
for dt in data:
if len(dt['consumables'])>0:
for con in dt['consumables']:
if con['content']:
con['content'] = re.sub(CLEANR, '', con['content'])
if dt['qwik_procedure']:
for qp in dt['qwik_procedure']['LHS']:
if qp['content']:
qp['content'] = re.sub('<ul>', ul_html,qp['content'] )
qp['content'] = re.sub('<li data-list="bullet">',li_html,qp['content'])
qp['content'] = re.sub('</li>',cling_li,qp['content'])
qp['content'] = re.sub(find_last_ul,cling_last,qp['content'])
cnverted_data = re.sub(CLEANR_back_slash,"'",qp['content'])
qp['content'] = cnverted_data
for qp_rhs in dt['qwik_procedure']['RHS']:
if qp_rhs:
qp_rhs['content'] = re.sub('<ul>', ul_html,qp_rhs['content'] )
qp_rhs['content'] = re.sub('<li data-list="bullet">',li_html,qp_rhs['content'])
qp_rhs['content'] = re.sub('</li>',cling_li,qp_rhs['content'])
qp_rhs['content'] = re.sub(find_last_ul,cling_last,qp_rhs['content'])
cnverted_data = re.sub(CLEANR_back_slash,"'",qp_rhs['content'])
qp_rhs['content'] = cnverted_data

5
smart_service/phase_2/doctype/instructions/instructions.json

@ -31,7 +31,8 @@
"fieldname": "content",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Content"
"label": "Content",
"mandatory_depends_on": "eval:doc.step_name && doc.content_type !='Image' ||doc.content_type !='Video'||doc.content_type !='PDF'"
},
{
"fieldname": "attach_file",
@ -49,7 +50,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-10-16 16:18:23.081846",
"modified": "2023-10-18 14:57:50.775053",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Instructions",

2
smart_service/phase_2/doctype/qwik_procedure/qwik_procedure.json

@ -35,7 +35,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-09-05 14:43:56.463049",
"modified": "2023-10-19 11:41:22.915409",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Qwik Procedure",

1
smart_service/phase_2/doctype/qwik_service/qwik_service.js

@ -366,6 +366,7 @@ function custom_tab_html(frm){
fieldname: 'content',
fieldtype: 'Text Editor',
default: qwik_dialog_value.content,
reqd:1
},
{
label: 'Side',

8
smart_service/phase_2/doctype/qwik_service/qwik_service.py

@ -116,11 +116,3 @@ def file_validation(pdf=None):
else:
return False, 2
# def delete_file(file_url, attached_to_doctype, attached_to_field, docname, is_child=None):
# image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url,
# "attached_to_doctype": attached_to_doctype,
# "attached_to_field": attached_to_field,
# "attached_to_name": docname})
# if len(image_name) > 0:
# frappe.delete_doc('File', image_name[0]['name'])
# return True

5
smart_service/phase_2/doctype/qwik_service_content/qwik_service_content.json

@ -14,7 +14,8 @@
"fieldname": "content",
"fieldtype": "Text Editor",
"in_list_view": 1,
"label": "Content"
"label": "Content",
"mandatory_depends_on": "eval:doc.content_type;"
},
{
"fieldname": "content_type",
@ -27,7 +28,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-09-04 17:19:19.054634",
"modified": "2023-10-18 15:24:24.091233",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Qwik Service Content",

21
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -7,12 +7,14 @@ frappe.ui.form.on('Special Tool Information', {
onload: function (frm) {
// Set Display Order
set_display_order(frm),
teb_validation(frm)
teb_validation(frm),
instructions(frm)
},
refresh: function (frm) {
// Set Display Order
set_display_order(frm),
teb_validation(frm)
teb_validation(frm),
instructions(frm)
},
validate:function(frm){
@ -244,7 +246,6 @@ function teb_validation(frm){
}
function set_display_order(frm){
if (frm.is_new()) {
frm.set_df_property('display_order', 'read_only', 1);
@ -309,6 +310,20 @@ frappe.ui.form.on('Instructions', {
refresh_field("instructions");
cur_frm.refresh_fields();
},
// validate:function(frm, cdt, cdn){
// cur_frm.refresh_fields("step_name")
// var select_value = locals[cdt][cdn];
// var x = select_value.idx - 1;
// if (select_value.step_name || select_value.content_type == 'Image' || select_value.content_type == 'Video' || select_value.content_type == 'PDF'){
// cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.reqd = 0;
// }
// else{
// cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.reqd = 1;
// }
// cur_frm.refresh_fields("step_name")
// refresh_field("instructions");
// cur_frm.refresh_fields();
// }
})
function check_field_character(field_name) {
if (field_name) {

24
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -16,8 +16,6 @@
"column_break_m3p9i",
"category",
"aggregate_name",
"aggregate_image",
"aggregate_image_preview",
"column_break_wvkn2",
"active_status",
"display_order",
@ -97,7 +95,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Aggregate Name",
"reqd": 1,
"mandatory_depends_on": "eval:doc.category !='TEB';",
"set_only_once": 1
},
{
@ -107,15 +105,8 @@
"in_standard_filter": 1,
"label": "Category",
"options": "Maintenance Service Category (MS)\nRepair Service Category (RS)\nOverhaul Service Category (OS)\nTEB",
"reqd": 1
},
{
"depends_on": "eval:doc.category !='TEB';",
"description": "Upload *.png(1280x720 pixel) 1 MB",
"fieldname": "aggregate_image",
"fieldtype": "Attach Image",
"label": "Aggregate Image",
"reqd": 1
"reqd": 1,
"set_only_once": 1
},
{
"depends_on": "eval:doc.category !='TEB';",
@ -178,18 +169,11 @@
"in_standard_filter": 1,
"label": "Tool Name",
"reqd": 1
},
{
"depends_on": "eval:doc.aggregate_image && doc.category!=\"TEB\";;",
"fieldname": "aggregate_image_preview",
"fieldtype": "Image",
"label": "Aggregate Image Preview",
"options": "aggregate_image"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-16 17:24:43.937085",
"modified": "2023-10-18 12:43:38.818592",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Special Tool Information",

6
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -29,6 +29,12 @@ class SpecialToolInformation(Document):
if not self.is_new() and self.published == 1:
self.published = 0
# if self.instructions:
# for d in self.instructions:
# if(d.step_name and d.content_type == 'Heading' or d.content_type == 'Description' or d.content_type == 'Caution' or d.content_type == 'Warning' or d.content_type == 'Notice'):
# if d.content=="":
# frappe.msgprint(d.content)
# frappe.throw("Content should not be empty")
@frappe.whitelist()

8
smart_service/transactions/doctype/publish/publish.js

@ -618,12 +618,16 @@ frappe.ui.form.on("Publish", {
},
callback: function (r) {
if (r.message) {
frm.set_value("version", r.message);
if (r.message['status'] == 1) {
frm.set_value("version", r.message['data']);
cur_frm.refresh_field("version");
frm.set_value("actual_published_date", frappe.datetime.nowdate());
window.location.reload();
}
else{
frappe.msgprint("Failed To Publish")
}
},
});
}

184
smart_service/transactions/doctype/publish/publish.py

@ -12,6 +12,7 @@ import json
from datetime import date
from frappe.utils import cstr
from frappe.utils import logger
import re
current_db_name = frappe.conf.get("db_name")
sys.tracebacklimit = 0
site_name = cstr(frappe.local.site)
@ -199,64 +200,70 @@ def update_qwik_published_docs(self):
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
}, fields=['name'])
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.commit()
elif module == 'Special Tool':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"language": language,
"publish_type": publish_type
}, fields=['name'])
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set mahindra_special_tool_information='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
}, fields=['name'])
if pub_data:
doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name'])
else:
doc = frappe.get_doc({
'doctype': 'Module Publish Mapping',
# frappe.set_user('Administrator')
try:
frappe.log_error("calling module",str(module))
if module == 'Repair service':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"variant": variant,
"language": language,
"publish_type": publish_type
})
if module == 'Automotive System':
doc.automotive_system = 1
doc.tsb = 1
doc.fsa = 1
doc.tekalert = 1
elif module == 'Feature Finder':
doc.feature_finder = 1
}, fields=['name'])
frappe.log_error("pub_data",str(pub_data))
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.log_error("kkkkkkkkkk")
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1',publish_type='{publish_type}' where name ='{d['name']}'""")
elif module == 'Qwik Service':
doc.qwik_service = 1
frappe.db.commit()
doc.save()
elif module == 'Special Tool':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"language": language,
"publish_type": publish_type
}, fields=['name'])
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set mahindra_special_tool_information='1',publish_type='{publish_type}' 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
}, fields=['name'])
if pub_data:
doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name'])
else:
doc = frappe.get_doc({
'doctype': 'Module Publish Mapping',
"vehicle": vehicle,
"variant": variant,
"language": language,
"publish_type": publish_type
})
if module == 'Automotive System':
doc.automotive_system = 1
doc.tsb = 1
doc.fsa = 1
doc.tekalert = 1
elif module == 'Feature Finder':
doc.feature_finder = 1
elif module == 'Qwik Service':
doc.qwik_service = 1
doc.save()
except Exception as e:
frappe.log_error("update_publish_mapping",str(e))
# def update_publish_status(self):
# try:
@ -1290,22 +1297,40 @@ def qwik_service_data(language, publish_type, variant, parent, vehicle):
qwik_service_details = frappe.db.sql('''select name,variant,vehicle,kilometers,language,service_time,active_status,
pdf,display_order,keywords,my_id from `tabQwik Service` where name='%s';''' %
(parent), as_dict=1)
(parent), as_dict=1)
CLEANR = re.compile('<.*?>')
for q in qwik_service_details:
q['pre_work'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where parent='%s'
&& content_type = 'Pre-work' order by display_order;''' % (q['name']), as_dict=1)
# if q['pre_work']:
# for con in q['pre_work']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
q['consumables'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where
parent='%s' && content_type = 'Consumables' order by display_order;''' % (q['name']), as_dict=1)
# if q['consumables']:
# for con in q['consumables']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
q['tools'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where
parent='%s' && content_type = 'Tools' order by display_order;''' % (q['name']), as_dict=1)
# if q['tools']:
# for con in q['tools']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
for p in qwik_service_details:
# p['qwik_procedure'] = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure`
# where parent ='%s';''' % (p['name']), as_dict=1)
LHS = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure`
where parent ='%s' and side = 'LHS';''' % (p['name']), as_dict=1)
# if LHS:
# for con in LHS:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
RHS = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure`
where parent ='%s' and side = 'RHS';''' % (p['name']), as_dict=1)
# if RHS:
# for con in RHS:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
p['qwik_procedure'] = {'LHS': LHS, 'RHS': RHS}
logger.info(
@ -1366,29 +1391,32 @@ def max_publish_new_module(doc):
@frappe.whitelist()
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";"""
.format(vehi=vehicle, lang=lang))
v = 0.0
if publish_type == 'Global':
if ver[0][0] == None:
v = 1.0
else:
v = int(float(ver[0][0])) + 1.0
try:
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";"""
.format(vehi=vehicle, lang=lang))
v = 0.0
if publish_type == 'Global':
if ver[0][0] == None:
v = 1.0
else:
v = int(float(ver[0][0])) + 1.0
elif publish_type == 'Internal':
if ver[0][0] == None:
v = 0.01
else:
v = float(ver[0][0]) + 0.01
v = "{:.2f}".format(v)
doc.version = v
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name))
frappe.db.commit()
return v
elif publish_type == 'Internal':
if ver[0][0] == None:
v = 0.01
else:
v = float(ver[0][0]) + 0.01
v = "{:.2f}".format(v)
doc.version = v
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name))
frappe.db.commit()
return {"status":1,"data":v}
except Exception as e:
return {"status":0,"data":"None","error":str(e)}
@frappe.whitelist()

Loading…
Cancel
Save