Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1319 Vistas

I've encountered a bug when using a binary field for storing a pdf, which I am not sure how to resolve.

Steps to reproduce:

  1. Upload a file
  2. Save
  3. Use the edit button to upload another file over it
  4. Save
  5. Upload the edit button to upload again
  6. Save and refresh the page
  7. Observe

Expected result:

The third file is displayed/stored in the sale's order

Actual result:

The second file persists. Even deleting it, saving and then uploading a new file, still shows the second one on refresh.

Additional information
In my model, i've defined the field as follows

scanned_contract = fields.Binary(copy=False, help="Attach here the signed hard copy of the contract")​

Then, in my view I display it like this, using pdf_viewer widget:

xpath expr="//field[@name='signature']" position="after"
​field widget="pdf_viewer" name="scanned_contract"/            
/xpath

Am I defining something wrong, or is this a bug with odoo/pdf_viewer itself?

Avatar
Descartar
Mejor respuesta

Hi Daniel Bashev,

Here’s an example using Odoo's fields.Binary to upload a file with its filename stored separately. This can be useful in forms for handling file uploads, such as for importing data or documents.

Python:

class YourModel(models.Model):
    _name = 'your.model'

    import_file = fields.Binary('Select File')  # Binary field to store the file
    file_name = fields.Char('File Name')  # Char field to store the file name

XML (for the view):

Explanation:

  • import_file: This is the field where the file data is stored.
  • file_name: This field will store the name of the uploaded file. It is hidden (invisible="1") in the form but still recorded.
  • filename="file_name": This ensures the uploaded file is associated with its filename, which is automatically captured.

Let me know if you need further details or customizations!

Best regards,

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
6
dic 24
3678
3
abr 24
1823
0
abr 25
349
0
oct 24
1724
2
jun 24
1835