jquerypython-3.xxmlodooodoo-12

How to preview images &pdf after uploading as attachment in form view in Odoo V12


There is ir.attachment model available for uploading URL and files but I want to upload images,pdf files and that can be viewed on the uploading form UI-view.

Is there any way I can do it as I haven't found anything on this related to Odoo V12.


Solution

  • Use the pdf_viewer widget on the form view definition.

    See an example at <path_to_v12>/addons/mrp/views/mrp_workorder_views.xml. The relevant code follows:

    <notebook>
        <page string="Work Instruction" attrs="{'invisible': [('worksheet', '=', False)]}">
            <field name="worksheet" widget="pdf_viewer"/>
        </page>
        ...
    </notebook>
    

    and worksheet was defined as Binary (you may add the parameter attachment=True) like this:

    worksheet = fields.Binary('Worksheet', attachment=True)