跳至内容
菜单
此问题已终结
4 回复
11105 查看

tried many different ways yet couldn't find any solution so far. checked all source code hoping to find an example yet nothing.

here is what I am trying to do:

food and ingredients ( aka nutrient ). ingredients must be selected once and not shown twice in drop-down.


i can control with domain to filter for first selection. no problem.

when adding another nutrient. (in the background) 'Vitamin A' is already on the list and that should be left out.

any idea how to achieve it ? keep in mind that record is still on create mode. nothing in db yet.

thanks,


note: many2one and one2many widgets are able to do this filtering but not drop-downs



形象
丢弃
编写者

Nikhil, thanks for the hint. that helped a lot. solved the problem.

can't convert your comment as answer, not having enough karma points.

最佳答案

I think Using python we can set a manual domain for the Nutrient field and achieve your requirement.

return like this

return {

'domain': {'field': [('********_ids', '!=', selected_ids)]},

}

selected ids first find by search and try.

形象
丢弃
编写者

Nikhil, this one works when using save&close button without any problem. but save&new button is totally problem. do you have any idea? thank you.

When you click save & new it runs the onchange function, I think that function makes the issue, you just post the issue and code too, then only we can find or suggest the issue.

编写者

actually it doesn't trigger onchange function for group/nutrient. it triggers the onchange function for values (many2one). i altered the context to pass selections in between but in current mode, contexts are different for values and group/nutrient on onchage functions.

编写者

well, things got complicated so hid that button with css for now. i ll look into it later.

编写者 最佳答案

final result:

<page string="Ingredients">
<field name="values" context="{'values': values}">
...



def onchange_group_id(self, cr, uid, ids, group_id, context=None):
if not group_id:
return {'value': {'group_id': False, 'nutrient_id': False}}

# how to improve here ??

exclude = []
if context and 'values' in context:
for ntr in context['values']:
if len(ntr) >= 2:
exclude.append(ntr[1])

result = {'value': {'group_id': group_id, 'nutrient_id': False}}

if len(exclude) > 0:
# id -> nutrient_id.
result.update({'domain': {'nutrient_id': [('id', 'not in', exclude)]}})

return result
形象
丢弃
相关帖文 回复 查看 活动
1
3月 23
2275
0
12月 22
2912
0
6月 21
2882
0
6月 20
5390
1
11月 19
2711