Skip to content

Commit

Permalink
(add) connection configs and update dashboard connection config modal
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Dec 18, 2023
1 parent ef6075c commit c22bce8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -30,7 +30,9 @@ def _extract_details(
settings: provider_utils.Settings,
) -> models.RateDetails:
rate = lib.to_object(rating.ResultType, data)
service = provider_units.ShippingService.map(settings.service_type or "R")
service = provider_units.ShippingService.map(
settings.connection_config.account_service_type 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ 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"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,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:
Expand Down
2 changes: 1 addition & 1 deletion modules/core/karrio/server/core/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down
32 changes: 31 additions & 1 deletion packages/ui/modals/connect-provider-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@ export const ConnectProviderModal: React.FC<ConnectProviderModalComponent> = ({
required={field("account").required}
/>}

{field("service_type").exists &&
<SelectField value={payload.service_type}
name="service_type"
label="Service type"
onChange={handleChange}
className="is-small is-fullwidth"
required={field("service_type").required}
>
{!field("service_type").required && <option value='none'></option>}
<option value={`R`}>{`Road service - R`}</option>
<option value={`P`}>{`Road service - P`}</option>
<option value={`PT`}>{`Road service - PT`}</option>
<option value={`PT2`}>{`Road service - PT2`}</option>
</SelectField>}

{field("billing_account").exists && <InputField label="Billing Account" value={payload.billing_account}
name="billing_account"
onChange={handleChange}
Expand Down Expand Up @@ -639,6 +654,21 @@ export const ConnectProviderModal: React.FC<ConnectProviderModalComponent> = ({
className="is-small is-fullwidth"
/>}

{"account_service_type" in connection_configs[carrier_name.toString()] &&
<SelectField value={payload.config?.account_service_type}
name="account_service_type"
label="Account service type"
onChange={handleConfigChange}
className="is-small is-fullwidth"
fieldClass="column is-6 mb-0"
>
<option value='none'></option>
<option value={`R`}>{`Road service - R`}</option>
<option value={`P`}>{`Road service - P`}</option>
<option value={`PT`}>{`Road service - PT`}</option>
<option value={`PT2`}>{`Road service - PT2`}</option>
</SelectField>}

{"shipping_services" in connection_configs[carrier_name.toString()] &&
<SelectField defaultValue={payload.config?.shipping_services}
name="shipping_services"
Expand Down Expand Up @@ -729,7 +759,7 @@ export const ConnectProviderModal: React.FC<ConnectProviderModalComponent> = ({
function fieldState(carrier_name: CarrierNameType, property: string) {
const field = (
({
[CarrierSettingsCarrierNameEnum.AlliedExpress]: [["carrier_id", true], ["username", true], ["password", true], ["account", false]],
[CarrierSettingsCarrierNameEnum.AlliedExpress]: [["carrier_id", true], ["username", true], ["password", true], ["account", false], ["service_type", false]],
[CarrierSettingsCarrierNameEnum.AmazonShipping]: [["carrier_id", true], ["seller_id", true], ["developer_id", true], ["mws_auth_token", true], ["aws_region"]],
[CarrierSettingsCarrierNameEnum.Aramex]: [["carrier_id", true], ["username", true], ["password", true], ["account_pin", true], ["account_entity", true], ["account_number", true], ["account_country_code"]],
[CarrierSettingsCarrierNameEnum.Australiapost]: [["carrier_id", true], ["api_key", true], ["password", true], ["account_number", true]],
Expand Down

0 comments on commit c22bce8

Please sign in to comment.