Orders

Orders reference.

Models

class salesman.orders.models.ParentalForeignKey(*args, **kwargs)[source]

Use this foreign key to add support for Wagtail in case modelcluster is installed.

class salesman.orders.models.Order(*args: Any, **kwargs: Any)[source]

Model that can be swapped by overriding SALESMAN_ORDER_MODEL setting.

exception DoesNotExist
exception MultipleObjectsReturned
class salesman.orders.models.OrderItem(*args: Any, **kwargs: Any)[source]

Model that can be swapped by overriding SALESMAN_ORDER_ITEM_MODEL setting.

exception DoesNotExist
exception MultipleObjectsReturned
class salesman.orders.models.OrderPayment(*args, **kwargs)[source]

Model that can be swapped by overriding SALESMAN_ORDER_PAYMENT_MODEL setting.

exception DoesNotExist
exception MultipleObjectsReturned
class salesman.orders.models.OrderNote(*args, **kwargs)[source]

Model that can be swapped by overriding SALESMAN_ORDER_NOTE_MODEL setting.

exception DoesNotExist
exception MultipleObjectsReturned

Serializers

class salesman.orders.serializers.OrderItemSerializer(*args, **kwargs)[source]

Serializer for order item.

class salesman.orders.serializers.OrderPaymentSerializer(*args, **kwargs)[source]

Serializer for order payment.

class salesman.orders.serializers.OrderNoteSerializer(*args, **kwargs)[source]

Serializer for order note.

class salesman.orders.serializers.OrderSerializer(*args, **kwargs)[source]

Serializer for order.

class salesman.orders.serializers.StatusTransitionSerializer(*args, **kwargs)[source]

Serializer to display order status with error.

to_representation(status: str) Any[source]

Object instance -> Dict of primitive datatypes.

class salesman.orders.serializers.OrderStatusSerializer(*args, **kwargs)[source]

Serializer used to change order status.

to_representation(instance: salesman.orders.models.BaseOrder) Any[source]

Object instance -> Dict of primitive datatypes.

class salesman.orders.serializers.OrderPaySerializer(*args, **kwargs)[source]

Serializer used to pay for existing order via payment method.

class salesman.orders.serializers.OrderRefundSerializer(*args, **kwargs)[source]

Serializer used to issue an order refund.

Signals

Status

class salesman.orders.status.BaseOrderStatus(value)[source]

Base order status enum, actuall choices must extend this class.

classmethod get_payable() list[str][source]

Returns list of statuses from which an order is eligible for payment.

classmethod get_transitions() dict[str, list[str]][source]

Returns a dict of statuses with their transitions. If not specified for status, any transition is valid.

classmethod validate_transition(status: str, order: BaseOrder) str[source]

Validate a given status transition for the order. By default check status is defined in transitions.

Parameters
  • status (str) – New status

  • order (Order) – Order instance

Raises

ValidationError – If transition not valid

Returns

Validated status

Return type

str

class salesman.orders.status.OrderStatus(value)[source]

Default order choices enum. Can be overriden by providing a dotted path to a class in SALESMAN_ORDER_STATUS setting. Required choices are NEW, CREATED, COMPLETED and REFUNDED.

Utils

salesman.orders.utils.generate_ref(request: django.http.request.HttpRequest) str[source]

Default order reference generator function. Can be overriden by providing a dotted path to a function in SALESMAN_ORDER_REFERENCE_GENERATOR setting.

Default format is {year}-{5-digit-increment} (eg. 2020-00001).

Parameters

request (HttpRequest) – Django request

Returns

New order reference

Return type

str

Views

class salesman.orders.views.OrderViewSet(**kwargs)[source]

Orders API endpoint.

serializer_class

alias of salesman.orders.serializers.OrderSerializer

get_queryset() django.db.models.query.QuerySet[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

optimize_queryset(queryset: django.db.models.query.QuerySet) django.db.models.query.QuerySet[source]

Extract fields for pre-fetching from order serializer and apply to queryset.

get_object() salesman.orders.models.BaseOrder[source]

Returns the object the view is displaying.

You may want to override this if you need to provide non-standard queryset lookups. Eg if objects are referenced using multiple keyword arguments in the url conf.

get_serializer_class() type[BaseSerializer][source]

Return the class to use for the serializer. Defaults to using self.serializer_class.

You may want to override this if you need to provide different serializations depending on the incoming request.

(Eg. admins get full serialization, others get basic serialization)

get_serializer_context() dict[str, Any][source]

Extra context provided to the serializer class.

dispatch(request: django.http.request.HttpRequest, *args: Any, **kwargs: Any) django.http.response.HttpResponseBase[source]

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

last(request: rest_framework.request.Request) rest_framework.response.Response[source]

Show last customer order.

all(request: rest_framework.request.Request) rest_framework.response.Response[source]

Show all orders to the admin user.

status(request: rest_framework.request.Request, ref: str) rest_framework.response.Response[source]

Change order status. Available only to admin user.

pay(request: rest_framework.request.Request, ref: str) rest_framework.response.Response[source]

Pay for order.

refund(request: rest_framework.request.Request, ref: str) rest_framework.response.Response[source]

Refund all order payments.