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

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
2325
0
12月 22
2949
0
6月 21
2899
0
6月 20
5410
1
11月 19
2737