I was trying to get all the price from a pricelist by execute read to product.pricelist.item . From this read result, I got the product id and then I execute another read to product.template to get the qty_available. This can be done correctly but the performance is slow when the pricelist got 60 products , it took more than 10 seconds to complete the result. Do you have any suggestion to improve the performance? Thanks in advance, below is the code I wrote :
$ids = $models->execute_kw($db, $uid, $password,
'product.pricelist', 'search_read',
array(array(array('id', '=', $_SESSION['pricelist_id']))),
array('fields'=>array('id','name','display_name', 'item_ids', 'company_id'))
) ;
$result = $models->execute_kw($db, $uid, $password,
'product.pricelist.item', 'read',
array($ids[0]['item_ids']),
array('fields'=>array('id','name','display_name', 'product_tmpl_id', 'compute_price', 'fixed_price', 'product_id', 'categ_id', 'pricelist_id', 'currency_id'))) ;
foreach($result as $product){
$prod_result = $models->execute_kw($db, $uid, $password,
'product.template', 'read',
array($product[product_tmpl_id][0]),
array('fields'=>array('default_code', 'qty_available','categ_id'))) ;
}
Hey Gary Kam,
As its going to check so many things (Security etc.) so but obvious it will take time,
But one tricks you can do ,
-> use sql queries wherever possible (e.g to fetch pricelist mostly.) it will boost up your performance Surely !.
Thanks.
Gary Kam
Dipak Shah <dipssah@gmail.com> 於 2018年1月23日 14:09 寫道:
Hey Gary Kam,
Simple query is like -> self.env.cr.execute("<yoursql>")
Moreover you can refer these links,
http://www.odoo.gotodoo.com/odoo-sql-query-tips/
https://www.odoo.com/forum/help-1/question/how-to-do-a-sql-query-in-odoo-10-119605
Thanks
Hi Gary,
in addition you can refer below to which is much helpful to you,
https://wiki.postgresql.org/wiki/Psycopg2_Tutorial
https://gis.stackexchange.com/questions/91443/how-to-execute-sql-lines-in-postgresql-using-python
Thank you.