This question has been flagged
1 Reply
3862 Views

I am trying to get the sum() saled quantity of a product. For that i write the below query.

out=self.cr.execute(
            """select sum(product_uom_qty) from sale_order_line where product_id=%d and state=%s"""
            %(product_id.id,'done'))

Ther is more than ten sales orders which are there in done state.

product_id is the browse record of product. But it's return None. Can any one tell me how can i get sum of saled quantity of product.

Avatar
Discard

@samba can you post little bit more code, which may help to find the issue. You can try one thing instead of %d, let it be %s, it will not affect your code.

Best Answer

hmm... maybe you should try something like...

self.cr.execute("some querry...")
res = cr.fetchall()

in your case out is only a querry, but you didn't fetch any data ...

also.. check this answer 
https://www.odoo.com/forum/help-1/question/how-to-use-cr-execute-to-perform-valid-sql-queries-70200
basicaly.. the same explanation...

Avatar
Discard
Author

Thank you Bole, working fine..