Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
19941 Ansichten

#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
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
Autor Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen