Skip to content

Commit

Permalink
OM-229 Fixed bill to mpay conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskikam committed Jul 22, 2024
1 parent 01379c5 commit fea6131
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
22 changes: 22 additions & 0 deletions msystems/soap/datetime.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions msystems/soap/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions msystems/views/mpay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import decimal
import logging
from functools import reduce

from lxml import etree
from django.db import transaction
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fea6131

Please sign in to comment.