Get document attachment list in qweb report Odoo

Question:

I am using qweb reports to generate a document which should have associated attachments using the document module of Odoo. But I don’t know how to display the list of attachments associated to a document in the qweb/pdf report.

Please note that I am not asking to store a document as attachment. Just to display the list of current attachments in a report.

Do you know how to do that?

Asked By: mijailr

||

Answers:

I solve that problem using computed fields in a relationship one2many.

this make the magic:

attachment_ids = fields.One2many(comodel_name="ir.attachment", inverse_name="res_id", compute="_add_attachment")
@api.multi
def _add_attachment(self):
    self.attachment_ids = self.env['ir.attachment'].search([('res_model','=','document'),('res_id','=',self.id)])
Answered By: mijailr
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.