This question has been flagged
3 Replies
18438 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 ??

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Best Answer

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)

 

Avatar
Discard