14. Managing the Deliver Process

Depending on the merchant’s setup, an order can be considered as one inseparably unit, or if partial shipping shall be allowed, as a collection of single products, which can be delivered individually.

To enable partial shipping, assure that both classes shop.models.delivery.BaseDelivery and shop.models.delivery.BaseDeliveryItem are instantiated. The easiest way to do this is to import the default materialized classes into an existing model class:

from shop.models.defaults.delivery import Delivery, DeliveryItem

__all__ = ['Delivery', 'DeliveryItem']  # prevent IDE to complain about unused imports

14.1. Partial Delivery Workflow

The class implementing the Order, requires additional methods provided by the mixin shop.shipping.delivery.PartialDeliveryWorkflowMixin. Mix this into the Order class by configuring:

SHOP_ORDER_WORKFLOWS = (
    # other workflow mixins
    'shop.shipping.defaults.PartialDeliveryWorkflowMixin',
)

Note

Do not combine this mixin with shop.shipping.defaults.CommissionGoodsWorkflowMixin.

14.2. Administration Backend

To control partial delivery, add the class shop.admin.delivery.DeliveryOrderAdminMixin to the amin class class implementing an Order:

myshop/admin/order.py
from django.contrib import admin
from shop.admin.order import BaseOrderAdmin
from shop.models.defaults.order import Order
from shop.admin.delivery import DeliveryOrderAdminMixin

@admin.register(Order)
class OrderAdmin(DeliveryOrderAdminMixin, BaseOrderAdmin):
    pass

14.3. Implementation Details

When partial delivery is activated, two additional tables are added to the database, one for each delivery and one for each delivered order item. This allows us to split up the quantity of an ordered item into two or more delivery objects. This can be useful, if a product is sold out, but the merchant wants to ship whatever is available on stock. The merchant then creates a delivery object and assigns the available quantity to each linked delivery item.

If a product is not available at all anymore, the merchant can alternatively cancel that order item.