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

i'am added a car field in product template which related  to the car model that contains all cars, also i'am work in multi compny, and i'am also added a many2many relation with car model, 
all i need is to filter the cars in product template and display all cars that i have been assign in the company  

this my code 


class cars(models.Model):
_name = 'cars'

name = fields.Char( string="Car",translate=True , required=True, ondelete='restrict')
class autopartscompany(models.Model):
_inherit = 'res.company'

car_ids = fields.Many2many(comodel_name="cars",string="Cars" )
class autopart(models.Model):
_inherit = 'product.template'
car = fields.Many2one(comodel_name="cars", store=True, string="Car", ondelete='restrict', required=False, domain="[('name','=', self.company_id.car_ids )]")
can any one help me how to define the domain filter correctly because that one give me error  Error: NameError: name 'self' is not defined
الصورة الرمزية
إهمال
أفضل إجابة

Hi Mohamed,

Go with the below defined domain code

def _get_cars_domain(self):
return [('id', 'in', self.company_id.car_ids.ids)]

car = fields.Many2one(comodel_name="cars", store=True, string="Car", ondelete='restrict', required=False, domain=_get_cars_domain)

Thanks.

الصورة الرمزية
إهمال
الكاتب

thanks dear for your help but it dosn't return any result

Check this -->

def _get_cars_domain(self):

return [('id', 'in', self.env.user.company_id.car_ids.ids)]

Thanks

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أغسطس 20
3451
1
يوليو 19
6583
0
أبريل 22
6201
0
فبراير 25
18
1
نوفمبر 19
4029