From 1c23ec2e71f59735fdc0165e3c38537eeac875ea Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Thu, 22 Jun 2023 13:53:42 +0530 Subject: [PATCH] Merge based on system,sub system id --- smart_service/apis/publish_api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index ccb9522..d96f4df 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -88,7 +88,7 @@ def api_procedure(args, publish_type, vehicle, language, version): return "Failed to save file" -def json_grouping1(args, language): +def old_json_grouping(args, language): dicfinal = [] docs_child = frappe.db.get_list("Publish_Docs", filters={"parent": args}, fields=["variant_mapping", "system", "sub_system", "procedure_status", @@ -734,7 +734,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): var_dict["Variant"]["Assets"] = data_old["JSON"][old_var_key]["Variant"]["Assets"] for i in variant_systems: - old_sys_key = check_key(i["system_name"], var_dict["Variant"]["Systems"], "System") + old_sys_key = check_key(i["sys_id"], var_dict["Variant"]["Systems"], "System") if old_sys_key is not None and old_sys_key >= 0: var_dict["Variant"]["Systems"][old_sys_key]["systemdisplayorder"] = i["systemdisplayorder"] @@ -745,7 +745,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): var_dict["Variant"]["Systems"][old_sys_key]["Assets"] = i["Assets"] for s in i["Subsystems"]: - old_sub_key = check_key(s["sub_systems"], + old_sub_key = check_key(s["subsys_id"], var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"], "Sub System") if old_sub_key is not None and old_sub_key >= 0: @@ -765,8 +765,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): with open(out_file_path, "w") as outfile: outfile.write(json_object) return True, out_file_path - except Exception as es: - frappe.log_error("Merge JSON:",frappe.get_traceback()) + except: + return False,frappe.log_error("Merge JSON:",frappe.get_traceback()) def check_key(key_name, old_data, type=None): @@ -778,14 +778,14 @@ def check_key(key_name, old_data, type=None): if type == "System": try: - if old_data[d]["system_name"] == key_name: + if old_data[d]["sys_id"] == key_name: return d except Exception as e: frappe.log_error("Check key System:",frappe.get_traceback()) if type == "Sub System": try: - if old_data[d]["sub_systems"] == key_name: + if old_data[d]["subsys_id"] == key_name: return d except Exception as e2: frappe.log_error("Check key subsystem:",frappe.get_traceback())