Odoo Help

1

Need help on search_count() funtion.

By
Gopalakrishnan Kasilingam
on 2/2/15, 7:19 AM 3,835 views

#field in the model "stock":

damaged_books=fields.Integer(compute='find_damage')

#code to get the count of damaged books(field name "status") from the model "bookinfo":

@api.depends()
def find_damage(self):
count=self.env['bookinfo.status'].search_count([('status','=','damage')])

self.damaged_books=count

The above code shows nothing, is there any wrong with the syntax or with the logic ??

1
Ivan
On 2/2/15, 8:26 PM

You have to set self.damaged_books = count in the method.

1

Thanks for your answer ivan, i tried the following code instead of the above it works fine. res=self.env['bookinfo'].search([])

a=0

for x in res: if(x.status=='damage'):

a=a+1

self.damaged_books=a

0
deep
On 2/3/15, 3:05 AM

In Odoo.

read(), search_count() methods on Environment objects are has been removed, hence you can't use such methods...
 

hence your rewritten code is also fine

OR you can rewrite it like this

self.damaged_books = len(self.env['bookinfo.status'].search([('status','=','damage')])._ids)

 

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 2/2/15, 7:19 AM
Seen: 3835 times
Last updated: 3/16/15, 8:10 AM