Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
20702 Lượt xem

Here's my model :

 from openerp import models, fields, api, tools

class Searches(models.Model):

	_name = 'user.search'

	search = fields.Char('Searches made by users',required=True)

	nb_searches = fields.Integer('Number of searches for this phrase',required=True)

	def a_function(sef,cr,uid,context=None):
		return None


And when I try to search in it :

self.search(cr, uid, []) 

I've got the following error :

AttributeError: 'user.search' object has no attribute '_ids'

What's wrong ? The user_search table have an 'id' attribute ... I don't what what I did wrong.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I've found the answer :

I had put a field called 'search' like this :

search = fields.Char(....)

And it seams that Odoo doesn't really apreciate that we call a field 'search', I changed it by 'search_sentence' and it worked perfectly.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Reference: https://github.com/nbessi/odoo_new_api_guideline/blob/master/source/environment.rst

Now  Seach function returns directly a RecordSet:

  ids = self.search([])  


You can do a search using env:

self.env['user.search'].search([]) 
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 19
4932
3
thg 4 23
11982
0
thg 12 24
1409
2
thg 7 24
2202
1
thg 3 24
2448