Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
5525 Представления

Odoo16
I'm trying to set a domain for warehouse_ids  field that exist in sale.order.line model
the domain depends on the selected values of allowed_locations field that is exist in res.users model

this is the code but it doesn't work

@api.depends('self.env.user.allowed_locations')
def domain(self):
user = self.env.user
locations_domain = []
for loc_id in user.allowed_locations:
locations_domain.append(loc_id.id)
print (loc_id.id)
return {'domain': {'warehouse_ids': [('id', 'in', locations_domain)]}}
warehouse_ids = fields.Many2one('stock.location',string="Warehouse ")


Аватар
Отменить
Лучший ответ
def _get_warehouse_domain(self):
​return [('id', 'in', self.env.user.allowed_locations.ids)]
warehouse_ids = fields.Many2one('stock.location', string="Warehouse", domain=_get_warehouse_domain)
Аватар
Отменить
Автор

Thanks very much
it works correctely after i added your code

Лучший ответ

Domain based on some another field

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
мар. 25
3422
1
сент. 23
3347
2
мар. 24
3141
2
мая 23
197
1
янв. 18
8921