如何写入许多字段并在UI中显示


merged_beneficiary_ids = fields.Many2many(
'openg2p.beneficiary',
'merged_beneficiary_rel',
'retained_id',
'merged_id',
string="Merged Duplicates",
index=True,
context={'active_test': False},
help="Duplicate records that have been merged with this."
" Primary function is to allow to reference of merged records "
)

我想在这个many2many字段中写入内容,并在odoo UI中显示merged_id的一些特定字段(可能是名字或姓氏(。我拥有的数据是受益人记录,id将被保留并合并。

当您想要显示特定字段时,这适用于x2many字段:首先将×2many字段的标签字段放入起始标签:

<field name="x2many_field_name>
</field>

现在,您在字段中添加树标记,为该特定字段创建特定列表:

<field name="x2many_field_name>
<tree>
        <!-- here you make a list view for x2many field's model so it's as you're inside the x2many field's model -->
         <!-- specific fields you want to show here -->
    </tree>
</field>

最后的代码如下:

<field name="merged_beneficiary_ids">
<tree>
         <!-- your fields here -->
         <field name="firstname" />
     </tree>
</field>

将现有记录添加到集合:

self.write({'merged_beneficiary_ids' : (4, id, 0)
})

请查看x2many字段的操作文档,因为Odoo以一种特殊的方式处理它。https://www.odoo.com/documentation/14.0/developer/reference/orm.html#odoo.models.Model.write

相关内容

  • 没有找到相关文章

最新更新