Skip to content

Commit

Permalink
feat: Identified and ensure all required FedEx Intl data are provided…
Browse files Browse the repository at this point in the history
… according to sandbox samples
  • Loading branch information
danh91 committed Apr 9, 2024
1 parent c2a6f96 commit fad46de
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 12 deletions.
16 changes: 13 additions & 3 deletions modules/connectors/fedex/karrio/providers/fedex/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ def rate_request(
commodities=[
fedex.CommodityType(
description=lib.text(
item.title or item.description or "N/A", max=35
item.description or item.title or "N/A", max=35
),
weight=fedex.WeightType(
units=packages.weight_unit,
value=item.weight,
),
unitPrice=(
unitPrice=lib.identity(
fedex.FixedValueType(
amount=lib.to_money(item.value_amount),
currency=(
Expand All @@ -287,11 +287,21 @@ def rate_request(
if item.value_amount
else None
),
customsValue=fedex.FixedValueType(
amount=lib.identity(
lib.to_money(item.value_amount or 1.0 * item.quantity)
),
currency=lib.identity(
item.value_currency
or packages.options.currency.state
or "USD"
),
),
quantity=item.quantity,
numberOfPieces=item.quantity,
quantityUnits="PCS",
harmonizedCode=item.hs_code,
name=None,
name=item.title,
partNumber=item.sku,
)
for item in commodities
Expand Down
49 changes: 40 additions & 9 deletions modules/connectors/fedex/karrio/providers/fedex/shipment/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,12 @@ def shipment_request(
),
commodities=[
fedex.CommodityType(
unitPrice=(
unitPrice=lib.identity(
fedex.TotalDeclaredValueType(
amount=lib.to_money(item.value_amount),
currency=(
item.value_currency
or packages.options.currency.state
or customs.duty.currency
),
)
if item.value_amount
Expand All @@ -430,16 +429,27 @@ def shipment_request(
numberOfPieces=item.quantity,
quantity=item.quantity,
quantityUnits="PCS",
customsValue=None,
customsValue=fedex.CustomsValueType(
amount=lib.identity(
lib.to_money(
item.value_amount or 1.0 * item.quantity
)
),
currency=lib.identity(
item.value_currency
or packages.options.currency.state
or "USD"
),
),
countryOfManufacture=(
item.origin_country or shipper.country_code
),
cIMarksAndNumbers=None,
harmonizedCode=item.hs_code,
description=lib.text(
item.title or item.description or "N/A", max=35
item.description or item.title or "N/A", max=35
),
name=None,
name=lib.text(item.title, max=35),
weight=fedex.WeightType(
units=weight_unit.value,
value=item.weight,
Expand All @@ -458,7 +468,19 @@ def shipment_request(
importerOfRecord=None,
generatedDocumentLocale=None,
exportDetail=None,
totalCustomsValue=None,
totalCustomsValue=lib.identity(
fedex.TotalDeclaredValueType(
amount=lib.to_money(
packages.options.declared_value.state
),
currency=lib.identity(
packages.options.currency.state or "USD"
),
)
if lib.to_money(packages.options.declared_value.state)
is not None
else None
),
partiesToTransactionAreRelated=None,
declarationStatementDetail=None,
insuranceCharge=None,
Expand All @@ -479,7 +501,7 @@ def shipment_request(
if hub_id and service == "SMART_POST"
else None
),
blockInsightVisibility=None,
blockInsightVisibility=False,
labelSpecification=fedex.LabelSpecificationType(
labelFormatType="COMMON2D",
labelOrder="SHIPPING_LABEL_FIRST",
Expand Down Expand Up @@ -530,7 +552,16 @@ def shipment_request(
).value
),
customerReferences=[],
declaredValue=None,
declaredValue=fedex.TotalDeclaredValueType(
amount=lib.identity(
lib.to_money(package.total_value)
or lib.to_money(packages.options.declared_value.state)
or 1.0
),
currency=lib.identity(
packages.options.currency.state or "USD"
),
),
weight=fedex.WeightType(
units=package.weight.unit,
value=package.weight.value,
Expand All @@ -552,7 +583,7 @@ def shipment_request(
)
else None
),
groupPackageCount=None,
groupPackageCount=1,
itemDescriptionForClearance=None,
contentRecord=[],
itemDescription=package.parcel.description,
Expand Down
2 changes: 2 additions & 0 deletions modules/connectors/fedex/tests/fedex/test_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ def test_parse_rate_response(self):
"customsClearanceDetail": {
"commodities": [
{
"name": "test",
"description": "test",
"harmonizedCode": "00339BB",
"numberOfPieces": 1,
"quantity": 1,
"quantityUnits": "PCS",
"weight": {"units": "LB", "value": 10.0},
"customsValue": {"amount": 1.0, "currency": "USD"},
}
],
"dutiesPayment": {
Expand Down
15 changes: 15 additions & 0 deletions modules/connectors/fedex/tests/fedex/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def test_parse_cancel_shipment_response(self):
"accountNumber": {"value": "2349857"},
"labelResponseOptions": "LABEL",
"requestedShipment": {
"blockInsightVisibility": False,
"customsClearanceDetail": {
"commercialInvoice": {
"customerReferences": [
Expand All @@ -229,11 +230,13 @@ def test_parse_cancel_shipment_response(self):
{
"countryOfManufacture": "US",
"description": "test",
"name": "test",
"harmonizedCode": "00339BB",
"numberOfPieces": 1,
"quantity": 1,
"quantityUnits": "PCS",
"weight": {"units": "LB", "value": 10.0},
"customsValue": {"amount": 1.0, "currency": "USD"},
}
],
"dutiesPayment": {
Expand Down Expand Up @@ -294,12 +297,14 @@ def test_parse_cancel_shipment_response(self):
],
"requestedPackageLineItems": [
{
"declaredValue": {"amount": 1.0, "currency": "USD"},
"dimensions": {
"height": 12.0,
"length": 12.0,
"units": "IN",
"width": 12.0,
},
"groupPackageCount": 1,
"packageSpecialServices": {
"signatureOptionType": "SERVICE_DEFAULT",
"specialServiceTypes": ["SIGNATURE_OPTION"],
Expand Down Expand Up @@ -346,6 +351,7 @@ def test_parse_cancel_shipment_response(self):
"accountNumber": {"value": "2349857"},
"labelResponseOptions": "LABEL",
"requestedShipment": {
"blockInsightVisibility": False,
"customsClearanceDetail": {
"commercialInvoice": {
"customerReferences": [
Expand All @@ -361,11 +367,13 @@ def test_parse_cancel_shipment_response(self):
{
"countryOfManufacture": "US",
"description": "test",
"name": "test",
"harmonizedCode": "00339BB",
"numberOfPieces": 1,
"quantity": 1,
"quantityUnits": "PCS",
"weight": {"units": "LB", "value": 10.0},
"customsValue": {"amount": 1.0, "currency": "USD"},
}
],
"dutiesPayment": {
Expand Down Expand Up @@ -426,12 +434,14 @@ def test_parse_cancel_shipment_response(self):
],
"requestedPackageLineItems": [
{
"declaredValue": {"amount": 1.0, "currency": "USD"},
"dimensions": {
"height": 12.0,
"length": 12.0,
"units": "IN",
"width": 12.0,
},
"groupPackageCount": 1,
"packageSpecialServices": {
"signatureOptionType": "SERVICE_DEFAULT",
"specialServiceTypes": ["SIGNATURE_OPTION"],
Expand Down Expand Up @@ -482,6 +492,7 @@ def test_parse_cancel_shipment_response(self):
"accountNumber": {"value": "2349857"},
"labelResponseOptions": "LABEL",
"requestedShipment": {
"blockInsightVisibility": False,
"customsClearanceDetail": {
"commercialInvoice": {
"customerReferences": [
Expand All @@ -497,11 +508,13 @@ def test_parse_cancel_shipment_response(self):
{
"countryOfManufacture": "US",
"description": "test",
"name": "test",
"harmonizedCode": "00339BB",
"numberOfPieces": 1,
"quantity": 1,
"quantityUnits": "PCS",
"weight": {"units": "LB", "value": 10.0},
"customsValue": {"amount": 1.0, "currency": "USD"},
}
],
"dutiesPayment": {
Expand Down Expand Up @@ -566,12 +579,14 @@ def test_parse_cancel_shipment_response(self):
],
"requestedPackageLineItems": [
{
"declaredValue": {"amount": 1.0, "currency": "USD"},
"dimensions": {
"height": 11.0,
"length": 11.0,
"units": "IN",
"width": 11.0,
},
"groupPackageCount": 1,
"packageSpecialServices": {
"signatureOptionType": "SERVICE_DEFAULT",
"specialServiceTypes": ["SIGNATURE_OPTION"],
Expand Down
16 changes: 16 additions & 0 deletions modules/sdk/karrio/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ def items(self) -> Products:

return Products(_items, self.weight_unit.value)

@property
def total_value(self) -> typing.Optional[float]:
if not any(self.parcel.items or []):
return None

return self.items.value_amount

class Packages(typing.Iterable[Package]):
"""The parcel collection common processing helper"""
Expand Down Expand Up @@ -943,6 +949,16 @@ def items(self) -> Products:

return Products(_items, _weight_unit.value)

@property
def total_value(self) -> typing.Optional[float]:
if not any([_.total_value for _ in self._items]):
return None

return sum(
[pkg.total_value for pkg in self._items if pkg.total_value is not None],
0.0
)

def validate(self, required: typing.List[str] = None, max_weight: Weight = None):
required = required or self._required
max_weight = max_weight or self._max_weight
Expand Down

0 comments on commit fad46de

Please sign in to comment.