İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
4900 Görünümler

Hello,

Is it possible to embed video in form view?

Rgds,

Anil


Avatar
Vazgeç
En İyi Yanıt

Yes, it's possible to embed a video into a form view in Odoo. You can achieve this by using the iframe HTML tag within the form view. Here's how you can embed a video, such as a YouTube or local video, into a form view in Odoo:

Steps to Embed a Video in a Form View

1. Add a Char or URL Field to Your Model

If you want the video URL to be dynamic (e.g., a YouTube video URL), add a field to your model to store the video link.

Example:

from odoo import models, fields

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

    video_url = fields.Char(string="Video URL", help="Enter the video URL to embed")

2. Update the Form View XML

Modify the form view to include an iframe tag or video embed logic. Use the video_url field to load the video dynamically.

Example XML:

<record id="view_form_your_model" model="ir.ui.view">
    <field name="name">your.model.form</field>
    <field name="model">your.model</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group>
                    <field name="name"/>
                    <field name="video_url"/>
                </group>
                <group>
                    <div t-if="record.video_url.raw_value" style="margin-top: 20px;">
                        <iframe t-att-src="record.video_url.raw_value"
                                width="560"
                                height="315"
                                frameborder="0"
                                allowfullscreen>
                        </iframe>
                    </div>
                </group>
            </sheet>
        </form>
    </field>
</record>
  • Key Points:
    • t-if="record.video_url.raw_value" ensures the video is displayed only if a URL is provided.
    • t-att-src="record.video_url.raw_value" dynamically sets the src attribute of the iframe to the value of the video_url field.

3. Testing

  1. Navigate to the corresponding form view for your model in Odoo.
  2. Enter a video URL (e.g., a YouTube video: https://www.youtube.com/embed/VIDEO_ID).
  3. Save the record, and the video should appear embedded in the form view.

Alternative: Embed a Hardcoded Video

If you don’t need dynamic video URLs and want to embed a static video, you can directly include the iframe in the XML without using a field:

Example:

<group>
    <iframe src="https://www.youtube.com/embed/VIDEO_ID" 
            width="560" 
            height="315" 
            frameborder="0" 
            allowfullscreen>
    </iframe>
</group>

4. Security Considerations

  • Ensure the video URL comes from a trusted source to prevent embedding malicious content.
  • If users enter the video URL manually, validate it using Odoo's @api.constrains or custom validation logic in the model.

Example Validation:

from odoo.exceptions import ValidationError

@api.constrains('video_url')
def _check_video_url(self):
    for record in self:
        if record.video_url and not record.video_url.startswith("https://www.youtube.com/embed/"):
            raise ValidationError("Please provide a valid YouTube embed URL.")

5. Embedding a Local Video

If the video is hosted locally or within Odoo, you can use the file or binary field and render it using an HTML <video> tag.

Example:

  • Add a Binary field:
    video_file = fields.Binary(string="Video File")
    
  • Update the XML view:
    <group>
        <video t-if="record.video_file.raw_value" controls width="560" height="315">
            <source t-att-src="'data:video/mp4;base64,%s' % record.video_file.raw_value" type="video/mp4"/>
            Your browser does not support the video tag.
        </video>
    </group>
    

By following the steps above, you can easily embed videos into form views in Odoo for dynamic or static content. Let me know if you need further assistance!

Avatar
Vazgeç
En İyi Yanıt

hello,

see this link https://www.odoo.com/forum/help-1/question/how-to-display-video-in-the-website-121494

may this will be helps you.

Avatar
Vazgeç
Üretici

I appreciate Mitul, for the link you've shared. Unfortunately I'm not looking for that solution, that I know already, that how to embed in website page. My question is how to embed video on form view, which is comes in odoo back end web part. I hope now my question is clear to you. Anyway, thanks.

Were you able to make progress in this. I am using odoo 17 and still there is no way to embed a video in the backend webpart.

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Ağu 25
2172
1
Tem 25
722
1
Ağu 25
1150
0
May 25
1247
2
Nis 25
3417