diff --git a/modules/connectors/eshipper/karrio/providers/eshipper/rate.py b/modules/connectors/eshipper/karrio/providers/eshipper/rate.py index 0ca180933..d126124c6 100644 --- a/modules/connectors/eshipper/karrio/providers/eshipper/rate.py +++ b/modules/connectors/eshipper/karrio/providers/eshipper/rate.py @@ -88,11 +88,19 @@ def rate_request( shipper = lib.to_address(payload.shipper) recipient = lib.to_address(payload.recipient) packages = lib.to_packages(payload.parcels) - services = lib.to_services(payload.services, provider_units.ShippingService) options = lib.to_shipping_options( payload.options, package_options=packages.options, ) + services = lib.to_services(payload.services, provider_units.ShippingService) + print(services, "<<<") + service_id = lib.identity( + options.eshipper_service_id.state + or provider_units.ShippingService.service_id( + services.first, + test_mode=settings.test_mode, + ) + ) request = eshipper.RateRequestType( scheduledShipDate=lib.fdatetime( @@ -100,7 +108,7 @@ def rate_request( options.shipping_date.state or datetime.datetime.now(), current_format="%Y-%m-%dT%H:%M", ), - output_format="%Y-%m-%dT%H:%M:%S.%fZ", # 2024-09-30T09:10:29.195Z + output_format="%Y-%m-%d %H:%M", ), raterequestfrom=eshipper.FromType( attention=shipper.contact, @@ -178,7 +186,7 @@ def rate_request( insidePickup=options.eshipper_inside_pickup.state, saturdayPickupRequired=options.eshipper_saturday_pickup_required.state, stackable=options.eshipper_stackable.state, - serviceId=getattr(services.first, "value", None), + serviceId=service_id, thirdPartyBilling=None, commodityType=None, ) diff --git a/modules/connectors/eshipper/karrio/providers/eshipper/shipment/create.py b/modules/connectors/eshipper/karrio/providers/eshipper/shipment/create.py index e64bb0a0e..0b9801b91 100644 --- a/modules/connectors/eshipper/karrio/providers/eshipper/shipment/create.py +++ b/modules/connectors/eshipper/karrio/providers/eshipper/shipment/create.py @@ -139,7 +139,7 @@ def shipment_request( options.shipping_date.state or datetime.datetime.now(), current_format="%Y-%m-%dT%H:%M", ), - output_format="%Y-%m-%dT%H:%M:%S.%fZ", # 2024-09-30T09:10:29.195Z + output_format="%Y-%m-%d %H:%M", ), shippingrequestfrom=eshipper.FromType( attention=shipper.contact, diff --git a/modules/connectors/eshipper/karrio/providers/eshipper/units.py b/modules/connectors/eshipper/karrio/providers/eshipper/units.py index 12b69f0ce..ee0f658c5 100644 --- a/modules/connectors/eshipper/karrio/providers/eshipper/units.py +++ b/modules/connectors/eshipper/karrio/providers/eshipper/units.py @@ -236,428 +236,6 @@ def find_rate_provider( return RateProvider.map(lib.to_snake_case(search)) -CARRIER_IDS = { - "5000001": "aramex", - "5000002": "canadapost", - "5000003": "canpar", - "5000017": "day_ross", - "5000004": "dhl_express", - "5000011": "eshipper", - "5000005": "fedex", - "8000010": "flashbird", - "56": "fleet_optics", - "5000008": "project44", - "5000007": "purolator", - "5000047": "pyk", - "5000014": "sameday", - "5000048": "skip", - "5000015": "smartepost_intl", - "5000010": "ups", - "5000013": "usps", -} - -CARRIER_SERVICES = { - "56": ["5000458", "5000458", "5000458", "5000458"], - "5000001": [ - "5000047", - "5000047", - "5000046", - "5000046", - "5000048", - "5000048", - "5000049", - "5000049", - ], - "5000002": [ - "5000181", - "5000181", - "5000181", - "5000028", - "5000028", - "5000028", - "5000029", - "5000029", - "5000029", - "5000025", - "5000025", - "5000025", - "5000031", - "5000031", - "5000031", - "5000035", - "5000035", - "5000035", - "5000034", - "5000034", - "5000034", - "5000033", - "5000033", - "5000033", - "5000027", - "5000027", - "5000027", - "5000024", - "5000024", - "5000024", - "5000032", - "5000032", - "5000032", - "5000026", - "5000026", - "5000026", - "5000030", - "5000030", - "5000030", - ], - "5000003": [ - "5000134", - "5000134", - "5000134", - "5000133", - "5000133", - "5000133", - "5000132", - "5000132", - "5000132", - "5000125", - "5000125", - "5000125", - "5000128", - "5000128", - "5000128", - "5000127", - "5000127", - "5000127", - "5000126", - "5000126", - "5000126", - "5000135", - "5000135", - "5000135", - "5000184", - "5000184", - "5000184", - "5000131", - "5000131", - "5000131", - "5000130", - "5000130", - "5000130", - "5000129", - "5000129", - "5000129", - ], - "5000004": [ - "5000020", - "5000020", - "5000021", - "5000021", - "5000019", - "5000019", - "5000015", - "5000015", - "5000023", - "5000023", - "5000014", - "5000014", - "5000180", - "5000180", - "5000017", - "5000017", - "5000016", - "5000016", - "5000018", - "5000018", - "5000186", - "5000186", - "5000022", - "5000022", - ], - "5000005": [ - "5000172", - "5000172", - "5000172", - "5000169", - "5000169", - "5000169", - "5000175", - "5000175", - "5000175", - "8000023", - "8000023", - "8000023", - "8000022", - "8000022", - "8000022", - "5000176", - "5000176", - "5000176", - "5000179", - "5000179", - "5000179", - "8000018", - "8000018", - "8000018", - "8000017", - "8000017", - "8000017", - "5000183", - "5000183", - "5000183", - "5000171", - "5000171", - "5000171", - "5000170", - "5000170", - "5000170", - "5000174", - "5000174", - "5000174", - "5000173", - "5000173", - "5000173", - "5000178", - "5000178", - "5000178", - "5000177", - "5000177", - "5000177", - ], - "5000007": [ - "5000008", - "5000008", - "5000008", - "5000009", - "5000009", - "5000009", - "5000007", - "5000007", - "5000007", - "5000005", - "5000005", - "5000005", - "5000006", - "5000006", - "5000006", - "5000004", - "5000004", - "5000004", - "5000012", - "5000012", - "5000012", - "5000013", - "5000013", - "5000013", - "5000010", - "5000010", - "5000010", - "5000011", - "5000011", - "5000011", - "5000002", - "5000002", - "5000002", - "5000003", - "5000003", - "5000003", - "5000001", - "5000001", - "5000001", - ], - "5000008": [ - "5000056", - "5000053", - "5000413", - "5000109", - "5000110", - "5000088", - "5000065", - "5000089", - "5000080", - "5000055", - "5000073", - "5000098", - "5000097", - "5000093", - "5000084", - "5000082", - "5000067", - "5000068", - "5000052", - "5000058", - "5000100", - "5000094", - "5000071", - "5000054", - "5000063", - "5000064", - "5000090", - "5000087", - "5000075", - "5000104", - "5000074", - "5000069", - "5000051", - "5000096", - "5000062", - "5000060", - "5000106", - "5000108", - "5000107", - "5000059", - "5000070", - "5000105", - "5000077", - "5000061", - "5000076", - "5000078", - "5000091", - "5000072", - "5000101", - "5000099", - "5000083", - "5000057", - "5000095", - "5000086", - "5000085", - "5000066", - "5000102", - "5000079", - "5000111", - "5000092", - "5000081", - "5000103", - ], - "5000010": [ - "5000044", - "5000044", - "5000044", - "5000037", - "5000037", - "5000037", - "5000038", - "5000038", - "5000038", - "5000042", - "5000042", - "5000042", - "5000041", - "5000041", - "5000041", - "5000039", - "5000039", - "5000039", - "5000045", - "5000045", - "5000045", - "5000043", - "5000043", - "5000043", - "5000040", - "5000040", - "5000040", - "5000036", - "5000036", - "5000036", - "5000182", - "5000182", - "5000182", - ], - "5000011": [ - "5000115", - "5000113", - "5000112", - "5000119", - "5000114", - "5000116", - "5000123", - "5000117", - "5000122", - "5000421", - "5000419", - "5000121", - "5000420", - "5000118", - "5000124", - "5000120", - "5000414", - ], - "5000013": [ - "5000153", - "5000153", - "8000003", - "5000152", - "5000152", - "5000151", - "5000151", - "5000150", - "5000150", - "5000155", - "5000155", - "5000154", - "5000154", - "5000149", - "5000149", - "5000148", - "5000148", - "5000147", - "5000147", - "8000002", - "5000146", - ], - "5000014": [ - "5000168", - "5000167", - "5000166", - "5000165", - "5000164", - "5000163", - "5000162", - "5000161", - "5000160", - "5000159", - "5000158", - "5000157", - "5000156", - ], - "5000015": [ - "5000145", - "5000145", - "5000145", - "5000144", - "5000144", - "5000144", - "5000143", - "5000143", - "5000143", - "5000142", - "5000142", - "5000142", - "5000141", - "5000141", - "5000141", - "5000140", - "5000140", - "5000140", - "5000139", - "5000139", - "5000139", - "5000138", - "5000138", - "5000138", - "5000137", - "5000137", - "5000137", - "8000053", - ], - "5000016": ["5000454"], - "5000017": ["5000457"], - "5000047": ["5000460", "5000460", "5000459", "5000459"], - "5000048": ["8000020", "8000019"], - "8000010": ["8000032"], -} - - ESHIPPER_CARRIER_METADATA = { lib.to_snake_case(carrier["carrierDTO"]["name"]): { **carrier["carrierDTO"], diff --git a/modules/connectors/eshipper/tests/eshipper/test_rate.py b/modules/connectors/eshipper/tests/eshipper/test_rate.py index b0dd92c2d..2f6aa71f8 100644 --- a/modules/connectors/eshipper/tests/eshipper/test_rate.py +++ b/modules/connectors/eshipper/tests/eshipper/test_rate.py @@ -326,7 +326,7 @@ def test_parse_rate_response(self): "zip": "L4T3T1", "country": "CA", }, - "scheduledShipDate": "2024-07-16T10:00:00.000000Z", + "scheduledShipDate": "2024-07-16 10:00", "packagingUnit": "Metric", "packages": { "type": "Package", diff --git a/modules/connectors/eshipper/tests/eshipper/test_shipment.py b/modules/connectors/eshipper/tests/eshipper/test_shipment.py index dfbb8ab76..172a69df5 100644 --- a/modules/connectors/eshipper/tests/eshipper/test_shipment.py +++ b/modules/connectors/eshipper/tests/eshipper/test_shipment.py @@ -178,7 +178,7 @@ def test_parse_cancel_shipment_response(self): "type": "Package", }, "packagingUnit": "Metric", - "scheduledShipDate": "2024-07-16T10:30:00.000000Z", + "scheduledShipDate": "2024-07-16 10:30", "serviceId": 4500, "from": { "address1": "9, Van Der Graaf Court", diff --git a/modules/core/karrio/server/core/validators.py b/modules/core/karrio/server/core/validators.py index d05703d65..643ad9815 100644 --- a/modules/core/karrio/server/core/validators.py +++ b/modules/core/karrio/server/core/validators.py @@ -117,19 +117,23 @@ def __init__(self, instance=None, **kwargs): current_format="%Y-%m-%dT%H:%M", ) - if shipping_date is None or shipping_date.date() < datetime.now().date(): - options.update(shipping_date=datetime.now().strftime("%Y-%m-%dT%H:%M")) - kwargs["data"].update(dict(options=options)) - - if shipping_date or options.get("shipping_date"): + if shipping_date is None or shipping_date < datetime.now(): options.update( - shipment_date=lib.fdate( - shipping_date or options.get("shipping_date"), - current_format="%Y-%m-%dT%H:%M", + shipping_date=lib.fdatetime( + lib.to_next_business_datetime(), + output_format="%Y-%m-%dT%H:%M", ) ) kwargs["data"].update(dict(options=options)) + options.update( + shipment_date=lib.fdate( + shipping_date or options.get("shipping_date"), + current_format="%Y-%m-%dT%H:%M", + ) + ) + kwargs["data"].update(dict(options=options)) + super().__init__(instance, **kwargs)