Products¶
Product model base implementation – you do not need to use this
It may save you some typing though.
-
class
plata.product.models.
ProductBase
(*args, **kwargs)[source] Product models must have two methods to be usable with Plata:
get_price
: Return a price instancehandle_order_item
: Fill in fields on the order item from the product, i.e. the name and the stock keeping unit.
-
get_price
(currency=None, orderitem=None)[source] This method is part of the public, required API of products. It returns either a price instance or raises a
DoesNotExist
exception.If you need more complex pricing schemes, override this method with your own implementation.
-
handle_order_item
(orderitem)[source] This method has to ensure that the information on the order item is sufficient for posteriority. Old orders should always be complete even if the products have been changed or deleted in the meantime.
Product extensions¶
Exact, transactional stock tracking for Plata¶
Follow these steps to enable this module:
Ensure your product model has an
items_in_stock
field with the following definiton:items_in_stock = models.IntegerField(default=0)
Add
'plata.product.stock'
toINSTALLED_APPS
.Set
PLATA_STOCK_TRACKING = True
to enable stock tracking in the checkout and payment processes.Optionally modify your add-to-cart forms on product detail pages to take into account
items_in_stock
.
-
class
plata.product.stock.models.
Period
(*args, **kwargs)[source] A period in which stock changes are tracked
You might want to create a new period every year and create initial amount transactions for every variation.
StockTransaction.objects.open_new_period
does this automatically.
-
class
plata.product.stock.models.
StockTransaction
(*args, **kwargs)[source] Stores stock transactions transactionally :-)
Stock transactions basically consist of a product variation reference, an amount, a type and a timestamp. The following types are available:
StockTransaction.INITIAL
: Initial amount, used when filling in the stock databaseStockTransaction.CORRECTION
: Use this for any errorsStockTransaction.PURCHASE
: Product purchase from a supplierStockTransaction.SALE
: Sales, f.e. through the webshopStockTransaction.RETURNS
: Returned products (i.e. from lending)StockTransaction.RESERVATION
: ReservationsStockTransaction.INCOMING
: Generic warehousingStockTransaction.OUTGOING
: Generic warehousingStockTransaction.PAYMENT_PROCESS_RESERVATION
: Product reservation during payment process
Most of these types do not have a significance to Plata. The exceptions are:
INITIAL
transactions are created byopen_new_period
SALE
transactions are created when orders are confirmedPAYMENT_PROCESS_RESERVATION
transactions are created by payment modules which send the user to a different domain for payment data entry (f.e. PayPal). These transactions are also special in that they are only valid for 15 minutes. After 15 minutes, other customers are able to put the product in their cart and proceed to checkout again. This time period is a security measure against customers buying products at the same time which cannot be delivered afterwards because stock isn’t available.
-
plata.product.stock.models.
validate_order_stock_available
(order)[source] Check whether enough stock is available for all selected products, taking into account payment process reservations.