Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[merge] paperless trade fix #465

Merged
merged 4 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/karrio/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.9.6
2023.9.7
2 changes: 1 addition & 1 deletion apps/api/karrio/server/static/karrio/js/karrio.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export KARRIO_TAG="${KARRIO_TAG:-2023.9.6}"
export KARRIO_TAG="${KARRIO_TAG:-2023.9.7}"
export SENTRY_DSN="${SENTRY_DSN:-'https://public@sentry.example.com/1'}"

SECRET_KEY=$(head -c 28 /dev/urandom | sha224sum -b | head -c 56)
Expand All @@ -23,7 +23,7 @@ if ! [ -z "$1" ]
then
export KARRIO_TAG=$1
else
echo "What version of Karrio would you like to install? (We default to '2023.9.6')"
echo "What version of Karrio would you like to install? (We default to '2023.9.7')"
echo "You can check out available versions here: https://hub.docker.com/r/karrio/server/tags"
read -r KARRIO_TAG_READ
if [ -z "$KARRIO_TAG_READ" ]
Expand Down
2 changes: 1 addition & 1 deletion bin/upgrade-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else
fi

[[ -f ".env" ]] && export $(cat .env | xargs) || ( echo "No .env file found. Please create it with SECRET_KEY and DOMAIN set." && exit 1)
export KARRIO_TAG="${KARRIO_TAG:-2023.9.6}"
export KARRIO_TAG="${KARRIO_TAG:-2023.9.7}"

# get karrio scripts
mkdir -p ./karrio
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3"
services:
api:
container_name: karrio.api
image: karrio.docker.scarf.sh/karrio/server:2023.9.6
image: karrio.docker.scarf.sh/karrio/server:2023.9.7
restart: unless-stopped
ports:
- ${KARRIO_HTTP_PORT}:${KARRIO_HTTP_PORT}
Expand All @@ -25,7 +25,7 @@ services:

worker:
container_name: karrio.worker
image: karrio.docker.scarf.sh/karrio/server:2023.9.6
image: karrio.docker.scarf.sh/karrio/server:2023.9.7
restart: unless-stopped
depends_on:
- db
Expand All @@ -46,7 +46,7 @@ services:

dashboard:
container_name: karrio.dashboard
image: karrio.docker.scarf.sh/karrio/dashboard:2023.9.6
image: karrio.docker.scarf.sh/karrio/dashboard:2023.9.7
restart: unless-stopped
ports:
- ${DASHBOARD_PORT}:3000/tcp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def rate_request(
origin_country=payload.shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

option_items = [
option for _, option in options.items() if option.state is not False
]
weight_unit, dim_unit = (
provider_units.COUNTRY_PREFERED_UNITS.get(payload.shipper.country_code)
or packages.compatible_units
Expand Down Expand Up @@ -192,9 +194,9 @@ def rate_request(
QtdShpExChrg=(
[
dhl.QtdShpExChrgType(SpecialServiceType=option.code)
for _, option in options.items()
for option in option_items
]
if any(options.items())
if any(option_items)
else None
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def shipment_request(
origin_country=shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

option_items = [
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"
reference = payload.reference or getattr(payload, "id", None)
Expand Down Expand Up @@ -392,7 +394,7 @@ def shipment_request(
currency if lib.to_money(svc.state) is not None else None
),
)
for _, svc in options.items()
for svc in option_items
],
Notification=(
dhl.Notification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def shipping_options_initializer(
_options.update(package_options.content)

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

return lib.units.ShippingOptions(
_options, ShippingOption, items_filter=items_filter
Expand Down
2 changes: 1 addition & 1 deletion modules/connectors/dhl_express/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="karrio.dhl_express",
version="2023.9.6",
version="2023.9.7",
description="Karrio - DHL Express Shipping Extension",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
209 changes: 209 additions & 0 deletions modules/connectors/dhl_express/tests/dhl_express/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class TestDHLShipment(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.ShipmentRequest = ShipmentRequest(**shipment_data)
self.NonPaperlessShipmentRequest = ShipmentRequest(
**non_paperless_intl_shipment_data
)

def test_create_shipment_request(self):
request = gateway.mapper.create_shipment_request(self.ShipmentRequest)
Expand All @@ -25,6 +28,20 @@ def test_create_shipment_request(self):

self.assertEqual(serialized_request, ShipmentRequestXml)

def test_create_non_paperless_shipment_request(self):
request = gateway.mapper.create_shipment_request(
self.NonPaperlessShipmentRequest
)

# remove MessageTime, Date for testing purpose
serialized_request = re.sub(
" <MessageTime>[^>]+</MessageTime>",
"",
request.serialize(),
)

self.assertEqual(serialized_request, NonParelessShipmentRequestXml)

@patch("karrio.mappers.dhl_express.proxy.lib.request", return_value="<a></a>")
def test_create_shipment(self, http_mock):
karrio.Shipment.create(self.ShipmentRequest).from_(gateway)
Expand Down Expand Up @@ -125,6 +142,81 @@ def test_not_supported_cancel_shipment(self):
},
}

non_paperless_intl_shipment_data = {
"customs": {
"certify": True,
"commercial_invoice": True,
"commodities": [
{
"description": "description",
"hs_code": "12345",
"metadata": {},
"quantity": 1,
"sku": "sku",
"title": "title",
"value_amount": 928.1,
"value_currency": "EUR",
"weight": 0.847,
"weight_unit": "KG",
}
],
"content_type": "merchandise",
"duty": {"currency": "EUR", "declared_value": 928.1, "paid_by": "sender"},
"incoterm": "DDP",
"invoice": "36892319",
"invoice_date": "2023-12-15",
"options": {},
},
"options": {
"currency": "EUR",
"declared_value": 928.1,
"paperless_trade": False,
"shipment_date": "2023-12-15",
},
"parcels": [
{
"dimension_unit": "CM",
"height": 5,
"is_document": False,
"items": [
{
"description": "description",
"hs_code": "123456",
"metadata": {},
"quantity": 1,
"sku": "sku",
"title": "title",
"value_amount": 928.1,
"value_currency": "EUR",
"weight": 0.847,
"weight_unit": "KG",
}
],
"length": 30,
"packaging_type": "small_box",
"weight": 0.847,
"weight_unit": "KG",
"width": 22,
}
],
"recipient": {
"address_line1": "Biryat Hadid 34",
"city": "Istanbul",
"country_code": "TR",
"email": "store@customer.com",
"person_name": "Store Customer",
"postal_code": "34020",
},
"service": "dhl_express_easy_nondoc",
"shipper": {
"address_line1": "address_line_1",
"city": "city",
"country_code": "CZ",
"person_name": "person_name",
},
}


ParsedShipmentMissingArgsError = [
None,
[
Expand Down Expand Up @@ -355,6 +447,123 @@ def test_not_supported_cancel_shipment(self):
</req:ShipmentRequest>
"""

NonParelessShipmentRequestXml = """<req:ShipmentRequest xsi:schemaLocation="http://www.dhl.com ship-val-global-req.xsd" xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="10.0">
<Request>
<ServiceHeader>

<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>site_id</SiteID>
<Password>password</Password>
</ServiceHeader>
<MetaData>
<SoftwareName>3PV</SoftwareName>
<SoftwareVersion>10.0</SoftwareVersion>
</MetaData>
</Request>
<RegionCode>EU</RegionCode>
<LanguageCode>en</LanguageCode>
<Billing>
<ShipperAccountNumber>123456789</ShipperAccountNumber>
<ShippingPaymentType>S</ShippingPaymentType>
<BillingAccountNumber>123456789</BillingAccountNumber>
</Billing>
<Consignee>
<CompanyName>N/A</CompanyName>
<AddressLine1>34 Biryat Hadid</AddressLine1>
<City>Istanbul</City>
<PostalCode>34020</PostalCode>
<CountryCode>TR</CountryCode>
<CountryName>Turkey</CountryName>
<Contact>
<PersonName>Store Customer</PersonName>
<PhoneNumber>0000</PhoneNumber>
<Email>store@customer.com</Email>
</Contact>
<StreetName>Biryat Hadid</StreetName>
<StreetNumber>34</StreetNumber>
</Consignee>
<Commodity>
<CommodityCode>sku</CommodityCode>
<CommodityName>title</CommodityName>
</Commodity>
<Dutiable>
<DeclaredValue>928.1</DeclaredValue>
<DeclaredCurrency>EUR</DeclaredCurrency>
<TermsOfTrade>DDP</TermsOfTrade>
</Dutiable>
<UseDHLInvoice>Y</UseDHLInvoice>
<ExportDeclaration>
<ExportReason>merchandise</ExportReason>
<ExportReasonCode>C</ExportReasonCode>
<InvoiceNumber>36892319</InvoiceNumber>
<InvoiceDate>2023-12-15</InvoiceDate>
<ExportLineItem>
<LineNumber>1</LineNumber>
<Quantity>1</Quantity>
<QuantityUnit>PCS</QuantityUnit>
<Description>title</Description>
<Value>928.1</Value>
<CommodityCode>sku</CommodityCode>
<Weight>
<Weight>0.85</Weight>
<WeightUnit>K</WeightUnit>
</Weight>
<GrossWeight>
<Weight>0.85</Weight>
<WeightUnit>K</WeightUnit>
</GrossWeight>
<ManufactureCountryCode>CZ</ManufactureCountryCode>
<ManufactureCountryName>Czech Republic</ManufactureCountryName>
<ImportCommodityCode>12345</ImportCommodityCode>
</ExportLineItem>
<PlaceOfIncoterm>N/A</PlaceOfIncoterm>
<ShipmentPurpose>COMMERCIAL</ShipmentPurpose>
</ExportDeclaration>
<ShipmentDetails>
<Pieces>
<Piece>
<PieceID>1</PieceID>
<PackageType>JJ</PackageType>
<Weight>0.85</Weight>
<Width>22</Width>
<Height>5</Height>
<Depth>30</Depth>
</Piece>
</Pieces>
<WeightUnit>K</WeightUnit>
<GlobalProductCode>8</GlobalProductCode>
<LocalProductCode>8</LocalProductCode>
<Date>2023-12-15</Date>
<Contents>N/A</Contents>
<DimensionUnit>C</DimensionUnit>
<PackageType>JJ</PackageType>
<IsDutiable>Y</IsDutiable>
<CurrencyCode>EUR</CurrencyCode>
</ShipmentDetails>
<Shipper>
<ShipperID>123456789</ShipperID>
<CompanyName>N/A</CompanyName>
<RegisteredAccount>123456789</RegisteredAccount>
<AddressLine1>address_line_1</AddressLine1>
<City>city</City>
<CountryCode>CZ</CountryCode>
<CountryName>Czech Republic</CountryName>
<Contact>
<PersonName>person_name</PersonName>
<PhoneNumber>0000</PhoneNumber>
</Contact>
<StreetNumber>address_line_1</StreetNumber>
</Shipper>
<Notification>
<EmailAddress>store@customer.com</EmailAddress>
</Notification>
<LabelImageFormat>PDF</LabelImageFormat>
<Label>
<LabelTemplate>6X4_PDF</LabelTemplate>
</Label>
</req:ShipmentRequest>
"""

ShipmentResponseXml = """<?xml version="1.0" encoding="UTF-8"?><res:ShipmentResponse xmlns:res='http://www.dhl.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation= 'http://www.dhl.com ship-val-res.xsd'>
<Response>
<ServiceHeader>
Expand Down
4 changes: 2 additions & 2 deletions packages/types/rest/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable */
/**
* Karrio API
* ## API Reference Karrio is an open source multi-carrier shipping API that simplifies the integration of logistic carrier services. The Karrio API is organized around REST. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs. The Karrio API differs for every account as we release new versions. These docs are customized to your version of the API. ## Versioning When backwards-incompatible changes are made to the API, a new, dated version is released. The current version is `2023.9.6`. Read our API changelog and to learn more about backwards compatibility. As a precaution, use API versioning to check a new API version before committing to an upgrade. ## Environments The Karrio API offer the possibility to create and retrieve certain objects in `test_mode`. In development, it is therefore possible to add carrier connections, get live rates, buy labels, create trackers and schedule pickups in `test_mode`. ## Pagination All top-level API resources have support for bulk fetches via \"list\" API methods. For instance, you can list addresses, list shipments, and list trackers. These list API methods share a common structure, taking at least these two parameters: limit, and offset. Karrio utilizes offset-based pagination via the offset and limit parameters. Both parameters take a number as value (see below) and return objects in reverse chronological order. The offset parameter returns objects listed after an index. The limit parameter take a limit on the number of objects to be returned from 1 to 100. ```json { \"count\": 100, \"next\": \"/v1/shipments?limit=25&offset=50\", \"previous\": \"/v1/shipments?limit=25&offset=25\", \"results\": [ { ... }, ] } ``` ## Metadata Updateable Karrio objects—including Shipment and Order—have a metadata parameter. You can use this parameter to attach key-value data to these Karrio objects. Metadata is useful for storing additional, structured information on an object. As an example, you could store your user\'s full name and corresponding unique identifier from your system on a Karrio Order object. Do not store any sensitive information as metadata. ## Authentication API keys are used to authenticate requests. You can view and manage your API keys in the Dashboard. Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth. Authentication to the API is performed via HTTP Basic Auth. Provide your API token as the basic auth username value. You do not need to provide a password. ```shell $ curl https://instance.api.com/v1/shipments \\ -u key_xxxxxx: # The colon prevents curl from asking for a password. ``` If you need to authenticate via bearer auth (e.g., for a cross-origin request), use `-H \"Authorization: Token key_xxxxxx\"` instead of `-u key_xxxxxx`. All API requests must be made over [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure). API requests without authentication will also fail.
* ## API Reference Karrio is an open source multi-carrier shipping API that simplifies the integration of logistic carrier services. The Karrio API is organized around REST. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs. The Karrio API differs for every account as we release new versions. These docs are customized to your version of the API. ## Versioning When backwards-incompatible changes are made to the API, a new, dated version is released. The current version is `2023.9.7`. Read our API changelog and to learn more about backwards compatibility. As a precaution, use API versioning to check a new API version before committing to an upgrade. ## Environments The Karrio API offer the possibility to create and retrieve certain objects in `test_mode`. In development, it is therefore possible to add carrier connections, get live rates, buy labels, create trackers and schedule pickups in `test_mode`. ## Pagination All top-level API resources have support for bulk fetches via \"list\" API methods. For instance, you can list addresses, list shipments, and list trackers. These list API methods share a common structure, taking at least these two parameters: limit, and offset. Karrio utilizes offset-based pagination via the offset and limit parameters. Both parameters take a number as value (see below) and return objects in reverse chronological order. The offset parameter returns objects listed after an index. The limit parameter take a limit on the number of objects to be returned from 1 to 100. ```json { \"count\": 100, \"next\": \"/v1/shipments?limit=25&offset=50\", \"previous\": \"/v1/shipments?limit=25&offset=25\", \"results\": [ { ... }, ] } ``` ## Metadata Updateable Karrio objects—including Shipment and Order—have a metadata parameter. You can use this parameter to attach key-value data to these Karrio objects. Metadata is useful for storing additional, structured information on an object. As an example, you could store your user\'s full name and corresponding unique identifier from your system on a Karrio Order object. Do not store any sensitive information as metadata. ## Authentication API keys are used to authenticate requests. You can view and manage your API keys in the Dashboard. Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth. Authentication to the API is performed via HTTP Basic Auth. Provide your API token as the basic auth username value. You do not need to provide a password. ```shell $ curl https://instance.api.com/v1/shipments \\ -u key_xxxxxx: # The colon prevents curl from asking for a password. ``` If you need to authenticate via bearer auth (e.g., for a cross-origin request), use `-H \"Authorization: Token key_xxxxxx\"` instead of `-u key_xxxxxx`. All API requests must be made over [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure). API requests without authentication will also fail.
*
* The version of the OpenAPI document: 2023.9.6
* The version of the OpenAPI document: 2023.9.7
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Loading
Loading