Skip to content

Commit

Permalink
fix: eshipper datetime requirement for ship date and update tests for…
Browse files Browse the repository at this point in the history
… order cancellation
  • Loading branch information
danh91 committed Aug 29, 2024
1 parent 88e227c commit ea3e2a2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import karrio.schemas.eshipper.shipping_request as eshipper
import karrio.schemas.eshipper.shipping_response as shipping
import typing
Expand Down Expand Up @@ -109,10 +110,16 @@ def shipment_request(
else None
),
)
shipping_date = lib.to_date(options.shipment_date.state or datetime.datetime.now())
now = datetime.datetime.now() + datetime.timedelta(minutes=5)
shipping_time = lib.ftime(options.shipping_time.state or now, "%H:%M")
shipping_date = lib.fdate(options.shipping_date.state or now)

request = eshipper.ShippingRequestType(
scheduledShipDate=lib.fdatetime(shipping_date, output_format="%Y-%m-%d %H:%M"),
scheduledShipDate=lib.fdatetime(
f"{shipping_date} {shipping_time}",
current_format="%Y-%m-%d %H:%M",
output_format="%Y-%m-%d %H:%M",
),
shippingrequestfrom=eshipper.FromType(
attention=shipper.contact,
company=shipper.company_name,
Expand Down
9 changes: 4 additions & 5 deletions modules/connectors/eshipper/tests/eshipper/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def test_parse_cancel_shipment_response(self):
},
],
"options": {
"shipment_date": "2024-07-16",
"shipping_date": "2024-07-16",
"shipping_time": "10:30",
},
}

Expand Down Expand Up @@ -178,7 +179,7 @@ def test_parse_cancel_shipment_response(self):
"type": "Package",
},
"packagingUnit": "Metric",
"scheduledShipDate": "2024-07-16 00:00",
"scheduledShipDate": "2024-07-16 10:30",
"serviceId": "5000184",
"from": {
"address1": "9, Van Der Graaf Court",
Expand All @@ -200,9 +201,7 @@ def test_parse_cancel_shipment_response(self):
},
}

ShipmentCancelRequest = {
"order": {"orderId": "1234567890", "trackingId": "794947717776"}
}
ShipmentCancelRequest = {"order": {"orderId": "1234567890"}}


ShipmentResponse = """{
Expand Down
16 changes: 15 additions & 1 deletion modules/sdk/karrio/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,6 @@ class ShippingOption(utils.Enum):
insurance = utils.OptionEnum("insurance", float)
cash_on_delivery = utils.OptionEnum("COD", float)
shipment_note = utils.OptionEnum("shipment_note")
shipment_date = utils.OptionEnum("shipment_date")
dangerous_good = utils.OptionEnum("dangerous_good", bool)
declared_value = utils.OptionEnum("declared_value", float)
paperless_trade = utils.OptionEnum("paperless_trade", bool)
Expand All @@ -1115,6 +1114,13 @@ class ShippingOption(utils.Enum):
functools.partial(utils.DP.to_object, models.Address),
)

"""TODO: dreprecate these"""
shipment_date = utils.OptionEnum("shipment_date")

"""TODO: standardize to these"""
shipping_date = utils.OptionEnum("shipping_date") # TODO: change format to datetime
shipping_time = utils.OptionEnum("shipping_time")


class ShippingOptions(Options):
"""The options common processing helper"""
Expand Down Expand Up @@ -1161,6 +1167,14 @@ def email_notification_to(self) -> utils.OptionEnum:
def shipment_date(self) -> utils.OptionEnum:
return self[ShippingOption.shipment_date.name]

@property
def shipping_date(self) -> utils.OptionEnum:
return self[ShippingOption.shipping_date.name] or self.shipment_date

@property
def shipping_time(self) -> utils.OptionEnum:
return self[ShippingOption.shipping_time.name]

@property
def signature_confirmation(self) -> utils.OptionEnum:
return self[ShippingOption.signature_confirmation.name]
Expand Down

0 comments on commit ea3e2a2

Please sign in to comment.