I would like to use the pdf viewer widget. I know that to display the pdf/image you have to have it downloaded to a directory so that you can pull it from there. But I wonder if there is a way to show image without uploading it. Is there is a way to use an image viewer/pdf widget that can accept a link that can be programmed into a database?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
you can try this way:
Create a New Field:
Add a new field to your model that will store the URL of the image or PDF you want to display.
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
_description = 'My Model'
image_url = fields.Char(string="Image URL")
Modify the Form View:
In your form view, you can use the widget attribute to display the image or PDF using an external URL
record id="view_my_model_form" model="" rel="ugc">ir.ui.view">
field name="name">my.model.form
field name="model">my.model
field name="arch" type="xml">
form>
group>
field name="image_url" widget="image" options="{'preview_image': 'url'}"/>
/group>
/form>
/field>
/record>
In this example, the widget attribute is set to "image" to display an image. The options attribute specifies that the URL should be used as the image source.
Input Image URLs: Now you can input external image URLs directly into the image_url field of your model. This URL can point to an image or a PDF file.
Thank you for this info @ shubham shiroya
I added the field and modified the form view.
When I checked the table in the database, I can see that the new field image_url has been successfully created there.
This is the updated form view:
<record id="vendor_bill_form" model="ir.ui.view">
<field name="name">vendor_bill_form</field>
<field name="model">vendor.bill</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group>
<field name="image_url" widget="image" options="{'preview_image':
'https://www.usnews.com/media/best-states/overall-rankings-2021.pdf'}"/>
</group>
</form>
</field>
</record>
And this is my new added field in my model:
image_url = fields.Char(string="Image URL")
Just for an example, I inputted that external link shown above.
But when I update the module, that URL is not being displayed. What can I do to fix it?
I also tried to apply the options attribute to the pdf widget, instead of image widget:
<group>
<field name="file" class="pdf_viewer" widget="pdf_viewer" options="{'preview_image':
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}" />
/group>
In this case, when I update the module, if I don't have an image uploaded already, then the pdf file states as missing PDF file:
PDF.js v2.2.228 (build: d7afb74a)
Message: Missing PDF "http://localhost:8069/web/content?model=vendor.bill&field=https%3A%2F%2Fwww.google.com%2Fimages%2Fbranding%2Fgooglelogo%2F1x%2Fgooglelogo_color_272x92dp.png&id=3".
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jul 20
|
5003 | ||
|
0
Sep 24
|
679 | ||
|
1
Aug 20
|
907 | ||
|
0
Nov 16
|
6213 | ||
|
1
Jul 20
|
5782 |