Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
8237 Lượt xem

I have a wizard model, where user can choose a car from another model(named 'techdoc' with fields car brand, model, year etc).
In first selection field user chooses car brand, and in second selection user chooses car model, depends on the selected first field.
But the second field value does not displays computed values to choose after setting the second field value. 
Is there any method to make it work properly?

class Roll_wizard(models.TransientModel):

_name = 'roll.wizard'

@api.multi

def get_car_brand(self):

brand = []

result = self.env['techdoc'].search([('name', '!=', "")])

for record in result:

tup=(record.name.lower(), record.name.title())

brand.append(tup)

brand = list(set(brand))

return sorted(brand)


@property

def ret_value(self):

return self.car_brand


@api.onchange("car_brand")

def get_car_model(self):

model = []

result = self.env['techdoc'].search([('name', '=', self.ret_value)])

for record in result:

tup=(record.car_model, record.car_model.title())

model.append(tup)

model = list(set(model))

return sorted(model)


car_brand = fields.Selection(get_car_brand, string="Car Brand")

car_model = fields.Selection(get_car_model, string="Car Model")

 

If I'll print in console the result of returned value's of get_car_model:

print result

print model

techdoc(18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)

[(u'fiesta', u'Fiesta'), (u'focus', u'Focus'), (u'fusion', u'Fusion')]

 So we can see, server returns the right value, but the selection field is not updated dynamically. 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I know it's an old question, but I've got here looking for a way to dynamically generate a selection list for each record of a model / recordset and I didn't succeeded yet.

But in your case I would have used two `Many2one` fields and for the car model a domain based on the car brand value, without the need to over complicate an build selection lists

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 5 22
14436
2
thg 5 16
10361
2
thg 12 22
5310
1
thg 12 20
4449
5
thg 4 19
8814