I have 1500+ products and 2000+ locations. I have updated the inventory with update inventory wizard in products and also I have processed some delivery orders and internal moves. Now I want to zero out the inventory. I made a script to zero out the inventory. The problem is that it takes too much time to update the inventory to zero as each product can be any where in 2000 locations. Is there any OpenERP function which will return all locations that a product is available?
1 Answers
Context
To keep the data model simple (KISS) and avoid issues with cache invalidation, OpenERP does not keep a cache of the current inventory of products in each location. This information is obtained by computing the double-entry balance of stock transactions entering and leaving each stock location. This is very similar to the double-entry bookkeeping used for financial accounting.
Option 1: using the API
There are several ways to obtain this information programmatically using the OpenERP API, by querying the stock.move
model for each stock.location
. For starters you can have a look at the stock.fill.inventory
wizard class of the stock
module, which has an option to fill in the physical inventory with zeroed lines. The product.product
model also has a get_product_available
method that returns this information for a given set of products.
Then you can create the appropriate counterpart stock.move
entries to achieve a balance of 0 in each location, in a way that is very similar to what the standard stock.fill.inventory
wizard does.
Option 2: wipe out using direct SQL
Alternatively, if you simply want to erase the whole inventory along with its history as a one-shot operation, there is a fast and dirty way. You can do it using a direct SQL query on the database (e.g. using the psql
command-line tool or pgadmin), simply wiping out the stock_move
and stock_picking
tables.
DON'T do this on a production database with real data! This will WIPE OUT a part of your database
Assuming you have installed the Sale Management module (sale
) and are using OpenERP 6.1, the following should work to erase the history of stock transactions and the documents their originated from:
Oh, and make a backup first!
DELETE FROM stock_move; DELETE FROM mrp_production; DELETE FROM stock_picking; DELETE FROM sale_order; DELETE FROM procurement_order;