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

[patch] 2024.6.4 #681

Merged
merged 14 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions modules/connectors/ups/generate
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ LIB_MODULES=./karrio/schemas/ups
find "${LIB_MODULES}" -name "*.py" -exec rm -r {} \;
touch "${LIB_MODULES}/__init__.py"

quicktype () {
quicktype() {
echo "Generating $1..."
docker run -it --rm --name quicktype -v $PWD:/app -e SCHEMAS=/app/schemas -e LIB_MODULES=/app/karrio/schemas/ups \
karrio/tools /quicktype/script/quicktype --no-uuids --no-date-times --no-enums --src-lang json --lang jstruct \
--no-nice-property-names --all-properties-optional --type-as-suffix $@
karrio/tools /quicktype/script/quicktype --no-uuids --no-date-times --no-enums --src-lang json --lang jstruct \
--no-nice-property-names --all-properties-optional --type-as-suffix $@
}

quicktype --src="${SCHEMAS}/document_upload_request.json" --out="${LIB_MODULES}/document_upload_request.py"
quicktype --src="${SCHEMAS}/document_upload_response.json" --out="${LIB_MODULES}/document_upload_response.py"
quicktype --src="${SCHEMAS}/error.json" --out="${LIB_MODULES}/error.py"
quicktype --src="${SCHEMAS}/error_response.json" --out="${LIB_MODULES}/error_response.py"
quicktype --src="${SCHEMAS}/rating_request.json" --out="${LIB_MODULES}/rating_request.py"
quicktype --src="${SCHEMAS}/rating_response.json" --out="${LIB_MODULES}/rating_response.py"
quicktype --src="${SCHEMAS}/rating_responses.json" --out="${LIB_MODULES}/rating_response.py"
quicktype --src="${SCHEMAS}/shipping_request.json" --out="${LIB_MODULES}/shipping_request.py"
quicktype --src="${SCHEMAS}/shipping_response.json" --out="${LIB_MODULES}/shipping_response.py"
quicktype --src="${SCHEMAS}/tracking_response.json" --out="${LIB_MODULES}/tracking_response.py"
Expand Down
32 changes: 18 additions & 14 deletions modules/connectors/ups/karrio/providers/ups/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import typing
import karrio.lib as lib
import karrio.core.units as units
import karrio.core.models as models
import karrio.providers.ups.error as provider_error
import karrio.providers.ups.units as provider_units
Expand All @@ -27,35 +28,35 @@ def _extract_details(
ctx: dict,
) -> typing.List[models.RateDetails]:
rate = lib.to_object(ups_response.RatedShipmentType, detail)
effective_rate = rate.NegotiatedRateCharges if rate.NegotiatedRateCharges is not None else rate
effective_rate = lib.identity(
rate.NegotiatedRateCharges if rate.NegotiatedRateCharges is not None else rate
)
total_charge = effective_rate.TotalChargesWithTaxes or effective_rate.TotalCharges
taxes = effective_rate.TaxCharges or []
itemized_charges = [*effective_rate.ItemizedCharges, *taxes]

charges = [
("Base charge", effective_rate.BaseServiceCharge.MonetaryValue),
*(
*lib.identity(
[]
if any(itemized_charges)
else [("Taxes", sum(lib.to_money(c.MonetaryValue) for c in taxes))]
),
*(
*lib.identity(
(rate.Service.Code, rate.ServiceOptionsCharges.MonetaryValue)
if lib.to_int(rate.ServiceOptionsCharges.MonetaryValue) > 0
else []
),
*(
*lib.identity(
(
(
lib.identity(
provider_units.SurchargeType.map(
str(getattr(c, "Code", None) or getattr(c, "Type", None))
).name.capitalize().replace("_", " ")
if provider_units.SurchargeType.map(
str(getattr(c, "Code", None) or getattr(c, "Type", None))
).name
else (getattr(c, "Code", None) or getattr(c, "Type", None))
)
.name_or_key.replace("_", " ")
.upper()
danh91 marked this conversation as resolved.
Show resolved Hide resolved
),
c.MonetaryValue
c.MonetaryValue,
)
for c in itemized_charges
),
Expand Down Expand Up @@ -106,13 +107,16 @@ def rate_request(
mps_packaging = lib.identity(
provider_units.PackagingType.ups_unknown.value if len(packages) > 1 else None
)
weight_unit, dim_unit = lib.identity(
provider_units.COUNTRY_PREFERED_UNITS.get(payload.shipper.country_code)
or packages.compatible_units
)
indications = [
*(["01"] if options.pickup_options.state else []),
*(["02"] if options.delivery_options.state else []),
]
weight_unit, dim_unit = lib.identity(
provider_units.COUNTRY_PREFERED_UNITS.get(payload.shipper.country_code)
or packages.compatible_units
origin = lib.identity(
"EU" if shipper.country_code in units.EUCountry else shipper.country_code
)

request = ups.RatingRequestType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@


@s(auto_attribs=True)
class ErrorElementType:
class ErrorType:
code: Optional[int] = None
message: Optional[str] = None


@s(auto_attribs=True)
class ResponseType:
errors: List[ErrorElementType] = JList[ErrorElementType]
errors: List[ErrorType] = JList[ErrorType]


@s(auto_attribs=True)
class ErrorType:
class ErrorResponseType:
response: Optional[ResponseType] = JStruct[ResponseType]
58 changes: 35 additions & 23 deletions modules/connectors/ups/karrio/schemas/ups/rating_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from attr import s
from typing import Optional, List
from typing import Optional, Any, Union, List
from jstruct import JStruct, JList


Expand All @@ -10,14 +10,14 @@ class BaseServiceChargeType:


@s(auto_attribs=True)
class AlertType:
class ResponseStatusType:
Code: Optional[str] = None
Description: Optional[str] = None


@s(auto_attribs=True)
class BillingWeightType:
UnitOfMeasurement: Optional[AlertType] = JStruct[AlertType]
UnitOfMeasurement: Optional[ResponseStatusType] = JStruct[ResponseStatusType]
Weight: Optional[str] = None


Expand All @@ -30,21 +30,21 @@ class FreightDensityRateType:
@s(auto_attribs=True)
class AdjustedHeightType:
Value: Optional[str] = None
UnitOfMeasurement: Optional[AlertType] = JStruct[AlertType]
UnitOfMeasurement: Optional[ResponseStatusType] = JStruct[ResponseStatusType]


@s(auto_attribs=True)
class DimensionsType:
UnitOfMeasurement: Optional[AlertType] = JStruct[AlertType]
UnitOfMeasurement: Union[ResponseStatusType, Any, str]
Length: Optional[str] = None
Width: Optional[str] = None
Height: Optional[str] = None


@s(auto_attribs=True)
class HandlingUnitsType:
class HandlingUnitType:
Quantity: Optional[str] = None
Type: Optional[AlertType] = JStruct[AlertType]
Type: Optional[ResponseStatusType] = JStruct[ResponseStatusType]
Dimensions: Optional[DimensionsType] = JStruct[DimensionsType]
AdjustedHeight: Optional[AdjustedHeightType] = JStruct[AdjustedHeightType]

Expand All @@ -61,17 +61,18 @@ class TransportationChargesType:
class FRSShipmentDataType:
TransportationCharges: Optional[TransportationChargesType] = JStruct[TransportationChargesType]
FreightDensityRate: Optional[FreightDensityRateType] = JStruct[FreightDensityRateType]
HandlingUnits: Optional[HandlingUnitsType] = JStruct[HandlingUnitsType]
HandlingUnits: List[HandlingUnitType] = JList[HandlingUnitType]


@s(auto_attribs=True)
class GuaranteedDeliveryType:
BusinessDaysInTransit: Optional[int] = None
BusinessDaysInTransit: Optional[str] = None
DeliveryByTime: Optional[str] = None
ScheduledDeliveryDate: Optional[str] = None


@s(auto_attribs=True)
class ItemizedChargeType:
class ItemizedChargeClassType:
Code: Optional[str] = None
Description: Optional[str] = None
CurrencyCode: Optional[str] = None
Expand All @@ -87,7 +88,7 @@ class TaxChargeType:

@s(auto_attribs=True)
class NegotiatedRateChargesType:
ItemizedCharges: List[ItemizedChargeType] = JList[ItemizedChargeType]
ItemizedCharges: List[ItemizedChargeClassType] = JList[ItemizedChargeClassType]
TaxCharges: List[TaxChargeType] = JList[TaxChargeType]
TotalCharge: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
TotalChargesWithTaxes: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
Expand All @@ -96,7 +97,11 @@ class NegotiatedRateChargesType:

@s(auto_attribs=True)
class NegotiatedChargesType:
ItemizedCharges: List[ItemizedChargeType] = JList[ItemizedChargeType]
ItemizedCharges: List[Union[ItemizedChargeClassType, str]] = JList[Union[ItemizedChargeClassType, str]]
BaseServiceCharge: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
TransportationCharges: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
ServiceOptionsCharges: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
TotalCharge: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]


@s(auto_attribs=True)
Expand All @@ -107,6 +112,11 @@ class RateModifierType:
Amount: Optional[str] = None


@s(auto_attribs=True)
class SimpleRateType:
Code: Optional[str] = None


@s(auto_attribs=True)
class RatedPackageType:
BaseServiceCharge: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
Expand All @@ -115,10 +125,11 @@ class RatedPackageType:
TotalCharges: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
Weight: Optional[str] = None
BillingWeight: Optional[BillingWeightType] = JStruct[BillingWeightType]
Accessorial: List[AlertType] = JList[AlertType]
ItemizedCharges: List[ItemizedChargeType] = JList[ItemizedChargeType]
Accessorial: List[ResponseStatusType] = JList[ResponseStatusType]
ItemizedCharges: List[ItemizedChargeClassType] = JList[ItemizedChargeClassType]
NegotiatedCharges: Optional[NegotiatedChargesType] = JStruct[NegotiatedChargesType]
RateModifier: Optional[RateModifierType] = JStruct[RateModifierType]
RateModifier: List[RateModifierType] = JList[RateModifierType]
SimpleRate: Optional[SimpleRateType] = JStruct[SimpleRateType]


@s(auto_attribs=True)
Expand Down Expand Up @@ -169,16 +180,16 @@ class TimeInTransitType:

@s(auto_attribs=True)
class RatedShipmentType:
Disclaimer: List[AlertType] = JList[AlertType]
Service: Optional[AlertType] = JStruct[AlertType]
Disclaimer: List[ResponseStatusType] = JList[ResponseStatusType]
Service: Optional[ResponseStatusType] = JStruct[ResponseStatusType]
RateChart: Optional[str] = None
RatedShipmentAlert: List[AlertType] = JList[AlertType]
RatedShipmentAlert: List[ResponseStatusType] = JList[ResponseStatusType]
BillableWeightCalculationMethod: Optional[str] = None
RatingMethod: Optional[str] = None
BillingWeight: Optional[BillingWeightType] = JStruct[BillingWeightType]
TransportationCharges: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
BaseServiceCharge: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
ItemizedCharges: List[ItemizedChargeType] = JList[ItemizedChargeType]
ItemizedCharges: List[ItemizedChargeClassType] = JList[ItemizedChargeClassType]
FRSShipmentData: Optional[FRSShipmentDataType] = JStruct[FRSShipmentDataType]
ServiceOptionsCharges: Optional[BaseServiceChargeType] = JStruct[BaseServiceChargeType]
TaxCharges: List[TaxChargeType] = JList[TaxChargeType]
Expand Down Expand Up @@ -214,13 +225,14 @@ class AlertDetailType:
@s(auto_attribs=True)
class TransactionReferenceType:
CustomerContext: Optional[str] = None
TransactionIdentifier: Optional[str] = None


@s(auto_attribs=True)
class ResponseType:
ResponseStatus: Optional[AlertType] = JStruct[AlertType]
Alert: Optional[AlertType] = JStruct[AlertType]
AlertDetail: Optional[AlertDetailType] = JStruct[AlertDetailType]
ResponseStatus: Optional[ResponseStatusType] = JStruct[ResponseStatusType]
Alert: List[ResponseStatusType] = JList[ResponseStatusType]
AlertDetail: List[AlertDetailType] = JList[AlertDetailType]
TransactionReference: Optional[TransactionReferenceType] = JStruct[TransactionReferenceType]


Expand All @@ -231,5 +243,5 @@ class RateResponseType:


@s(auto_attribs=True)
class RatingResponseType:
class RatingResponseElementType:
RateResponse: Optional[RateResponseType] = JStruct[RateResponseType]
Loading
Loading