Dear all,
I need to have a form view were user will be able to select a value from a list, based on a previous selected value on another related field. It will use the same approach as the Country / States on partners form were user selects a Country and Odoo will show all states for the selected Country.
I am learning Odoo developement and I am using Odoo version 9 for this module.
The module.py has 3 classes (just an example):
- Vehicles class: for registering vehicles;
- Brands class: for registering vehicles brands - related to models class below;
- Models class: for registering vehicle brand models - related to brands class;
The classes definition
class vehicle_vehicle(models.Model):
_name='vehicle.vehicle'
_columns = {
'name' : fields.char('Name', size=64, required=True),
'brand_id' : fields.many2one('vehicle.brand','Brand'),
'model_id' : fields.many2one('vehicle.model','Model'),
}
class vehicle_brand(models.Model):
_name='vehicle.brand'
_columns = {
'name' : fields.char('Name', size=32, required=True),
'model_ids' : fields.one2many('vehicle.model','brand_id',string='Models'),
}
class vehicle_model(models.Model):
_name='vehicle.model'
_columns = {
'name' : fields.char('Name', size=40, required=True),
'brand_id' : fields.many2one('vehicle.brand','Brand'),
}
I have a form view for the vehicles were I do need to allow user to select a "brand" and under "models" list all models related to the selected brand :
<record id="vehicle_vehicle_form_view" model="ir.ui.view">
<field name="name">vehicle.vehicle.form.view</field>
<field name="model">vehicle.vehicle</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Vehicles">
<sheet>
<group>
<field name="name"/>
<field name="brand_id"/>
<field name="model_id"/>
</group>
</sheet>
</form>
</field>
</record>
How can I achieve that?
Thank you all in advance
Best regards
Paulo