Skip to content

Commit

Permalink
feat: introduce dhl_shipment_content to allow custom content descript…
Browse files Browse the repository at this point in the history
…ion for insured items
  • Loading branch information
danh91 committed Oct 1, 2024
1 parent ba0c4a6 commit 0f1f153
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def shipment_request(
)
product = provider_units.ShippingService.map(payload.service).value_or_key

weight_unit, dim_unit = (
weight_unit, dim_unit = lib.identity(
provider_units.COUNTRY_PREFERED_UNITS.get(payload.shipper.country_code)
or packages.compatible_units
)
Expand Down Expand Up @@ -113,9 +113,15 @@ def shipment_request(
option for _, option in options.items() if option.state is not False
]
duty = customs.duty or models.Duty(paid_by="sender")
content = packages[0].parcel.content or customs.content_description or "N/A"
content = lib.identity(
options.dhl_shipment_content.state
or customs.content_description
or packages.content
or packages.description
or "N/A"
)
reference = payload.reference or getattr(payload, "id", None)
currency = (
currency = lib.identity(
options.currency.state
or units.CountryCurrency.map(payload.shipper.country_code).value
or settings.default_currency
Expand Down Expand Up @@ -171,7 +177,7 @@ def shipment_request(
),
BusinessPartyTypeCode=None,
),
Commodity=(
Commodity=lib.identity(
[
dhl.Commodity(
CommodityCode=c.hs_code or c.sku or "N/A",
Expand All @@ -182,7 +188,7 @@ def shipment_request(
if any(customs.commodities)
else None
),
Dutiable=(
Dutiable=lib.identity(
dhl_global.Dutiable(
DeclaredValue=(
duty.declared_value or options.declared_value.state or 1.0
Expand Down Expand Up @@ -212,10 +218,10 @@ def shipment_request(
),
UseDHLInvoice=("Y" if is_dutiable else None),
DHLInvoiceLanguageCode=("en" if is_dutiable else None),
DHLInvoiceType=(
DHLInvoiceType=lib.identity(
("CMI" if customs.commercial_invoice else "PFI") if is_dutiable else None
),
ExportDeclaration=(
ExportDeclaration=lib.identity(
dhl_global.ExportDeclaration(
InterConsignee=None,
IsPartiesRelation=None,
Expand Down Expand Up @@ -291,7 +297,7 @@ def shipment_request(
"COMMERCIAL" if customs.commercial_invoice else "PERSONAL"
),
DocumentFunction=None,
CustomsDocuments=(
CustomsDocuments=lib.identity(
dhl_global.CustomsDocuments(
CustomsDocument=[
dhl.CustomsDocument(
Expand All @@ -314,7 +320,7 @@ def shipment_request(
if is_dutiable
else None
),
Reference=(
Reference=lib.identity(
[dhl.Reference(ReferenceID=lib.text(reference, max=30))]
if any(reference or "")
else None
Expand Down Expand Up @@ -373,7 +379,7 @@ def shipment_request(
IsDutiable=("Y" if is_dutiable else "N"),
CurrencyCode=currency,
CustData=getattr(payload, "id", None),
ShipmentCharges=(
ShipmentCharges=lib.identity(
options.cash_on_delivery.state
if options.cash_on_delivery.state
else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ class ShippingOption(lib.Enum):
dhl_customer_rebate = lib.OptionEnum("ZD", bool)
dhl_e_com_discount = lib.OptionEnum("ZE", bool)

""" Custom Options """
dhl_shipment_content = lib.OptionEnum("content")

""" Unified Option type mapping """
insurance = dhl_shipment_insurance
paperless_trade = dhl_paperless_trade
Expand All @@ -613,7 +616,7 @@ def shipping_options_initializer(
_options.update(package_options.content)

def items_filter(key: str) -> bool:
return key in ShippingOption # type: ignore
return key in ShippingOption and key != "dhl_shipment_content" # type: ignore

return lib.units.ShippingOptions(
_options, ShippingOption, items_filter=items_filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def test_not_supported_cancel_shipment(self):
"incoterm": "DAP",
"invoice": "N/A",
"invoice_date": "2021-05-03",
"commodities": [{"description": "cn", "weight": 4.0, "sku": "sku", "hs_code": "hs_code"}],
"commodities": [
{"description": "cn", "weight": 4.0, "sku": "sku", "hs_code": "hs_code"}
],
"duty": {
"account_number": "123456789",
"paid_by": "sender",
Expand Down Expand Up @@ -538,7 +540,7 @@ def test_not_supported_cancel_shipment(self):
<GlobalProductCode>8</GlobalProductCode>
<LocalProductCode>8</LocalProductCode>
<Date>2023-12-15</Date>
<Contents>N/A</Contents>
<Contents>title</Contents>
<DimensionUnit>C</DimensionUnit>
<PackageType>JJ</PackageType>
<IsDutiable>Y</IsDutiable>
Expand Down
9 changes: 9 additions & 0 deletions modules/sdk/karrio/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,15 @@ def description(self) -> typing.Optional[str]:

return description

@property
def content(self) -> typing.Optional[str]:
contents = set([item.parcel.content for item in self._items])
content: typing.Optional[str] = utils.SF.concat_str(
*list(contents), join=True
) # type:ignore

return content

@property
def options(self) -> "ShippingOptions":
def merge_options(acc, pkg) -> dict:
Expand Down

0 comments on commit 0f1f153

Please sign in to comment.