Skip to content

Commit

Permalink
refactor: carrier proxies to only be generated for django admin and p…
Browse files Browse the repository at this point in the history
…revent migration requirement
  • Loading branch information
danh91 committed Aug 20, 2024
1 parent db5e59a commit 6889a82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
3 changes: 2 additions & 1 deletion modules/core/karrio/server/providers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,6 @@ def has_module_permission(self, request):
return False


for carrier_name, proxy in providers.CARRIER_PROXIES.items():
for carrier_name, display_name in ref.collect_references()["carriers"].items():
proxy = providers.create_carrier_proxy(carrier_name, display_name)
admin.site.register(proxy, model_admin(carrier_name, proxy))
2 changes: 1 addition & 1 deletion modules/core/karrio/server/providers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
WEIGHT_UNITS,
DIMENSION_UNITS,
CAPABILITIES_CHOICES,
CARRIER_PROXIES,
create_carrier_proxy,
)
import karrio.server.providers.extension.models as extensions

Expand Down
7 changes: 0 additions & 7 deletions modules/core/karrio/server/providers/models/carrier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing
import functools
from django import dispatch
import django.conf as conf
import django.forms as forms
import django.db.models as models
Expand Down Expand Up @@ -307,9 +306,3 @@ def get_queryset(self):
"system_carriers": _SystemCarrierManager(),
},
)


CARRIER_PROXIES = {
f"{carrier_name}": create_carrier_proxy(carrier_name, display_name)
for carrier_name, display_name in ref.collect_references()["carriers"].items()
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,11 @@ def create_shipment_tracker(shipment: typing.Optional[models.Shipment], context)
if (
rate_provider != shipment.carrier_name
) and rate_provider in dataunits.CARRIER_NAMES:
carrier = providers.CARRIER_PROXIES[rate_provider].access_by(context).first()
carrier = (
providers.Carrier.access_by(context)
.filter(carrier_code=rate_provider)
.first()
)

# Handle hub extension tracking
if shipment.selected_rate_carrier.gateway.is_hub and carrier is None:
Expand Down

0 comments on commit 6889a82

Please sign in to comment.