Skip to content

Commit

Permalink
(fix) dhl_express option parsing and filter
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Dec 13, 2023
1 parent da2ddb8 commit 8ffe970
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def rate_request(
options = lib.to_shipping_options(
payload.options,
package_options=packages.options,
origin_country=payload.shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def shipment_request(
options = lib.to_shipping_options(
payload.options,
package_options=packages.options,
origin_country=shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

Expand Down Expand Up @@ -275,7 +276,7 @@ def shipment_request(
]
)
if (
options.dhl_paperless_trade.state
options.dhl_paperless_trade.state == True
and any(options.doc_references.state or [])
)
else None
Expand Down Expand Up @@ -420,7 +421,8 @@ def shipment_request(
]
)
if (
options.dhl_paperless_trade.state and any(options.doc_files.state or [])
options.dhl_paperless_trade.state == True
and any(options.doc_files.state or [])
)
else None
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,21 @@ class ShippingOption(lib.Enum):
def shipping_options_initializer(
options: dict,
package_options: lib.units.Options = None,
origin_country: str = None,
) -> lib.units.Options:
"""
Apply default values to the given options.
"""
_options = options.copy()

if origin_country in UNSUPPORTED_PAPERLESS_COUNTRIES:
_options.update({"dhl_paperless_trade": False})

if package_options is not None:
_options.update(package_options.content)

def items_filter(key: str) -> bool:
return key in ShippingOption # type: ignore
return (key in ShippingOption) and (_options.get(key) not in [False]) # type: ignore

return lib.units.ShippingOptions(
_options, ShippingOption, items_filter=items_filter
Expand Down

0 comments on commit 8ffe970

Please sign in to comment.