2

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

Moaz Mabrok
  • 697
  • 10
  • 32

1 Answers1

4

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).

Kenly
  • 24,317
  • 7
  • 44
  • 60
  • Hi @Kenly I was creating a controller to gets information from module and wonted to display the pdf or image on the website how to get the url I was able to download `return http.send_file(maybefiel, filename='sdsdds', as_attachment=False)` it using this but I wonted to display it – Moaz Mabrok Jul 14 '20 at 23:52
  • I think you should ask another question, this requirement has nothing to do with the question title. – Kenly Jul 15 '20 at 01:07
  • I created a new question https://stackoverflow.com/questions/62908614/how-to-display-binary-field-data-in-website-using-a-controller-odoo-13 for the second part – Moaz Mabrok Jul 15 '20 at 06:13
  • I wonted to confirm this I used ```FileStorage = kw['record_file'] FileData = FileStorage.read() file_base64 = base64.encodestring(FileData)``` to save the file from the form as it gave me this error ```TypeError: argument should be a bytes-like object or ASCII string, not 'FileStorage'``` does this change the way it is stored in any way – Moaz Mabrok Jul 15 '20 at 06:17
  • also if i needed to see the file for some reason I need to use `res_field = True` – Moaz Mabrok Jul 15 '20 at 06:21
  • It is a char field, its value can be the field name. You can use `Ressource Field contains "record_file"` filter to show the attachments. – Kenly Jul 15 '20 at 08:13