zoukankan      html  css  js  c++  java
  • 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"/>
    

    懂得,原来世界如此简单!

  • 相关阅读:
    事后诸葛亮
    冲刺总结
    Alpha第十天
    Alpha第八天
    Alpha第九天
    Alpha第六天
    Alpha第七天
    Alpha第五天
    Python之pytesseract模块-实现OCR
    Selenium4 IDE初体验
  • 原文地址:https://www.cnblogs.com/qianxunman/p/15266643.html
Copyright © 2011-2022 走看看