تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5157 أدوات العرض

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 25
2984
1
سبتمبر 23
3090
2
مارس 24
2799
2
مايو 23
197
1
يناير 18
8538