Skip to Content
मेन्यू
This question has been flagged
2 Replies
1794 Views
steps followed:
1.widget="section_and_note_one2many" add to one2many field
2. context="{'default_display_type': 'line_section'}" for add a section control


From the above code i'm trying to add a section , so the add a section option is reflecting but when i click on it it works same as add a line


Avatar
Discard
Best Answer

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>



Avatar
Discard
Best Answer
Add that display_type field in your O2M field as an invisible.

Hope it's helps you.
Avatar
Discard
Related Posts Replies Views Activity
0
जन॰ 24
4693
1
जन॰ 25
1530
2
सित॰ 24
1286
1
जुल॰ 24
2402
1
जुल॰ 24
1660