Comment 0 for bug 899470

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : [6.0 TRUNK][STOCK] opening menu location take 45 seconds...

Hi all
Everything is in the title ;)
When I open the menu location form warehouse=>configuration=>warehouse management=>location
OpenERP need 45 second (on a core i5) to open the menu, python process run at 100% :(

The problem is really easy to understand. Let's explain.

First mistake:
The view "view_location_tree2" in stock_view add the field stock_real and stock_virtual

        <record id="view_location_tree2" model="ir.ui.view">
            <field name="name">stock.location.tree</field>
            <field name="model">stock.location</field>
            <field name="type">tree</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <tree string="Stock Location" colors="blue:usage=='view';darkred:usage=='internal'">
                    <field name="complete_name"/>
                    <field name="usage"/>
                    <field name="stock_real" invisible="'product_id' not in context"/>
                    <field name="stock_virtual" invisible="'product_id' not in context"/>
                </tree>
            </field>
        </record>

In this case we don't need it and so we make it invisible. But making invisible the field will not remove it from the view and we still need to compute them. In this case computing the stock level of the location is useless and long (45s for 4000 product)

Second mistake:
Using browse method on the object product in the function 'get_product_available' (file : stock/product.py) should be not use. Why?
Because we pretch all field with browse method and when you customer have 4000 products translated this is meant that in order to compute the stock level you are going to read the translation of the sale description of all of your product (yes you read it)

I just apply an ugly path to test it

+ uom_ids=[]
         product2uom = {}
- for product in self.browse(cr, uid, ids, context=context):
- product2uom[product.id] = product.uom_id.id
- uoms_o[product.uom_id.id] = product.uom_id
+ for product in self.read(cr, uid, ids, ['uom_id'], context=context):
+ product2uom[product['id']] = product['uom_id'][0]
+ if not product['uom_id'][0] in uom_ids : uom_ids.append(product['uom_id'][0])
+ print 'uom_ids', uom_ids

+ for uom in self.pool.get('product.uom').browse(cr, uid, uom_ids, context=context):
+ uoms_o[uom.id] = uom
+

Just replacing the browse method by a read method and then I was able to open my menu in less than 2 seconds.
This is meant that computing stock level can be done 22x faster when you have translated contain!! (great news, no?)

Exactly the problem is not the browse method because it's cleaner to use browse in the code ;). The huge problem is that browse method do not support field restriction, I mean we can not just apply a browse on specific field as we can do with the read method.

To finish If I remove the two field stock_real and stock_virtual from the tree view opening the menu is instantaneous.

Hope my explication is clear. We should really fix this issue.
Reading the translation of the sale description for computing the stock is not clean at all ;).

Have a nice day everyone

Also I send an email to support team with LP link, my customer have an OPW