Step 1 .py file:
name = fields.Char('Description')
display_type = fields.Selection(
selection=[
('line_section', "Section"),
],
default=False)
@api.model
def create(self, vals_list):
if vals_list.get('display_type'):
vals_list.update(product_id=False, qty=0)
return super().create(vals_list)
Step 2 .xml file:
<field name="parts_ids" widget="section_and_note_one2many" mode="tree"
context="{'default_display_type': False}">
<tree editable="bottom">
<control>
<create string="Add Line"/>
<create name="add_section_control"
string="Add a section"
context="{'default_display_type':'line_section'}"/>
</control>
<field name="product_id" domain="[('sparce_part', '=', True)]"
required="not display_type"/>
<field name="display_type" column_invisible="1"/>
</tree>
</field>