Search code examples
odooodoo-13

what does attachment=True do odoo 13


I created a custom module in which I have this field

record_file = fields.Binary(string='file', attachment=True, help='Upload the file')

from what I understand attachment=True should save my images or pdfs to ir.attachment but am not seeing any there

am I doing something wrong


Solution

  • You are not doing something wrong, ir.attachment records are hidden when the value of res_field (a Char field) is set.

    When you upload the file and save, an attachment is created and the value of the res_field is set to record_file which makes it invisible under Attachments.

    You can check that the methods _search and read_group was overridden to add res_field=False in the domain if not present.

    Note that the default value for the attachment parameter is True so you do not need to useattachment=True.

    Edit:

    From Binary field documentation:

    attachment (bool) – whether the field should be stored as ir_attachment or in a column of the model’s table (default: True).