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

I am trying to use a method to return my domain. Any advice?

Not working this way.

The client_id and client_id.id both return integers. When I hard code an example such as 

domain="[('client_id.id','=', 5)]"

Everything works. I think it is an encoding thing or formatting issue of what I am returning. 

#################################

#################################

@api.model

def _getClientId(self):

    client_id = self.client_id.id

    domain = "[('client_id.id','='," + " " + str(client_id) + ")]"

    return domain

selected_review = fields.Many2one('something.something', domain=_getClientId)

Ảnh đại diện
Huỷ bỏ

The last character ) in domain=... is probably redundant?

Tác giả

You are right. That may have been a residual typo. Thank you for letting me know. I turned out to be the id's I was using were not the correct ones.

Tác giả Câu trả lời hay nhất

Alright. So here is what worked for me in the end. 

#####################

@api.model

def _getClientId(self):

    if len(self.search_read([],[])) == 0:

        return [('client_id','=','client_id')]

    else:

        client_id = self.search_read([],['id'])[0].get('id')

        domain = "[('client_id','='," + " " + str(client_id) + ")]"

        return domain

selected_review = fields.Many2one('sentry.review',

domain=_getClientId,

string="Selected Review")

####################################

The issue is that I was referring to the wrong id.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 21
66
0
thg 8 16
4381
1
thg 4 16
5471
2
thg 2 25
6040
1
thg 12 24
1555