Get quantity of multiple products at once - proteus

Right now to get the list of products along with their quantities I use:

ProductsByLocation = Model.get('stock.products_by_locations')
with config.set_context ( locations = [warehouse.id] ): 
    products = ProductsByLocation.find('')
for product in products: print(product.quantity)

However, I have two issues:

  • Looping over products and executing product.quantity for each product is pretty slow. In the client, it happens pretty quickly. How can I read the quantities faster?
  • How can I set the ‘At Date’ in proteus like in the client (for Products by Locations)?

Any solution must also be usable for calculating cost_value for the products.

PS. Searching for products and getting quantity or cost_value is equally slow, since it’s done one by one over a loop.

Hi,

You can try using the “low_level” read method directly.

Product.read([x.id for x in products], ['quantity', 'cost_value'], conf._context)

proteus does not do batch reading even for record instantiated from the same search.
It does not have the group mechanism that other clients have but it could be a nice addition as more and more people are using it as production tool.
https://bugs.tryton.org/issue2723

@JCavallo Yes, that’s much faster. But how to set the ‘At Date’?

I do not know this particular module, but it probably is doable by setting the appropriate key in the context when calling read

Edit: typo

It is the context key: stock_date_end.

1 Like