Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
11098 Vizualizări

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



Imagine profil
Abandonează
Autor

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

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

Cel mai bun răspuns

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.

Imagine profil
Abandonează
Autor

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.

Autor

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.

Autor

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

Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 23
2254
0
dec. 22
2903
0
iun. 21
2881
0
iun. 20
5379
1
nov. 19
2702