From 987c34c21c9b58220f43c3d31eb441f4c05f7f26 Mon Sep 17 00:00:00 2001 From: sniedzielski Date: Mon, 26 Aug 2024 12:23:09 +0200 Subject: [PATCH] OM-190: added mapping VoucherStatus from SOAP to system and viceversa --- msystems/views/vouchers.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/msystems/views/vouchers.py b/msystems/views/vouchers.py index 468e941..35cbb7d 100644 --- a/msystems/views/vouchers.py +++ b/msystems/views/vouchers.py @@ -8,6 +8,7 @@ from spyne.server.django import DjangoApplication from spyne.service import ServiceBase from zeep.exceptions import SignatureVerificationFailed +from msystems.soap.models import VoucherStatus from msystems.apps import MsystemsConfig from msystems.soap.datetime import SoapDatetime @@ -19,6 +20,23 @@ namespace = 'https://mpay.gov.md' logger = logging.getLogger(__name__) +_voucher_status_map_system_to_soap = { + WorkerVoucher.Status.ASSIGNED: VoucherStatus.Assigned, + WorkerVoucher.Status.AWAITING_PAYMENT: VoucherStatus.AwaitingPayment, + WorkerVoucher.Status.CANCELED: VoucherStatus.Canceled, + WorkerVoucher.Status.CLOSED: VoucherStatus.Closed, + WorkerVoucher.Status.EXPIRED: VoucherStatus.Expired, + WorkerVoucher.Status.UNASSIGNED: VoucherStatus.Unassigned, +} + +_voucher_status_map_soap_to_system = { + VoucherStatus.Assigned: WorkerVoucher.Status.ASSIGNED, + VoucherStatus.AwaitingPayment: WorkerVoucher.Status.AWAITING_PAYMENT, + VoucherStatus.Canceled: WorkerVoucher.Status.CANCELED, + VoucherStatus.Closed: WorkerVoucher.Status.CLOSED, + VoucherStatus.Expired: WorkerVoucher.Status.EXPIRED, + VoucherStatus.Unassigned: WorkerVoucher.Status.UNASSIGNED, +} def _get_vouchers(query: VouchersDetailsQuery): vouchers = WorkerVoucher.objects.filter(is_deleted=False) @@ -40,7 +58,7 @@ def _get_vouchers(query: VouchersDetailsQuery): vouchers = vouchers.filter(code=query.VoucherCode) if query.VoucherStatus: - vouchers = vouchers.filter(status=query.VoucherStatus) + vouchers = vouchers.filter(status=_voucher_status_map_soap_to_system[query.VoucherStatus]) return vouchers @@ -97,7 +115,7 @@ def GetVouchersDetails(ctx, query: VouchersDetailsQuery) -> GetVouchersDetailsRe EmployerCode=str(voucher.policyholder.code) if voucher.policyholder else None, WorkerNationalID=str(voucher.insuree.chf_id) if voucher.insuree else None, VoucherCode=str(voucher.code), - VoucherStatus=str(voucher.status), + VoucherStatus=_voucher_status_map_system_to_soap[voucher.status], )) if not vouchers_details: