On 2017-06-22 04:49, TPH wrote:
> 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]


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: [email protected]
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/20170624215816.GH3590%40kei.

Reply via email to