Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1128 มุมมอง

I am using odoo18, and it troubles me with the control in list view that even I copied code from purchase module, it seems like not capable.

code like:

<control>
<create name="add_product_control" string="add field" context="{'default_display_type': ''}"/>
<create name="add_section_control" string="add a section" context="{'default_display_type': 'line_section'}"/>
<create name="add_note_control" string="add a note" context="{'default_display_type': 'line_note'}"/>
</control>

But when I click on the add a section or add a note, it always creates a record like clicking on add field.

Is there any possible solution, thanks & regards.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You need to make sure your model uses the context default when creating:

class YourModel(models.Model):

    _name = "your.model"

    _description = "Your Model"


    display_type = fields.Selection([

        ('', 'Normal Line'),

        ('line_section', 'Section'),

        ('line_note', 'Note'),

    ], string="Display Type", default='')


    @api.model

    def create(self, vals):

        if not vals.get('display_type'):

            vals['display_type'] = self._context.get('default_display_type', '')

        return super().create(vals)


XML:

<field name="display_type"/>

    <control>

        <create name="add_product_control"

                string="Add field"

                context="{'default_display_type': ''}"/>

        <create name="add_section_control"

                string="Add a section"

                context="{'default_display_type': 'line_section'}"/>

        <create name="add_note_control"

                string="Add a note"

                context="{'default_display_type': 'line_note'}"/>

    </control>


Hope it helps.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.ย. 25
703
3
ส.ค. 25
982
1
ก.ค. 25
868
1
ก.ค. 25
1214
1
ก.ค. 25
1638