例子:

下边附件上传3个附件
odoo 中的附件在form及tree表单中以超链接的形式显示
在form 表单中显示这三个附件:
odoo 中的附件在form及tree表单中以超链接的形式显示

代码:

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

相关文章:

  • 2021-08-08
  • 2022-01-07
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2021-05-31
  • 2021-08-14
  • 2021-12-05
  • 2021-11-27
相关资源
相似解决方案