Gopalakrishnan Cassie
Gopalakrishnan Cassie

Reputation: 29

Need help on search_count() function in odoo

i'm creating a sample module like library management, and int that having a "stock" model i would like to get the count of the damaged books number from overall books in the library(e.g status of books are damaged, lended etc) i would like to get the count of the books that are in damaged condition from the model named "bookinfo" i tried the below code but no issues . plz help on this.

field in the model "stock":

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

code to get the count of damaged books from the model "bookinfo":

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

Upvotes: 1

Views: 8127

Answers (1)

Hardik Patadia
Hardik Patadia

Reputation: 1999

Try following:

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

Here I don't think you need to add the watch on any field so you don't need to use "@api.depends". It is used when you want to keep watch on other fields to calculate the field and store the values in database.

Upvotes: 2

Related Questions