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

2024-06-13 12:17:43 发布

您现在位置:Python中文网/ 问答频道 /正文

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 "
    )

我想写入这个多个字段,并在odoo UI中显示合并id的一些特定字段(可能是firstname或lastname)。我拥有的数据是受益人记录,id将被保留和合并id


Tags: toididsfieldsstringindexmergedrel
1条回答
网友
1楼 · 发布于 2024-06-13 12:17:43

当您希望显示特定字段时,这适用于许多字段,您可以: 首先,将标记字段放入带有起始标记的×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

相关问题 更多 >