Odoo Help

Welcome!

This community 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.

1

Need help on search_count() funtion.

By
Gopalakrishnan Kasilingam
on 2/2/15, 7:19 AM 2,260 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

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
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

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

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)

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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