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

i made a model it called part number as examble it contains the part number as name field and car and model fields, also in product.template view i'am added thos tow fields car and model and a button with method to print the part number which contins the same self car and model it's works well but it givs no result if i remove search conditions it print all results this the code

class autopart(models.Model):
_inherit = 'product.template'  @api.multi
@api.depends('car','model')
def partnum(self):
    part=self.env['part_num'].search([('model_id', '=', 'model'),('car_id', '=', 'car')])
    print(part)
    pass

car = fields.Many2one(comodel_name="cars", store=True, string="Car", ondelete='restrict', required=False, )
model = fields.Many2one(comodel_name="models", store=True, string="Model", ondelete='restrict', required=False,default='', domain="[('car','=', car )]")

and this is the part num model

class part_num(models.Model):
_rec_name = 'name'
_name = 'part_num'  name = fields.Char(string="name",required=True)

car_id = fields.Many2one(comodel_name="cars", string="car", required=False, )
model_id = fields.Many2one(comodel_name="models", string="model", required=False, )


الصورة الرمزية
إهمال
أفضل إجابة

You just need to use the fields of product template to search the parts based on selected Car and Model in the product template and search for the related parts.

Try following code:

@api.multi
def partnum(self):
print (self.car, self.model)
parts = self.env['part_num'].search([('model_id', '=', self.car.id),('car_id', '=', self.model.id)])
print (parts)



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

it also print empty in parts even if true conditions

It should work without any issue. Make sure the car and model are selected in the product template.

Also make sure that parts has same combination as product template for the "car and model".

الكاتب

Thank you it works well dear

الكاتب

pleare change values in search conditions

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
ديسمبر 22
3615
2
أبريل 20
4529
1
أبريل 20
3472
2
سبتمبر 19
9053
2
يونيو 19
5580