Skip to content

Commit

Permalink
Merge pull request #470 from karrioapi/enrich-allied-express-services
Browse files Browse the repository at this point in the history
enhancement: Enrich allied express services
  • Loading branch information
danh91 authored Dec 18, 2023
2 parents 89e7771 + aa96f3b commit e0c5d6a
Showing 25 changed files with 3,231 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -17,4 +17,5 @@
is_hub=False,
services=units.ShippingService,
options=units.ShippingOption,
connection_configs=units.ConnectionConfig,
)
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class Settings(provider_utils.Settings):
username: str
password: str
account: str = None
service_type: str = "R"

# generic properties
id: str = None
Original file line number Diff line number Diff line change
@@ -30,7 +30,11 @@ def _extract_details(
settings: provider_utils.Settings,
) -> models.RateDetails:
rate = lib.to_object(rating.ResultType, data)
service = provider_units.ShippingService.allied_standard
service = provider_units.ShippingService.map(
settings.connection_config.account_service_type.state
or settings.service_type
or "R"
)
charges = [
("Job charge", lib.to_money(rate.jobCharge)),
*((s.chargeCode, lib.to_money(s.netValue)) for s in rate.surcharges),
@@ -39,7 +43,7 @@ def _extract_details(
return models.RateDetails(
carrier_id=settings.carrier_id,
carrier_name=settings.carrier_name,
service=service.name,
service=service.name_or_key,
total_charge=lib.to_money(rate.totalCharge),
currency=units.Currency.AUD.name,
extra_charges=[
Original file line number Diff line number Diff line change
@@ -17,10 +17,17 @@ class PackagingType(lib.StrEnum):
your_packaging = PACKAGE


class ConnectionConfig(lib.Enum):
account_service_type = lib.OptionEnum("account_service_type")


class ShippingService(lib.StrEnum):
"""Carrier specific services"""

allied_standard = "R"
allied_road_service = "R"
allied_parcel_service = "P"
allied_standard_pallet_service = "PT"
allied_oversized_pallet_service = "PT2"


class ShippingOption(lib.Enum):
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ class Settings(core.Settings):
username: str
password: str
account: str = None
service_type: str = "R"

account_country_code: str = "AU"

@@ -29,6 +30,15 @@ def authorization(self):
pair = "%s:%s" % (self.username, self.password)
return base64.b64encode(pair.encode("utf-8")).decode("ascii")

@property
def connection_config(self) -> lib.units.Options:
from karrio.providers.allied_express.units import ConnectionConfig

return lib.to_connection_config(
self.config or {},
option_type=ConnectionConfig,
)


@attr.s(auto_attribs=True)
class AlliedResponse:
2 changes: 1 addition & 1 deletion modules/connectors/allied_express/setup.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

setup(
name="karrio.allied_express",
version="2023.12.1",
version="2023.12.2",
description="Karrio - Allied Express Shipping Extension",
long_description=long_description,
long_description_content_type="text/markdown",
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ def test_parse_error_response(self):
"options": {"dangerous_good": True},
},
],
"services": ["allied_standard"],
"services": ["allied_road_service"],
"options": {
"instructions": "This is just an instruction",
},
@@ -109,8 +109,8 @@ def test_parse_error_response(self):
"extra_charges": [
{"amount": 14.18, "currency": "AUD", "name": "Job charge"}
],
"meta": {"service_name": "allied_standard"},
"service": "allied_standard",
"meta": {"service_name": "allied_road_service"},
"service": "allied_road_service",
"total_charge": 40.66,
}
],
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ def test_parse_error_response(self):
"options": {"dangerous_good": True},
},
],
"service": "allied_standard",
"service": "allied_road_service",
"options": {
"instructions": "This is just an instruction",
},
2 changes: 1 addition & 1 deletion modules/core/karrio/server/core/authentication.py
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ def get_request_org(request, user, org_id: str = None, default_org=None):
orgs = Organization.objects.filter(users__id=user.id)
org = (
orgs.filter(id=org_id).first()
if org_id is not None
if org_id is not None and orgs.filter(id=org_id).exists()
else orgs.filter(is_active=True).first()
)

Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class Meta:
username = models.CharField(max_length=50)
password = models.CharField(max_length=50)
account = models.CharField(max_length=50, null=True, blank=True)
service_type = models.CharField(max_length=50, null=True, blank=True)

@property
def carrier_name(self) -> str:
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2023-12-18 20:48

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("providers", "0060_belgianpostsettings_rate_sheet_and_more"),
]

operations = [
migrations.AddField(
model_name="alliedexpresssettings",
name="service_type",
field=models.CharField(blank=True, max_length=50, null=True),
),
]
Loading

0 comments on commit e0c5d6a

Please sign in to comment.