تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4410 أدوات العرض

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?

الصورة الرمزية
إهمال
أفضل إجابة

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>


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

  2. 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".

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 20
5098
0
سبتمبر 24
755
1
أغسطس 20
959
0
نوفمبر 16
6312
1
يوليو 20
5867