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. 44
      smart_service/transactions/doctype/publish/publish.py

54
smart_service/apis/v2/master.py

@ -4,16 +4,39 @@ from urllib import request
import datetime import datetime
from frappe import utils from frappe import utils
import json import json
import html
import os import os
from smart_service.apis.app_user_login import input_validation from smart_service.apis.app_user_login import input_validation
from frappe.utils import cstr from frappe.utils import cstr
site_name = cstr(frappe.local.site) site_name = cstr(frappe.local.site)
BASE_URL = os.path.expanduser( BASE_URL = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public" "~") + "/frappe-bench/sites/" + site_name + "/public"
date_format = "%Y-%m-%d %H:%M:%S.%f" date_format = "%Y-%m-%d %H:%M:%S.%f"
current_db_name = frappe.conf.get("db_name") 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) @frappe.whitelist(methods=["POST"], allow_guest=1)
def get_role_mapping(): def get_role_mapping():
@ -172,11 +195,42 @@ def new_publish():
elif module == 'QWIK Service': elif module == 'QWIK Service':
flag, data = get_qwik_service(variant, language) flag, data = get_qwik_service(variant, language)
CLEANR = re.compile('<.*?>') 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: for dt in data:
if len(dt['consumables'])>0: if len(dt['consumables'])>0:
for con in dt['consumables']: for con in dt['consumables']:
if con['content']: if con['content']:
con['content'] = re.sub(CLEANR, '', 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", "fieldname": "content",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"in_list_view": 1, "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", "fieldname": "attach_file",
@ -49,7 +50,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-10-16 16:18:23.081846", "modified": "2023-10-18 14:57:50.775053",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Instructions", "name": "Instructions",

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

@ -35,7 +35,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-09-05 14:43:56.463049", "modified": "2023-10-19 11:41:22.915409",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Qwik Procedure", "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', fieldname: 'content',
fieldtype: 'Text Editor', fieldtype: 'Text Editor',
default: qwik_dialog_value.content, default: qwik_dialog_value.content,
reqd:1
}, },
{ {
label: 'Side', label: 'Side',

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

@ -116,11 +116,3 @@ def file_validation(pdf=None):
else: else:
return False, 2 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", "fieldname": "content",
"fieldtype": "Text Editor", "fieldtype": "Text Editor",
"in_list_view": 1, "in_list_view": 1,
"label": "Content" "label": "Content",
"mandatory_depends_on": "eval:doc.content_type;"
}, },
{ {
"fieldname": "content_type", "fieldname": "content_type",
@ -27,7 +28,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-09-04 17:19:19.054634", "modified": "2023-10-18 15:24:24.091233",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Qwik Service Content", "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) { onload: function (frm) {
// Set Display Order // Set Display Order
set_display_order(frm), set_display_order(frm),
teb_validation(frm) teb_validation(frm),
instructions(frm)
}, },
refresh: function (frm) { refresh: function (frm) {
// Set Display Order // Set Display Order
set_display_order(frm), set_display_order(frm),
teb_validation(frm) teb_validation(frm),
instructions(frm)
}, },
validate:function(frm){ validate:function(frm){
@ -244,7 +246,6 @@ function teb_validation(frm){
} }
function set_display_order(frm){ function set_display_order(frm){
if (frm.is_new()) { if (frm.is_new()) {
frm.set_df_property('display_order', 'read_only', 1); frm.set_df_property('display_order', 'read_only', 1);
@ -309,6 +310,20 @@ frappe.ui.form.on('Instructions', {
refresh_field("instructions"); refresh_field("instructions");
cur_frm.refresh_fields(); 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) { function check_field_character(field_name) {
if (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", "column_break_m3p9i",
"category", "category",
"aggregate_name", "aggregate_name",
"aggregate_image",
"aggregate_image_preview",
"column_break_wvkn2", "column_break_wvkn2",
"active_status", "active_status",
"display_order", "display_order",
@ -97,7 +95,7 @@
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Aggregate Name", "label": "Aggregate Name",
"reqd": 1, "mandatory_depends_on": "eval:doc.category !='TEB';",
"set_only_once": 1 "set_only_once": 1
}, },
{ {
@ -107,15 +105,8 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Category", "label": "Category",
"options": "Maintenance Service Category (MS)\nRepair Service Category (RS)\nOverhaul Service Category (OS)\nTEB", "options": "Maintenance Service Category (MS)\nRepair Service Category (RS)\nOverhaul Service Category (OS)\nTEB",
"reqd": 1 "reqd": 1,
}, "set_only_once": 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
}, },
{ {
"depends_on": "eval:doc.category !='TEB';", "depends_on": "eval:doc.category !='TEB';",
@ -178,18 +169,11 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Tool Name", "label": "Tool Name",
"reqd": 1 "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, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2023-10-16 17:24:43.937085", "modified": "2023-10-18 12:43:38.818592",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Special Tool Information", "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: if not self.is_new() and self.published == 1:
self.published = 0 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() @frappe.whitelist()

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

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

44
smart_service/transactions/doctype/publish/publish.py

@ -12,6 +12,7 @@ import json
from datetime import date from datetime import date
from frappe.utils import cstr from frappe.utils import cstr
from frappe.utils import logger from frappe.utils import logger
import re
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
sys.tracebacklimit = 0 sys.tracebacklimit = 0
site_name = cstr(frappe.local.site) site_name = cstr(frappe.local.site)
@ -199,18 +200,23 @@ def update_qwik_published_docs(self):
def update_publish_mapping(vehicle, variant, language, module, publish_type): def update_publish_mapping(vehicle, variant, language, module, publish_type):
frappe.set_user('Administrator') # frappe.set_user('Administrator')
try:
frappe.log_error("calling module",str(module))
if module == 'Repair service': if module == 'Repair service':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={ pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle, "vehicle": vehicle,
"language": language, "language": language,
"publish_type": publish_type "publish_type": publish_type
}, fields=['name']) }, fields=['name'])
frappe.log_error("pub_data",str(pub_data))
if len(pub_data) > 0: if len(pub_data) > 0:
for d in pub_data: for d in pub_data:
if d['name']: if d['name']:
frappe.log_error("kkkkkkkkkk")
frappe.db.sql( frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""", as_dict=1) f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1',publish_type='{publish_type}' where name ='{d['name']}'""")
frappe.db.commit() frappe.db.commit()
elif module == 'Special Tool': elif module == 'Special Tool':
@ -223,7 +229,7 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
for d in pub_data: for d in pub_data:
if d['name']: if d['name']:
frappe.db.sql( 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) 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() frappe.db.commit()
else: else:
pub_data = frappe.db.get_list('Module Publish Mapping', filters={ pub_data = frappe.db.get_list('Module Publish Mapping', filters={
@ -256,7 +262,8 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
doc.qwik_service = 1 doc.qwik_service = 1
doc.save() doc.save()
except Exception as e:
frappe.log_error("update_publish_mapping",str(e))
# def update_publish_status(self): # def update_publish_status(self):
# try: # try:
@ -1291,21 +1298,39 @@ 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, 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';''' % 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: 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' 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) && 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 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) 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 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) 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: 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` 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) 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` 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) 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} p['qwik_procedure'] = {'LHS': LHS, 'RHS': RHS}
logger.info( logger.info(
@ -1366,6 +1391,7 @@ def max_publish_new_module(doc):
@frappe.whitelist() @frappe.whitelist()
def cal_ver_new_module(vehicle, lang, publish_type, doc): def cal_ver_new_module(vehicle, lang, publish_type, doc):
try:
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
doc = frappe.get_doc("Publish", doc) doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}" and ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}" and
@ -1388,7 +1414,9 @@ def cal_ver_new_module(vehicle, lang, publish_type, doc):
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format( frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name)) current_db_name, v, doc.name))
frappe.db.commit() frappe.db.commit()
return v return {"status":1,"data":v}
except Exception as e:
return {"status":0,"data":"None","error":str(e)}
@frappe.whitelist() @frappe.whitelist()

Loading…
Cancel
Save