如何解决如何写入many2many字段并在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将被保留并合并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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。