跳至內容
選單
此問題已被標幟
1 回覆
10653 瀏覽次數

In v8, I have a related Many2many field "A".

And I have a Many2one field "B".

Field B should only show the records available in A. (It is just to choose one record from A that will be default for other things)

How can I do this in a view, and having in mind A can change?

頭像
捨棄
最佳答案

try this:

domain="[('id', 'in', many2many_field[0][2])]"

頭像
捨棄
作者

Thanks, Yogesh, this solved my problem. Two questions arise: What do the [0][2] mean? And where is it documented?

Anubia, I doubt if it is documented somewhere, but it works because m2m field is computed as list of a tuple containing ids of records on 2nd index of tuple eg [(0,0,[ids_of_records])], so field_name[0][2] extracts list of ids.

作者

Hello, again. It is working for me in xml view file. But in python is not working. How do I get the ids from a One2many or Many2many in python code? Doing ids = myobject.one2many_field, fails. Doing ids = myobject.one2many_field[0][2] fails. Always complins about expecting singleton.

line_ids = [] for line in one2many: line_ids.append(line.id) print "all ids of one2many record", line_ids # same way you can get for many2many

作者

It fails anyway when I do "for line in one2many:". I have this: zone_ids = fields.One2many( comodel_name='base.zone', inverse_name='zip_ids', string='Zones', relation='base_zone_zip_rel', ) @api.one def get_zone_ids(self): ids = [] for rec in self.zone_ids: #

作者

OK, solved, the problem was I was relating a One2many with a Many2many. Changed to be Many2many both and working perfectly.

相關帖文 回覆 瀏覽次數 活動
1
2月 24
12823
1
10月 21
5629
3
3月 15
10359
0
11月 22
80
5
10月 22
13870