Skip to content

Commit

Permalink
Core: add attribute in Carrier model to control whether to manage shi…
Browse files Browse the repository at this point in the history
…pments using default behavior
  • Loading branch information
chessbr committed Mar 15, 2021
1 parent 8f2b58d commit b6c3c3e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ List all changes after the last release here (newer on top). Each change on a se

### Added

- Core: add attribute in Carrier model to control whether to manage shipments using default behavior
- Admin: add shipment list view to list all shipments

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions shuup/admin/modules/orders/sections.py
Expand Up @@ -69,6 +69,10 @@ class ShipmentSection(Section):

@staticmethod
def visible_for_object(order, request=None):
if not order.shipping_method:
return False
if not order.shipping_method.carrier.uses_default_shipments_manager:
return False
return (
order.has_products_requiring_shipment() or
Shipment.objects.all_except_deleted().filter(order=order).exists()
Expand Down
34 changes: 19 additions & 15 deletions shuup/admin/modules/orders/views/shipment.py
Expand Up @@ -254,34 +254,38 @@ def get_order(self, instance):
return str(instance.order)

def get_content(self, instance):
shipment_products = ShipmentProduct.objects.filter(shipment=instance)
content = ""
shipment_products = ShipmentProduct.objects.filter(shipment=instance).select_related(
"product", "product__sales_unit"
)
content = []

for shipment_product in shipment_products:
unit = UnitInterface(shipment_product.product.sales_unit)
quantity = unit.render_quantity(shipment_product.quantity)
content += f"{shipment_product.product} ({quantity})"

return content
content.append(f"{shipment_product.product} ({quantity})")
return ", ".join(content)

def create_action_buttons(self, instance):
if instance.status not in (ShipmentStatus.SENT, ShipmentStatus.ERROR):
url = "{base_url}?next={next_url}".format(
base_url=reverse("shuup_admin:order.set-shipment-sent", kwargs={"pk": instance.pk}),
next_url=reverse('shuup_admin:order.shipments.list')
)
return render_to_string("shuup/admin/orders/_set_shipments_status_button.jinja", {
"shipment_id": instance.pk,
"url": url,
})
if instance.order.shipping_method and instance.order.shipping_method.carrier.uses_default_shipments_manager:
if instance.status not in (ShipmentStatus.SENT, ShipmentStatus.ERROR):
url = "{base_url}?next={next_url}".format(
base_url=reverse("shuup_admin:order.set-shipment-sent", kwargs={"pk": instance.pk}),
next_url=reverse('shuup_admin:order.shipments.list')
)
return render_to_string("shuup/admin/orders/_set_shipments_status_button.jinja", {
"shipment_id": instance.pk,
"url": url,
})
return instance.status.label

def __init__(self):
super().__init__()
self.columns = self.default_columns

def get_queryset(self):
queryset = super().get_queryset().exclude(status=ShipmentStatus.DELETED)
queryset = super().get_queryset().exclude(status=ShipmentStatus.DELETED).select_related(
"order", "order__shipping_method"
)
supplier = get_supplier(self.request)
if supplier:
queryset = queryset.filter(supplier=supplier)
Expand Down
4 changes: 4 additions & 0 deletions shuup/core/models/_service_shipping.py
Expand Up @@ -80,6 +80,10 @@ class Carrier(ServiceProvider):
rather through a concrete subclass.
"""

# Flags whether the order shipments should be managed
# by the default shipment section.
uses_default_shipments_manager = True

service_model = ShippingMethod

def delete(self, *args, **kwargs):
Expand Down

0 comments on commit b6c3c3e

Please sign in to comment.