odoo 中的附件在form及tree表单中以超链接的形式显示

例子:

下边附件上传3个附件
image
在form 表单中显示这三个附件:
image

代码:

mail.thread 模型中添加计算字段

from odoo import models, fields, api


class MailThread(models.AbstractModel):
    _inherit = 'mail.thread'

    attachment_ids = fields.Many2many(comodel_name='ir.attachment', compute='_compute_attachment_ids')

    def _compute_attachment_ids(self):
        for rec in self:
            rec.attachment_ids = self.env['ir.attachment'].search(
                [('res_id', 'in', rec.ids), ('res_model', '=', self._name)])

在xml文件中添加计算字段:

<field name="attachment_ids" widget="many2many_binary"/>
posted @ 2021-09-14 11:07  那时一个人  阅读(463)  评论(0)    收藏  举报