diff --git a/msystems/soap/datetime.py b/msystems/soap/datetime.py new file mode 100644 index 0000000..ad8405c --- /dev/null +++ b/msystems/soap/datetime.py @@ -0,0 +1,22 @@ +import re +from datetime import datetime as py_datetime + +from core import datetime + +class SoapDatetime(datetime.datetime): + def isoformat(self): + return re.sub(r"[+-]00:?00$", "Z", self.strftime("%y-%m-%dT%H:%M:%S%z")) + + @classmethod + def from_ad_date(cls, value): + if value is None: + return None + return SoapDatetime(value.year, value.month, value.day, 0, 0, 0, 0, py_datetime.now().astimezone().tzinfo) + + @classmethod + def from_ad_datetime(cls, value): + if value is None: + return None + return SoapDatetime(value.year, value.month, value.day, + value.hour, value.minute, value.second, value.microsecond, + value.tzinfo or py_datetime.now().astimezone().tzinfo) \ No newline at end of file diff --git a/msystems/soap/models.py b/msystems/soap/models.py index 3380594..b4a311d 100644 --- a/msystems/soap/models.py +++ b/msystems/soap/models.py @@ -1,3 +1,5 @@ +from datetime import timezone + from spyne.model.primitive import Unicode, DateTime, Decimal, Boolean from spyne.model.complex import ComplexModel, Array from spyne.model.enum import Enum @@ -69,8 +71,8 @@ class OrderDetails(ComplexModel): CustomerID = Unicode.customize(min_occurs=0, max_occurs=1, max_len=13, nillable=False) CustomerName = Unicode.customize(min_occurs=1, max_occurs=1, max_len=60, nillable=False) CustomerType = CustomerType.customize(min_occurs=1, max_occurs=1, nillable=False) - DueDate = DateTime.customize(min_occurs=0, max_occurs=1, nillable=False) - IssuedAt = DateTime.customize(min_occurs=0, max_occurs=1, nillable=False) + DueDate = DateTime.customize(min_occurs=0, max_occurs=1, nillable=False, as_timezone=timezone.utc) + IssuedAt = DateTime.customize(min_occurs=0, max_occurs=1, nillable=False, as_timezone=timezone.utc) Lines = (Array(OrderLine.customize(min_occurs=1, max_occurs="unbounded", nillable=False)) .customize(min_occurs=1, max_occurs=1, nillable=False)) OrderKey = Unicode.customize(min_occurs=1, max_occurs=1, max_len=36, nillable=False) diff --git a/msystems/views/mpay.py b/msystems/views/mpay.py index 582d81d..6244acc 100644 --- a/msystems/views/mpay.py +++ b/msystems/views/mpay.py @@ -1,6 +1,5 @@ import decimal import logging -from functools import reduce from lxml import etree from django.db import transaction @@ -21,6 +20,7 @@ from invoice.apps import InvoiceConfig from invoice.models import Bill, BillPayment from msystems.apps import MsystemsConfig +from msystems.soap.datetime import SoapDatetime from msystems.soap.models import OrderDetailsQuery, GetOrderDetailsResult, OrderLine, OrderDetails, \ PaymentConfirmation, PaymentAccount, OrderStatus, CustomerType from msystems.xml_utils import add_signature, verify_signature, verify_timestamp, add_timestamp @@ -156,8 +156,8 @@ def GetOrderDetails(ctx, query: OrderDetailsQuery) -> GetOrderDetailsResult: ServiceID=query.ServiceID, Status=_order_status_map[bill.status], TotalAmountDue=str(bill.amount_total), - IssuedAt=bill.date_created.strftime("%Y-%m-%dT%H:%M:%SZ"), - DueAt=bill.date_due.strftime("%Y-%m-%dT%H:%M:%SZ"), + IssuedAt=SoapDatetime.from_ad_datetime(bill.date_created), + DueDate=SoapDatetime.from_ad_date(bill.date_due), ) ret = GetOrderDetailsResult(OrderDetails=order_details)