Browse Source

Publish Changes

version2
venkata akhil 12 months ago
parent
commit
3d55c6285e
  1. 290
      smart_service/apis/v2/master.py
  2. 115
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

290
smart_service/apis/v2/master.py

@ -18,23 +18,23 @@ 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> # style="""<style>
# ul { # ul {
# margin: 0.75em 0; # margin: 0.75em 0;
# padding: 0 1em; # padding: 0 1em;
# list-style: none; # list-style: none;
# } # }
# li:before { # li:before {
# content: ""; # content: "";
# border-color: transparent #FF0000; # border-color: transparent #FF0000;
# border-style: solid; # border-style: solid;
# border-width: 0.35em 0 0.35em 0.45em; # border-width: 0.35em 0 0.35em 0.45em;
# display: block; # display: block;
# height: 0; # height: 0;
# width: 0; # width: 0;
# left: -1em; # left: -1em;
# top: 0.9em; # top: 0.9em;
# position: relative; # position: relative;
# } # }
# </style>""" # </style>"""
@ -175,7 +175,7 @@ def get_training_information(vehicle, language):
@frappe.whitelist(methods=['POST']) @frappe.whitelist(methods=['POST'])
def new_publish(): def old_publish():
req = json.loads(frappe.request.data) req = json.loads(frappe.request.data)
try: try:
module = req['module'] module = req['module']
@ -187,7 +187,7 @@ def new_publish():
data = [] data = []
if module == 'Feature Finder': if module == 'Feature Finder':
flag, data = get_feature_finder(vehicle, variant, language) flag, data = get_feature_finder(vehicle, variant, language)
elif module == 'Repair/Service Check Sheet': elif module == 'Repair/Service Check Sheet':
@ -196,98 +196,119 @@ 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("\"") CLEANR_back_slash = re.compile("\"")
ul_html='<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' ul_html = '<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>'
li_html='<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list=\"bullet\">' li_html = '<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list=\"bullet\">'
cling_li='</li><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' cling_li = '</li><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>'
cling_last='</ul>' cling_last = '</ul>'
find_last_ul='<span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span></ul>' find_last_ul = '<span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></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 len(dt['pre_work'])>0: # if len(dt['pre_work'])>0:
for pw in dt['pre_work']: for pw in dt['pre_work']:
reg_str = "<p>" reg_str = "<p>"
reg_str1 = "<div>" reg_str1 = "<div>"
if pw['content']: if pw['content']:
res = str(pw['content']).find('<div>') res = str(pw['content']).find('<div>')
res1 = str(pw['content']).find('<p>') res1 = str(pw['content']).find('<p>')
if res == 1: if res == 1:
pw['content'] = re.sub('<div>','',pw['content']) pw['content'] = re.sub(
pw['content'] = re.sub('</div>','',pw['content']) '<div>', '', pw['content'])
pw['content'] = re.sub('<p>','<div style="color: #fff;margin:0px !important;">',pw['content'] ) pw['content'] = re.sub(
pw['content'] = re.sub('</p>','</div>',pw['content'] ) '</div>', '', pw['content'])
cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) pw['content'] = re.sub(
'<p>', '<div style="color: #fff;margin:0px !important;">', pw['content'])
pw['content'] = re.sub(
'</p>', '</div>', pw['content'])
cnverted_data = re.sub(
CLEANR_back_slash, "'", pw['content'])
pw['content'] = cnverted_data pw['content'] = cnverted_data
else: else:
pw['content'] = '<div style="color: #fff;margin:0px !important;">'+pw['content']+'</div>' pw['content'] = '<div style="color: #fff;margin:0px !important;">' + \
cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) pw['content']+'</div>'
cnverted_data = re.sub(
CLEANR_back_slash, "'", pw['content'])
frappe.log_error(str('if')+pw['content']) frappe.log_error(str('if')+pw['content'])
pw['content'] = cnverted_data pw['content'] = cnverted_data
if res1 == 1: if res1 == 1:
pw['content'] = re.sub('<div>','',pw['content']) pw['content'] = re.sub(
pw['content'] = re.sub('</div>','',pw['content']) '<div>', '', pw['content'])
pw['content'] = re.sub('<p>','<div style="color: #fff;margin:0px !important;">',pw['content'] ) pw['content'] = re.sub(
pw['content'] = re.sub('</p>','</div>',pw['content'] ) '</div>', '', pw['content'])
cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) pw['content'] = re.sub(
'<p>', '<div style="color: #fff;margin:0px !important;">', pw['content'])
pw['content'] = re.sub(
'</p>', '</div>', pw['content'])
cnverted_data = re.sub(
CLEANR_back_slash, "'", pw['content'])
pw['content'] = cnverted_data pw['content'] = cnverted_data
else: else:
frappe.log_error(str('else')+pw['content']) frappe.log_error(str('else')+pw['content'])
pw['content'] = '<div style="color: #fff;margin:0px !important;">'+pw['content']+'</div>' pw['content'] = '<div style="color: #fff;margin:0px !important;">' + \
cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) pw['content']+'</div>'
cnverted_data = re.sub(
CLEANR_back_slash, "'", pw['content'])
frappe.log_error(str('if')+pw['content']) frappe.log_error(str('if')+pw['content'])
pw['content'] = cnverted_data pw['content'] = cnverted_data
if dt['qwik_procedure']: if dt['qwik_procedure']:
for qp in dt['qwik_procedure']['LHS']: for qp in dt['qwik_procedure']['LHS']:
if qp['content']: if qp['content']:
qp['content'] = re.sub('<ul>', ul_html,qp['content'] ) qp['content'] = re.sub(
qp['content'] = re.sub('<li data-list="bullet">',li_html,qp['content']) '<ul>', ul_html, qp['content'])
clsing_li_tag = re.sub('</li>',cling_li,qp['content']) qp['content'] = re.sub(
'<li data-list="bullet">', li_html, qp['content'])
clsing_li_tag = re.sub(
'</li>', cling_li, qp['content'])
qp['content'] = clsing_li_tag qp['content'] = clsing_li_tag
res = re.sub(find_last_ul,cling_last,qp['content']) res = re.sub(
find_last_ul, cling_last, qp['content'])
qp['content'] = res qp['content'] = res
cnverted_data = re.sub(CLEANR_back_slash,"'",qp['content']) cnverted_data = re.sub(
CLEANR_back_slash, "'", qp['content'])
qp['content'] = cnverted_data qp['content'] = cnverted_data
for qp_rhs in dt['qwik_procedure']['RHS']: for qp_rhs in dt['qwik_procedure']['RHS']:
if qp_rhs: if qp_rhs:
qp_rhs['content'] = re.sub('<ul>', ul_html,qp_rhs['content'] ) qp_rhs['content'] = re.sub(
qp_rhs['content'] = re.sub('<li data-list="bullet">',li_html,qp_rhs['content']) '<ul>', ul_html, qp_rhs['content'])
qp_rhs['content'] = re.sub('</li>',cling_li,qp_rhs['content']) qp_rhs['content'] = re.sub(
qp_rhs['content'] = re.sub(find_last_ul,cling_last,qp_rhs['content']) '<li data-list="bullet">', li_html, qp_rhs['content'])
cnverted_data = re.sub(CLEANR_back_slash,"'",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 qp_rhs['content'] = cnverted_data
elif module == 'Training Information': elif module == 'Training Information':
# flag, data = get_training_information(vehicle, language) # flag, data = get_training_information(vehicle, language)
pass pass
elif module == 'Mahindra Special Tool Information': elif module == 'Mahindra Special Tool Information':
CLEANR_back_slash = re.compile("\"") CLEANR_back_slash = re.compile("\"")
html_code_ul = '<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' html_code_ul = '<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>'
html_code_li = '<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list="bullet">' html_code_li = '<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list="bullet">'
flag, data = get_special_tool_information(vehicle) flag, data = get_special_tool_information(vehicle)
for dt in data: for dt in data:
if len(dt['instructions'])>0: if len(dt['instructions']) > 0:
for c_t in dt['instructions']: for c_t in dt['instructions']:
if c_t['content_type'] == 'Description': if c_t['content_type'] == 'Description':
if c_t['content']: if c_t['content']:
c_t['content'] = html_code_ul+html_code_li+c_t['content']+'</li>'+'</ul>' c_t['content'] = html_code_ul + \
cnverted_data = re.sub(CLEANR_back_slash,"'",c_t['content']) html_code_li+c_t['content']+'</li>'+'</ul>'
cnverted_data = re.sub(
CLEANR_back_slash, "'", c_t['content'])
c_t['content'] = cnverted_data c_t['content'] = cnverted_data
elif module == 'PDI Inspection': elif module == 'PDI Inspection':
pass pass
@ -311,8 +332,8 @@ def new_publish():
return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None} return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None}
@frappe.whitelist(methods=['POST']) @frappe.whitelist(methods=['POST'], allow_guest=1)
def new_publish1(): def new_publish():
req = json.loads(frappe.request.data) req = json.loads(frappe.request.data)
try: try:
module = req['module'] module = req['module']
@ -328,30 +349,109 @@ def new_publish1():
if len(publish_type) > 0: if len(publish_type) > 0:
publish_type = publish_type[0]['publish_type'] publish_type = publish_type[0]['publish_type']
else:
return {"status": 0, "error": "Publish Type Not Set For: " + iid}
BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \ BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \
str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/' str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/'
FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \
str(vehicle) + '/' + str(language) + '/' + str(publish_type) + \
'/'+"{}".format(publish_type)+" Full Update/"
if module == 'Feature Finder': if module == 'Feature Finder':
with open(BASE_PATH + str(vehicle) + '-feature_finder.json') as outfile: if publish_type == 'Internal':
data = json.load(outfile) if os.path.isfile(FULL_UPDATE_PATH):
data = data['data'] with open(FULL_UPDATE_PATH + str(vehicle) + '-feature_finder_full_update.json') as outfile:
filter_json = filter_publish_json(data, variant) data = json.load(outfile)
data = filter_json # data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
else:
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \
str(vehicle) + '/' + str(language) + \
'/' + str(publish_type) + '/'
with open(LATEST_GLOBAL_PATH + str(vehicle) + '-feature_finder.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
else:
if os.path.isfile(FULL_UPDATE_PATH):
with open(FULL_UPDATE_PATH + str(vehicle) + '-feature_finder_full_update.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
elif module == 'Repair/Service Check Sheet': elif module == 'Repair/Service Check Sheet':
with open(BASE_PATH + str(vehicle) + '-repair_check_sheet.json') as outfile: if publish_type == 'Internal':
data = json.load(outfile) if os.path.isfile(FULL_UPDATE_PATH):
data = data['data'] with open(FULL_UPDATE_PATH + str(vehicle) + '-repair_check_sheet_full_update.json') as outfile:
filter_json = filter_publish_json(data, variant) data = json.load(outfile)
data = filter_json # data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
else:
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \
str(vehicle) + '/' + str(language) + \
'/' + str(publish_type) + '/'
with open(LATEST_GLOBAL_PATH + str(vehicle) + '-repair_check_sheet.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
else:
if os.path.isfile(FULL_UPDATE_PATH):
with open(FULL_UPDATE_PATH + str(vehicle) + '-repair_check_sheet_full_update.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get(variant)
elif module == 'QWIK Service': elif module == 'QWIK Service':
with open(BASE_PATH + str(vehicle) + '-qwik_service.json') as outfile: if publish_type == 'Internal':
data = json.load(outfile) if os.path.isfile(FULL_UPDATE_PATH):
data = data['data'] with open(FULL_UPDATE_PATH + str(vehicle) + '-qwik_service_full_update.json') as outfile:
filter_json = filter_publish_json(data, variant) data = json.load(outfile)
data = filter_json # data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get('variant')
else:
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \
str(vehicle) + '/' + str(language) + \
'/' + str(publish_type) + '/'
with open(LATEST_GLOBAL_PATH + str(vehicle) + '-repair_check_sheet.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get('variant')
else:
if os.path.isfile(FULL_UPDATE_PATH):
with open(FULL_UPDATE_PATH + str(vehicle) + '-qwik_service_full_update.json') as outfile:
data = json.load(outfile)
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data.get('data')
data = data.get('variant')
elif module == 'Training Information': elif module == 'Training Information':
pass pass
@ -359,9 +459,11 @@ def new_publish1():
elif module == 'Mahindra Special Tool Information': elif module == 'Mahindra Special Tool Information':
with open(BASE_PATH + str(vehicle) + '-special_tool_information.json') as outfile: with open(BASE_PATH + str(vehicle) + '-special_tool_information.json') as outfile:
data = json.load(outfile) data = json.load(outfile)
data = data['data'] # data = data['data']
filter_json = filter_publish_json(data, variant) # filter_json = filter_publish_json(data, variant)
data = filter_json # data = filter_json
data = data.get('data')
data = data.get(variant)
elif module == 'PDI Inspection': elif module == 'PDI Inspection':
pass pass
@ -454,10 +556,22 @@ def update_publish_mapping(vehicle, variant, language, module):
return 1 return 1
def filter_publish_json(src_json, filter_cond): # def filter_publish_json(src_json, filter_cond):
# try:
# # filtered_json = [src_json.get(filter_cond, None) for d in src_json]
# # if not filtered_json:
# # return None
# # return filtered_json[0]
# frappe.log_error(str(filter_cond))
# return src_json[filter_cond]
# except Exception as e:
# frappe.throw(str(e))
def valid_input(input):
try: try:
filtered_json = [src_json.get(filter_cond, None) for d in src_json] for key, val in input.items():
pass
return filtered_json[0]
except Exception as e: except Exception as e:
frappe.throw(str(e)) return str(e)

115
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -5,75 +5,72 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
import sys import sys
from frappe import _ from frappe import _
sys.tracebacklimit=0 sys.tracebacklimit = 0
class KilometerMapping(Document): class KilometerMapping(Document):
def onload(self): def onload(self):
###Kilometer mapping config table idx allignment # Kilometer mapping config table idx allignment
if(self.config_kilometer): if (self.config_kilometer):
idx = 0 idx = 0
for x in self.get("config_kilometer"): for x in self.get("config_kilometer"):
idx += 1 idx += 1
x.idx = idx x.idx = idx
@frappe.whitelist() @frappe.whitelist()
def get_system(doc): def get_system(doc):
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True) system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(
if system_map: current_db_name, doc), as_dict=True)
for s in system_map: if system_map:
doc = frappe.get_doc("System Mapping",s.name) for s in system_map:
system = frappe.db.sql("""select sub_systems,mat from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True) doc = frappe.get_doc("System Mapping", s.name)
return system system = frappe.db.sql("""select sub_systems,mat from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name, s.name), as_dict=True)
return system
@frappe.whitelist() @frappe.whitelist()
def get_subsystem(doc): def get_subsystem(doc):
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True) system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(
if system_map: current_db_name, doc), as_dict=True)
for s in system_map: if system_map:
doc = frappe.get_doc("System Mapping",s.name) for s in system_map:
sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True) doc = frappe.get_doc("System Mapping", s.name)
return sub_system sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name, s.name), as_dict=True)
return sub_system
@frappe.whitelist() @frappe.whitelist()
def update_duplicate_km(doc,kilometer): def update_duplicate_km(doc, kilometer):
km = frappe.get_doc("Kilometer Mapping",doc)
output = frappe.db.sql("""select kilometer,mat,sub_systems,row_name from `tabKilometer Mapping_Items` where parent = '{0}' and kilometer = '{1}' order by kilometer""".format(doc,kilometer),as_dict=True)
# frappe.msgprint(str(output))
for data in output:
# frappe.msgprint(str(data['mat']))
km.append('duplicate_kilometer_mapping_items', {
'kilometer': data['kilometer'],
'mat': data['mat'],
'sub_systems': data['sub_systems'],
'row_name': data['row_name']
})
km.save(ignore_permissions=True)
@frappe.whitelist()
def get_config_kilometer(doc,docname):
res = frappe.db.sql(f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""",as_dict=1)
ress = frappe.get_doc("Kilometer Mapping",docname)
ress.config_kilometer = []
for d in res:
ress.append("config_kilometer",d)
ress.add_comment(text=_("data added"+str(res)))
ress.save()
frappe.db.commit()
return {"status":"success"}
# @frappe.whitelist() km = frappe.get_doc("Kilometer Mapping", doc)
# def km_filter(parent = None , record = None, km = None): output = frappe.db.sql("""select kilometer,mat,sub_systems,row_name from `tabKilometer Mapping_Items` where parent = '{0}' and kilometer = '{1}' order by kilometer""".format(
# if record == "All": doc, kilometer), as_dict=True)
# km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by length(kilometer),kilometer;""",as_dict = 1) # frappe.msgprint(str(output))
for data in output:
# frappe.msgprint(str(data['mat']))
km.append('duplicate_kilometer_mapping_items', {
'kilometer': data['kilometer'],
'mat': data['mat'],
'sub_systems': data['sub_systems'],
'row_name': data['row_name']
})
km.save(ignore_permissions=True)
# else:
# km_filters =frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" and kilometer ="{km}" order by length(kilometer),kilometer """,as_dict = 1)
# return km_filters @frappe.whitelist()
def get_config_kilometer(doc, docname):
res = frappe.db.sql(
f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""", as_dict=1)
ress = frappe.get_doc("Kilometer Mapping", docname)
ress.config_kilometer = []
for d in res:
ress.append("config_kilometer", d)
ress.add_comment(text=_("data added"+str(res)))
ress.save()
frappe.db.commit()
return {"status": "success"}

Loading…
Cancel
Save