This commit is contained in:
dx-tan 2024-03-29 17:47:28 +07:00
parent f7dadf2cb6
commit 580f099200
5 changed files with 37 additions and 19 deletions

View File

@ -260,10 +260,13 @@ def create_billing_report(report_id, **kwargs):
report.average_OCR_time = {"invoice": None, "imei": None, report.average_OCR_time = {"invoice": None, "imei": None,
"invoice_count": None, "imei_count": None, "avg": None} "invoice_count": None, "imei_count": None, "avg": None}
report.status = "Ready" report.status = "Ready"
detail_file_name = "detail_" + report.report_id + ".xlsx"
dashboard_file_name = "overview_" + report.report_id + ".xlsx"
report.S3_file_name = os.path.join("report", report.report_id, detail_file_name)
report.S3_dashboard_file_name = os.path.join("report", report.report_id, dashboard_file_name)
report.save() report.save()
data_workbook = dict2xlsx(billing_data, _type='billing_report') data_workbook = dict2xlsx(billing_data, _type='billing_report')
local_workbook = save_workbook_file( local_workbook = save_workbook_file(detail_file_name, report, data_workbook)
report.report_id + ".xlsx", report, data_workbook)
s3_key = save_report_to_S3(report.report_id, local_workbook) s3_key = save_report_to_S3(report.report_id, local_workbook)
except IndexError as e: except IndexError as e:
print(e) print(e)

View File

@ -34,7 +34,8 @@ class Command(BaseCommand):
"imei_number": [], "imei_number": [],
"retailername": "", "retailername": "",
"purchase_date": "", "purchase_date": "",
"sold_to_party": "" "sold_to_party": "",
"invoice_no": ""
} }
images = SubscriptionRequestFile.objects.filter(request=request, file_category=FileCategory.Origin.value) images = SubscriptionRequestFile.objects.filter(request=request, file_category=FileCategory.Origin.value)
@ -46,7 +47,7 @@ class Command(BaseCommand):
if request.predict_result.get("status", 200) != 200: if request.predict_result.get("status", 200) != 200:
raise AttributeError(f"Failed request: {request.request_id}") raise AttributeError(f"Failed request: {request.request_id}")
for field in ['retailername', 'purchase_date', 'imei_number']: for field in ['retailername', 'purchase_date', 'imei_number', 'invoice_no']:
if image.feedback_result[field] is not None and ((field == 'imei_number' and len(image.feedback_result[field]) > 0 and image.feedback_result[field][0] == user_feedback) or image.feedback_result[field] == user_feedback): if image.feedback_result[field] is not None and ((field == 'imei_number' and len(image.feedback_result[field]) > 0 and image.feedback_result[field][0] == user_feedback) or image.feedback_result[field] == user_feedback):
is_match = True is_match = True
@ -65,10 +66,11 @@ class Command(BaseCommand):
"imei_number": [], "imei_number": [],
"retailername": "", "retailername": "",
"purchase_date": "", "purchase_date": "",
"sold_to_party": "" "sold_to_party": "",
"invoice_no": ""
} }
if image.doc_type == "invoice" and field in ['retailername', 'purchase_date']: if image.doc_type == "invoice" and field in ['retailername', 'purchase_date', 'invoice_no']:
if _reviewed_result: if _reviewed_result:
_reviewed_result[field] = reviewed_result _reviewed_result[field] = reviewed_result
_reviewed_result["imei_number"] = [] _reviewed_result["imei_number"] = []
@ -79,11 +81,14 @@ class Command(BaseCommand):
"retailername": None, "retailername": None,
"sold_to_party": None, "sold_to_party": None,
"purchase_date": None, "purchase_date": None,
"imei_number": [reviewed_result] "imei_number": [reviewed_result],
"invoice_no": None
} if _reviewed_result else None } if _reviewed_result else None
image.reviewed_result = _reviewed_result image.reviewed_result = _reviewed_result
if reason: if reason:
image.reason = reason image.reason = reason
else:
image.reason = ""
if counter: if counter:
image.counter_measures = counter image.counter_measures = counter
image.save() image.save()

View File

@ -584,7 +584,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True)
def format_datetime_for_report_detail(ocr_extraction_date): def format_datetime_for_report_detail(ocr_extraction_date):
naived_time = timezone.make_naive(ocr_extraction_date) naived_time = timezone.make_naive(ocr_extraction_date)
ocr_extraction_date = timezone.make_aware(value=naived_time, timezone=timezone.get_current_timezone()) ocr_extraction_date = timezone.make_aware(value=naived_time, timezone=timezone.get_current_timezone())
format_to_date = '%Y/%m/%d' format_to_date = '%Y-%m-%d'
ocr_extraction_date = ocr_extraction_date.strftime(format_to_date) ocr_extraction_date = ocr_extraction_date.strftime(format_to_date)
return ocr_extraction_date return ocr_extraction_date
@ -755,8 +755,8 @@ def create_billing_data(subscription_requests):
_sub = map_subsidiary_short_to_long(request.redemption_id[:2]) _sub = map_subsidiary_short_to_long(request.redemption_id[:2])
redemption_id = request.redemption_id redemption_id = request.redemption_id
format_to_time = '%Y/%m/%d %H:%M' format_to_time = '%Y-%m-%d %H:%M'
format_to_date = '%Y/%m/%d' format_to_date = '%Y-%m-%d'
format_to_month = '%B %Y' format_to_month = '%B %Y'
naive_created_time = timezone.make_naive(request.created_at) naive_created_time = timezone.make_naive(request.created_at)
rq_created_at = timezone.make_aware(value=naive_created_time, timezone=timezone.get_current_timezone()) rq_created_at = timezone.make_aware(value=naive_created_time, timezone=timezone.get_current_timezone())

View File

@ -59,6 +59,16 @@ const ReportTable: React.FC = () => {
}, },
width: 110, width: 110,
}, },
{
title: 'Report Type',
dataIndex: 'Report Type',
key: 'Report Type',
render: (_, record) => {
const reportType = record["Report Type"];
const uppercasedReportType = reportType.charAt(0).toUpperCase() + reportType.slice(1);
return <>{uppercasedReportType}</>;
},
},
{ {
title: 'Start Date', title: 'Start Date',
dataIndex: 'Start Date', dataIndex: 'Start Date',
@ -172,7 +182,7 @@ const ReportTable: React.FC = () => {
}, },
}, },
{ {
title: 'Average Processing Time (ms)', title: 'Average Processing Time (seconds)',
dataIndex: 'Avg. OCR Processing Time', dataIndex: 'Avg. OCR Processing Time',
key: 'Avg. OCR Processing Time', key: 'Avg. OCR Processing Time',
render: (_, record) => { render: (_, record) => {

View File

@ -89,12 +89,12 @@ services:
depends_on: depends_on:
db-sbt: db-sbt:
condition: service_started condition: service_started
# command: sh -c "chmod -R 777 /app; sleep 5; python manage.py collectstatic --no-input && command: sh -c "chmod -R 777 /app; sleep 5; python manage.py collectstatic --no-input &&
# python manage.py makemigrations && python manage.py makemigrations &&
# python manage.py migrate && python manage.py migrate &&
# python manage.py compilemessages && python manage.py compilemessages &&
# gunicorn fwd.asgi:application -k uvicorn.workers.UvicornWorker --timeout 300 -b 0.0.0.0:9000" # pre-makemigrations on prod gunicorn fwd.asgi:application -k uvicorn.workers.UvicornWorker --timeout 300 -b 0.0.0.0:9000" # pre-makemigrations on prod
command: "sleep infinity" # command: "sleep infinity"
minio: minio:
image: minio/minio image: minio/minio
@ -179,8 +179,8 @@ services:
- ./cope2n-api:/app - ./cope2n-api:/app
working_dir: /app working_dir: /app
# command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO -c 5" command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO -c 5"
command: bash -c "tail -f > /dev/null" # command: bash -c "tail -f > /dev/null"
# Back-end persistent # Back-end persistent
db-sbt: db-sbt: