跳至内容
菜单
此问题已终结

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

相关帖文 回复 查看 活动
2
3月 25
2992
1
9月 23
3100
2
3月 24
2804
2
5月 23
197
1
1月 18
8544