From 5042a7081098679e015b68cc0acb65c53b0e1b2e Mon Sep 17 00:00:00 2001 From: PhanThanhTrung Date: Tue, 12 Mar 2024 16:45:50 +0700 Subject: [PATCH] process_sync update invoice_no --- cope2n-ai-fi/common/utils_kvu/split_docs.py | 3 ++- .../celery_worker/process_result_tasks.py | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cope2n-ai-fi/common/utils_kvu/split_docs.py b/cope2n-ai-fi/common/utils_kvu/split_docs.py index 52d1078..c20d10d 100755 --- a/cope2n-ai-fi/common/utils_kvu/split_docs.py +++ b/cope2n-ai-fi/common/utils_kvu/split_docs.py @@ -107,6 +107,7 @@ def merge_sbt_output(loutputs): merged_output = [] combined_output = {"retailername": None, "sold_to_party": None, + "invoice_no": None, "purchase_date": [], "imei_number": []} # place holder for the output for output in loutputs: @@ -123,7 +124,7 @@ def merge_sbt_output(loutputs): combined_output[field["label"]].append(field["value"]) if output['doc_type'] == "invoice": for field in fields: - if field["label"] in ["retailername", "sold_to_party", "purchase_date"] : + if field["label"] in ["retailername", "sold_to_party", "purchase_date", "invoice_no"] : if isinstance(combined_output[field["label"]], list): if field["value"] is not None: if isinstance(field["value"], list): diff --git a/cope2n-api/fwd_api/celery_worker/process_result_tasks.py b/cope2n-api/fwd_api/celery_worker/process_result_tasks.py index 728d8fb..da03539 100755 --- a/cope2n-api/fwd_api/celery_worker/process_result_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_result_tasks.py @@ -29,8 +29,8 @@ def aggregate_result(results): des_result["content"]["total_pages"] = 0 des_result["content"]["ocr_num_pages"] = 0 des_result["content"]["document"][0]["end_page"] = 0 - des_result["content"]["document"][0]["content"][3]["value"] = [None for _ in range(doc_types.count("imei"))] - des_result["content"]["document"][0]["content"][2]["value"] = [] + des_result["content"]["document"][0]["content"][4]["value"] = [None for _ in range(doc_types.count("imei"))] + des_result["content"]["document"][0]["content"][3]["value"] = [] imei_count = 0 for doc_type, result in sorted_results: @@ -38,12 +38,14 @@ def aggregate_result(results): des_result["content"]["ocr_num_pages"] += 1 des_result["content"]["document"][0]["end_page"] += 1 if doc_type == "imei": - des_result["content"]["document"][0]["content"][3]["value"][imei_count] = result["content"]["document"][0]["content"][3]["value"][0] + if len(result["content"]["document"][0]["content"][4]["value"]): + des_result["content"]["document"][0]["content"][4]["value"][imei_count] = result["content"]["document"][0]["content"][4]["value"][0] imei_count += 1 elif doc_type == "invoice": des_result["content"]["document"][0]["content"][0]["value"] = result["content"]["document"][0]["content"][0]["value"] des_result["content"]["document"][0]["content"][1]["value"] = result["content"]["document"][0]["content"][1]["value"] - des_result["content"]["document"][0]["content"][2]["value"] += result["content"]["document"][0]["content"][2]["value"] + des_result["content"]["document"][0]["content"][2]["value"] = result["content"]["document"][0]["content"][2]["value"] + des_result["content"]["document"][0]["content"][3]["value"] += result["content"]["document"][0]["content"][3]["value"] elif doc_type == "all": des_result.update(result) else: @@ -151,7 +153,6 @@ def process_invoice_sbt_result(rq_id, result, metadata): index_in_request = metadata.pop("index_to_image_type", 0) result["metadata"] = metadata _update_subscription_rq_file(request_id=rq, index_in_request=index_in_request, doc_type=image_type, result=result) - status = result.get("status", 200) redis_client.set_cache(rq_id, page_index, result) done = rq.pages == redis_client.get_size(rq_id) @@ -194,9 +195,9 @@ def process_invoice_sbt_result(rq_id, result, metadata): def _update_subscription_rq_file(request_id, index_in_request, doc_type, result): image = SubscriptionRequestFile.objects.filter(request=request_id, index_in_request=index_in_request, doc_type=doc_type).first() - retailer_name = None sold_to_party = None + invoice_no = None purchase_date = [] imei_number = [] predicted_res = __get_actual_predict_result(result=result) @@ -208,19 +209,23 @@ def _update_subscription_rq_file(request_id, index_in_request, doc_type, result) sold_to_party = elem['value'] elif elem["label"] == "purchase_date": purchase_date = elem['value'] + elif elem["label"] == "invoice_no": + invoice_no = elem['value'] else: imei_number = elem['value'] if doc_type=='invoice': _predict_result = { "retailername": retailer_name, - "sold_to_party": sold_to_party, + "sold_to_party": sold_to_party, + "invoice_no": invoice_no, "purchase_date": purchase_date, "imei_number": [] } else: _predict_result = { "retailername": None, - "sold_to_party": None, + "sold_to_party": None, + "invoice_no": None, "purchase_date": [], "imei_number": imei_number }