Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
19889 Представления

#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 ??

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор Лучший ответ

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

Аватар
Отменить
Лучший ответ

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)

 

Аватар
Отменить