Find only location with product stock available using proteus

34 views
Skip to first unread message

TPH

unread,
Jun 22, 2017, 8:25:05 AM6/22/17
to tryton
Hello

I try to find all location containing a product. I need this because until now I have to check every location for product stock and this takes about 30 seconds. I asked something similar 2 years ago, but only found a solution to fast get the quantity of a location if I have location name: https://groups.google.com/forum/#!searchin/tryton/proteus/tryton/JciAJE-3u9A/9BGT4HylytQJ

But I still found no fest way to get all locations with quantity of a product. So maybe first step is to get locations with quantity.

I use Tryton with Proteus 3.2 but also can use version 3.8.

What I tried is the following:

    def products_by_location(self, product_code):
       
Product = Model.get('product.product')
       
Location = Model.get('stock.location')
        product
, = Product.find([('code', '=', product_code)])
       
self.xmlrpc_config.set_context(stock_date_end = date.today())
       
self.xmlrpc_config.set_context(product=product.id)  
        locations
= Location.find([('type', '=', 'storage'), ("parent", "=", self.default_warehouse)])
        locations_with_product_stock
= [(l.name, l.quantity) for l in locations if l.quantity]



Cédric Krier

unread,
Jun 24, 2017, 6:00:07 PM6/24/17
to tryton
There is no better solution for now.
There are two points that could be improved:

- proteus: it makes a query for each location quantity read. The
performance would be improved if there were some batch processing.

- stock: a searched method could be implemented on Location.quantity
just like we have a searched on Product.quantity.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages