Hi,
In Odoo, when you have repetitive data like tyre slots, the recommended approach is to create a tyre.slot model and link it to your main model (e.g., vehicle) via a One2many field. Then, in the form view, you can display each tyre slot in a form view inside a notebook or a group.
Code:
from odoo import models, fields, api
class Vehicle(models.Model):
_name = 'fleet.vehicle'
_description = 'Vehicle'
name = fields.Char(string="Vehicle Name")
tyre_slot_ids = fields.One2many('tyre.slot', 'vehicle_id', string="Tyre Slots")
class TyreSlot(models.Model):
_name = 'tyre.slot'
_description = 'Tyre Slot'
vehicle_id = fields.Many2one('fleet.vehicle', string="Vehicle")
slot_number = fields.Integer(string="Slot Number")
brand = fields.Char(string="Brand")
size = fields.Char(string="Size")
otd = fields.Float(string="OTD")
rtd = fields.Float(string="RTD")
condition = fields.Selection([('new', 'New'), ('used', 'Used'), ('bad', 'Bad')], string="Condition")
def button_repair(self):
# Example button logic
self.condition = 'new'
XML:
<record id="view_vehicle_form" model="ir.ui.view">
<field name="name">fleet.vehicle.form</field>
<field name="model">fleet.vehicle</field>
<field name="arch" type="xml">
<form string="Vehicle">
<sheet>
<group>
<field name="name"/>
</group>
<notebook>
<page string="Tyre Slots">
<field name="tyre_slot_ids">
<form>
<group>
<field name="slot_number"/>
<field name="brand"/>
<field name="size"/>
<field name="otd"/>
<field name="rtd"/>
<field name="condition" attrs="{'readonly':[('condition','=','bad')]}"/>
</group>
<footer>
<button name="button_repair" type="object" string="Repair" class="btn-primary"/>
</footer>
</form>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
Hope it helps
Do you mean to add an undefined number of fields in the form? Like slot_1_brand, slot_2_brand, slot_n_brand where n is to be determined by *something*? What is the outcome you are looking for and why exactly is a One2many field not suitable? Because a One2many field is supposed to exactly handle this scenario... Also, One2many lists in forms allow for readonly, invisible (and column_invisible) conditions as well. So far it sounds like really bad model design.