-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Consolidate Easyship integration with live tests
- Loading branch information
Showing
16 changed files
with
5,342 additions
and
13,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ def _extract_details( | |
docs=models.Documents(label=label), | ||
meta=dict( | ||
tracking_numbers=tracking_numbers, | ||
rate_provider=ctx["rate_provider"], | ||
easyship_courier_id=ctx["courier_id"], | ||
easyship_shipment_id=details.easyship_shipment_id, | ||
easyship_courier_account_id=details.courier.id, | ||
), | ||
|
@@ -67,21 +69,24 @@ def shipment_request( | |
return_address = lib.to_address(payload.return_address or payload.shipper) | ||
packages = lib.to_packages(payload.parcels, options=payload.options) | ||
weight_unit, dimension_unit = packages.compatible_units | ||
service = provider_units.ShippingService.map(payload.service).name_or_key | ||
courrier_id = provider_units.ShippingServiceID.map(service).value_or_key | ||
options = lib.to_shipping_options( | ||
payload.options, | ||
package_options=packages.options, | ||
initializer=provider_units.shipping_options_initializer, | ||
) | ||
service = lib.identity( | ||
options.easyship_courier_id.state | ||
or provider_units.ShippingServiceID.map(payload.service).name_or_key | ||
) | ||
courier = provider_units.ShippingCourierID.find(service) | ||
customs = lib.to_customs_info( | ||
payload.customs, | ||
shipper=payload.shipper, | ||
recipient=payload.recipient, | ||
weight_unit=weight_unit.name, | ||
) | ||
incoterms = lib.identity( | ||
options.easyship_incoterms.state or customs.options.incoterm | ||
options.easyship_incoterms.state or customs.options.incoterm.state or "DDU" | ||
) | ||
label_type = provider_units.LabelFormat.map(payload.label_type) | ||
|
||
|
@@ -116,14 +121,18 @@ def shipment_request( | |
if options.easyship_list_unavailable_couriers.state is not None | ||
else False | ||
), | ||
selected_courier_id=courrier_id, | ||
selected_courier_id=service, | ||
), | ||
destination_address=easyship.AddressType( | ||
city=recipient.city, | ||
company_name=recipient.company_name, | ||
contact_email=recipient.email, | ||
company_name=recipient.company_name or "N/A", | ||
contact_email=lib.identity( | ||
recipient.email | ||
or options.email_notification_to.state | ||
or "[email protected]" | ||
), | ||
contact_name=recipient.person_name, | ||
contact_phone=recipient.phone_number, | ||
contact_phone=recipient.phone_number or "N/A", | ||
country_alpha2=recipient.country_code, | ||
line_1=recipient.address_line1, | ||
line_2=recipient.address_line2, | ||
|
@@ -140,10 +149,14 @@ def shipment_request( | |
order_data=None, | ||
origin_address=easyship.AddressType( | ||
city=return_address.city, | ||
company_name=return_address.company_name, | ||
contact_email=return_address.email, | ||
company_name=return_address.company_name or "N/A", | ||
contact_email=lib.identity( | ||
return_address.email | ||
or options.email_notification_to.state | ||
or "[email protected]" | ||
), | ||
contact_name=return_address.person_name, | ||
contact_phone=return_address.phone_number, | ||
contact_phone=return_address.phone_number or "N/A", | ||
country_alpha2=return_address.country_code, | ||
line_1=return_address.address_line1, | ||
line_2=return_address.address_line2, | ||
|
@@ -168,10 +181,14 @@ def shipment_request( | |
shipment_request_return=options.is_return.state, | ||
return_address=easyship.AddressType( | ||
city=return_address.city, | ||
company_name=return_address.company_name, | ||
contact_email=return_address.email, | ||
company_name=return_address.company_name or "N/A", | ||
contact_email=lib.identity( | ||
return_address.email | ||
or options.email_notification_to.state | ||
or "[email protected]" | ||
), | ||
contact_name=return_address.person_name, | ||
contact_phone=return_address.phone_number, | ||
contact_phone=return_address.phone_number or "N/A", | ||
country_alpha2=return_address.country_code, | ||
line_1=return_address.address_line1, | ||
line_2=return_address.address_line2, | ||
|
@@ -181,10 +198,12 @@ def shipment_request( | |
return_address_id=options.easyship_return_address_id.state, | ||
sender_address=easyship.AddressType( | ||
city=shipper.city, | ||
company_name=shipper.company_name, | ||
contact_email=shipper.email, | ||
company_name=shipper.company_name or "N/A", | ||
contact_email=lib.identity( | ||
shipper.email or options.email_notification_to.state or "[email protected]" | ||
), | ||
contact_name=shipper.person_name, | ||
contact_phone=shipper.phone_number, | ||
contact_phone=shipper.phone_number or "N/A", | ||
country_alpha2=shipper.country_code, | ||
line_1=shipper.address_line1, | ||
line_2=shipper.address_line2, | ||
|
@@ -233,15 +252,17 @@ def shipment_request( | |
items=[ | ||
easyship.ItemType( | ||
dimensions=None, | ||
declared_currency=item.value_currency or options.currency.state, | ||
declared_currency=lib.identity( | ||
item.value_currency or options.currency.state or "USD" | ||
), | ||
origin_country_alpha2=item.origin_country, | ||
quantity=item.quantity, | ||
actual_weight=item.weight, | ||
category=item.category, | ||
category=item.category or "bags_luggages", | ||
declared_customs_value=item.value_amount, | ||
description=item.description or item.title, | ||
description=item.description or item.title or "Item", | ||
sku=item.sku, | ||
hs_code=item.hs_code, | ||
hs_code=item.hs_code or "N/A", | ||
contains_liquids=item.metadata.get("contains_liquids"), | ||
contains_battery_pi966=item.metadata.get( | ||
"contains_battery_pi966" | ||
|
@@ -250,7 +271,17 @@ def shipment_request( | |
"contains_battery_pi967" | ||
), | ||
) | ||
for item in package.items | ||
for item in lib.identity( | ||
(package.items if any(package.items) else customs.commodities) | ||
if any(package.items) or any(payload.customs or "") | ||
else [ | ||
models.Commodity( | ||
title=lib.text(package.description, max=35), | ||
quantity=1, | ||
value_amount=1.0, | ||
) | ||
] | ||
) | ||
], | ||
total_actual_weight=package.weight.value, | ||
) | ||
|
@@ -264,7 +295,8 @@ def shipment_request( | |
lib.to_json(_).replace("shipment_request_return", "return") | ||
), | ||
ctx=dict( | ||
courier_id=courrier_id, | ||
courier_id=service, | ||
rate_provider=courier.name, | ||
label_type=label_type.name or "PDF", | ||
), | ||
) |
Oops, something went wrong.