Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 3.15 KB

order_customization.rst

File metadata and controls

76 lines (52 loc) · 3.15 KB

Order customization

This page documents different order customization methods.

Custom statuses

Order statuses are defined using django's django.db.models.TextChoices enum class with the default set to salesman.orders.status.OrderStatus class.

You can change it by providing a dotted path in SALESMAN_ORDER_STATUS setting that points to a class extending salesman.orders.status.BaseOrderStatus class.

/../salesman/orders/status.py

As seen in the default status class above, you must define statuses with names and values NEW, CREATED, COMPLETED and REFUNDED while others are customizable to your needs.

You can also optionally override salesman.orders.status.BaseOrderStatus.get_payable method that returns a list of statuses from which an order is eligible for payment, and salesman.orders.status.BaseOrderStatus.get_transitions method which limits status transitions for an order.

Order Status enum can be access using salesman.orders.models.BaseOrder.Status class property.

Validate status transitions

You might want to validate certain status transitions for your orders. This is possible by overriding the salesman.orders.status.BaseOrderStatus.validate_transition method.

Tip

Eg. you could enforce a check that the order has been fully paid for before it can be marked as Completed, or even return and force a different status entirely.

A default status transition validation is provided with salesman.orders.status.BaseOrderStatus class which checks that transition is available for the current order status:

/../salesman/orders/status.py

Note

To include base validation be sure to call super() when overriding validation.

Custom reference generator

Order reference is generated when a new order get's created and represents a unique identifier for that order. By default reference is generated in a {year}-{5-digit-increment} format using salesman.orders.utils.generate_ref function.

You can change it by providing a dotted path in SALESMAN_ORDER_REFERENCE_GENERATOR setting that points to a function that returns a unique reference string.

/../salesman/orders/utils.py

Your custom function should accept Django's request object as a parameter.

Custom order serializer

You can override order serializer by providing a dotted path in SALESMAN_ORDER_SERIALIZER setting. Optionally you can configure a separate order "summary" serializer with SALESMAN_ORDER_SUMMARY_SERIALIZER setting, otherwise the same order serializer is used. Default serializer for is set to salesman.orders.serializers.OrderSerializer.

You can also override the prefetch_related_fields and select_related_fields in OrderSerializer.Meta properties to optimize for any added relations to your custom serializer.