From 3d55c6285e3ba2fd79816b4f61a185baeb02bef8 Mon Sep 17 00:00:00 2001 From: venkata akhil Date: Wed, 29 Nov 2023 10:15:05 +0530 Subject: [PATCH] Publish Changes --- smart_service/apis/v2/master.py | 290 ++++++++++++------ .../kilometer_mapping/kilometer_mapping.py | 115 ++++--- 2 files changed, 258 insertions(+), 147 deletions(-) diff --git a/smart_service/apis/v2/master.py b/smart_service/apis/v2/master.py index 70bbb56..7385f9f 100644 --- a/smart_service/apis/v2/master.py +++ b/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") # style="""""" @@ -175,7 +175,7 @@ def get_training_information(vehicle, language): @frappe.whitelist(methods=['POST']) -def new_publish(): +def old_publish(): req = json.loads(frappe.request.data) try: module = req['module'] @@ -187,7 +187,7 @@ def new_publish(): data = [] if module == 'Feature Finder': - + flag, data = get_feature_finder(vehicle, variant, language) elif module == 'Repair/Service Check Sheet': @@ -196,98 +196,119 @@ def new_publish(): elif module == 'QWIK Service': flag, data = get_qwik_service(variant, language) CLEANR = re.compile('<.*?>') - CLEANR_back_slash = re.compile("\"") - ul_html='' - find_last_ul='' - + CLEANR_back_slash = re.compile("\"") + ul_html = '' + find_last_ul = '' + for dt in data: - if len(dt['consumables'])>0: - + if len(dt['consumables']) > 0: + for con in dt['consumables']: if con['content']: con['content'] = re.sub(CLEANR, '', con['content']) # if len(dt['pre_work'])>0: for pw in dt['pre_work']: - reg_str = "

" + reg_str = "

" reg_str1 = "

" if pw['content']: res = str(pw['content']).find('
') res1 = str(pw['content']).find('

') if res == 1: - pw['content'] = re.sub('

','',pw['content']) - pw['content'] = re.sub('
','',pw['content']) - pw['content'] = re.sub('

','

',pw['content'] ) - pw['content'] = re.sub('

','
',pw['content'] ) - cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) + pw['content'] = re.sub( + '
', '', pw['content']) + pw['content'] = re.sub( + '
', '', pw['content']) + pw['content'] = re.sub( + '

', '

', pw['content']) + pw['content'] = re.sub( + '

', '
', pw['content']) + cnverted_data = re.sub( + CLEANR_back_slash, "'", pw['content']) pw['content'] = cnverted_data else: - pw['content'] = '
'+pw['content']+'
' - cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) + pw['content'] = '
' + \ + pw['content']+'
' + cnverted_data = re.sub( + CLEANR_back_slash, "'", pw['content']) frappe.log_error(str('if')+pw['content']) pw['content'] = cnverted_data if res1 == 1: - pw['content'] = re.sub('
','',pw['content']) - pw['content'] = re.sub('
','',pw['content']) - pw['content'] = re.sub('

','

',pw['content'] ) - pw['content'] = re.sub('

','
',pw['content'] ) - cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) + pw['content'] = re.sub( + '
', '', pw['content']) + pw['content'] = re.sub( + '
', '', pw['content']) + pw['content'] = re.sub( + '

', '

', pw['content']) + pw['content'] = re.sub( + '

', '
', pw['content']) + cnverted_data = re.sub( + CLEANR_back_slash, "'", pw['content']) pw['content'] = cnverted_data else: frappe.log_error(str('else')+pw['content']) - pw['content'] = '
'+pw['content']+'
' - cnverted_data = re.sub(CLEANR_back_slash,"'",pw['content']) + pw['content'] = '
' + \ + pw['content']+'
' + cnverted_data = re.sub( + CLEANR_back_slash, "'", pw['content']) frappe.log_error(str('if')+pw['content']) pw['content'] = cnverted_data - if dt['qwik_procedure']: for qp in dt['qwik_procedure']['LHS']: if qp['content']: - qp['content'] = re.sub('
    ', ul_html,qp['content'] ) - qp['content'] = re.sub('
  • ',li_html,qp['content']) - clsing_li_tag = re.sub('
  • ',cling_li,qp['content']) + qp['content'] = re.sub( + '
      ', ul_html, qp['content']) + qp['content'] = re.sub( + '
    • ', li_html, qp['content']) + clsing_li_tag = re.sub( + '
    • ', cling_li, qp['content']) 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 - - cnverted_data = re.sub(CLEANR_back_slash,"'",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_html,qp_rhs['content'] ) - qp_rhs['content'] = re.sub('
      • ',li_html,qp_rhs['content']) - qp_rhs['content'] = re.sub('
      • ',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'] = re.sub( + '
          ', ul_html, qp_rhs['content']) + qp_rhs['content'] = re.sub( + '
        • ', li_html, qp_rhs['content']) + qp_rhs['content'] = re.sub( + '
        • ', 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 - - elif module == 'Training Information': # flag, data = get_training_information(vehicle, language) pass elif module == 'Mahindra Special Tool Information': - CLEANR_back_slash = re.compile("\"") + CLEANR_back_slash = re.compile("\"") html_code_ul = '
            ' - html_code_li = '
          • ' + html_code_li = '
          • ' flag, data = get_special_tool_information(vehicle) for dt in data: - if len(dt['instructions'])>0: + if len(dt['instructions']) > 0: for c_t in dt['instructions']: if c_t['content_type'] == 'Description': if c_t['content']: - c_t['content'] = html_code_ul+html_code_li+c_t['content']+'
          • '+'
          ' - cnverted_data = re.sub(CLEANR_back_slash,"'",c_t['content']) + c_t['content'] = html_code_ul + \ + html_code_li+c_t['content']+''+'
        ' + cnverted_data = re.sub( + CLEANR_back_slash, "'", c_t['content']) c_t['content'] = cnverted_data - elif module == 'PDI Inspection': pass @@ -311,8 +332,8 @@ def new_publish(): return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None} -@frappe.whitelist(methods=['POST']) -def new_publish1(): +@frappe.whitelist(methods=['POST'], allow_guest=1) +def new_publish(): req = json.loads(frappe.request.data) try: module = req['module'] @@ -328,30 +349,109 @@ def new_publish1(): if len(publish_type) > 0: 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/" + \ 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': - with open(BASE_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 + if publish_type == 'Internal': + 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) + + 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': - with open(BASE_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 + if publish_type == 'Internal': + 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) + 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': - with open(BASE_PATH + str(vehicle) + '-qwik_service.json') as outfile: - data = json.load(outfile) - data = data['data'] - filter_json = filter_publish_json(data, variant) - data = filter_json + if publish_type == 'Internal': + 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') + 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': pass @@ -359,9 +459,11 @@ def new_publish1(): elif module == 'Mahindra Special Tool Information': with open(BASE_PATH + str(vehicle) + '-special_tool_information.json') as outfile: data = json.load(outfile) - data = data['data'] - filter_json = filter_publish_json(data, variant) - data = filter_json + # data = data['data'] + # filter_json = filter_publish_json(data, variant) + # data = filter_json + data = data.get('data') + data = data.get(variant) elif module == 'PDI Inspection': pass @@ -454,10 +556,22 @@ def update_publish_mapping(vehicle, variant, language, module): 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: - 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: - frappe.throw(str(e)) + return str(e) diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index 26ffeef..09b7d60 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -5,75 +5,72 @@ import frappe from frappe.model.document import Document import sys from frappe import _ -sys.tracebacklimit=0 +sys.tracebacklimit = 0 + class KilometerMapping(Document): - def onload(self): - ###Kilometer mapping config table idx allignment - if(self.config_kilometer): - idx = 0 - for x in self.get("config_kilometer"): - idx += 1 - x.idx = idx + def onload(self): + # Kilometer mapping config table idx allignment + if (self.config_kilometer): + idx = 0 + for x in self.get("config_kilometer"): + idx += 1 + x.idx = idx + @frappe.whitelist() def get_system(doc): - 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) - if system_map: - for s in system_map: - doc = frappe.get_doc("System Mapping",s.name) - 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 - + 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) + if system_map: + for s in system_map: + doc = frappe.get_doc("System Mapping", s.name) + 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() def get_subsystem(doc): - 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) - if system_map: - for s in system_map: - doc = frappe.get_doc("System Mapping",s.name) - 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 + 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) + if system_map: + for s in system_map: + doc = frappe.get_doc("System Mapping", s.name) + 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() -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"} - +def update_duplicate_km(doc, kilometer): -# @frappe.whitelist() -# def km_filter(parent = None , record = None, km = None): -# if record == "All": -# km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by length(kilometer),kilometer;""",as_dict = 1) + 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) -# 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 \ No newline at end of file +@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"}