Sammy J
Sammy J

Reputation: 1066

How to perform stock updation process in Django Oscar

I was going through the code for the stock record model here, and above the num_allocated field it says in the comment,

#: The amount of stock allocated to orders but not fed back to the master
#: stock system.  A typical stock update process will set the num_in_stock
#: variable to a new value and reset num_allocated to zero

So, how do I do the stock update process as specified in the comment when the product is out of stock?I need to set the num_in_stock variable to new value and set the num_allocated to zero.

So far if the order is being shipped, I call the consume_stock_allocations() method in the EventHandler Class and the num in stock for the products in the order is being reduced.

If someone has implemented this please do share some code or some example as I am new to oscar.

Upvotes: 4

Views: 1077

Answers (1)

solarissmoke
solarissmoke

Reputation: 31474

For the num_allocated, the most common way to address that is to either consume

EventHandler().consume_stock_allocations(order, [lines], [line_quantities])

or cancel

EventHandler().cancel_stock_allocations(order, [lines], [line_quantities])

allocations whenever an order is dispatched or cancelled. Doing this in a shipping event handler as you are doing is perfectly fine.

This will clear the allocation and reduce the num_in_stock by the same amount as the allocation (for consumptions, not cancellations) - i.e., you do not need to do anything more to adjust num_in_stock.

What you do need to do is to keep num_in_stock updated whenever new stock arrives etc. How you do this really depends on how you manage stock on your site - e.g., if you are fetching stock information from a third party ERP system, then you would reset the num_in_stock every time you synchronise with the ERP. If you are managing inventory manually then you would just update from the dashboard.

Upvotes: 7

Related Questions