Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
10716 Tampilan

Model

class ItemStocks(models.Model):

    _name = 'item.stocks'

    item_url = fields.Char('View Item')

    ItemStocks()


View:

<record id="view_item_stocks_form" model="ir.ui.view">

     <field name="name">item.stocks.form</field>

     <field name="model">item.stocks</field>

     <field name="arch" type="xml">

         <form string="Item Stocks"> ...

            <page string="Live Site">

                 <form string="Embedded Webpage" version="7.0" edit="false">

                       <iframe marginheight="0" marginwidth="0" frameborder="0" src="{Variable for this.item_url}" width="100%"                                   height="1000"/>

                 </form>

         </page> ...

        </form>

     </field>

</record>


How can I replace {Variable for this.item_url} with a valid expression for the field in model?

Is there a better way to do like this?

What would you prefer to solve the requirement of showing dynamically an embedded webpage?

Avatar
Buang
Jawaban Terbai

I'm not sure to have well understood the question.
But if you want a generic iframe preview,
a tricky way can be to use a template and store the computed template in a field.

Here an example of how it could be made (to test)...


from openerp import api, fields, models

Model :

class ItemStocks(models.Model):
    _name = 'item.stocks'
     item_url = fields.Char('View Item')
     ItemStocks()

     iframe = fields.Html('Embedded Webpage', compute='_compute_iframe', sanitize=False, strip_style=False )
  
    @api.multi
     def _compute_iframe(self):
        for item_stock in self:
            url = item_stock.item_url
            template = self.env.ref('<your_module_name>.framed_page')
            item_stock.framed_page_rendered = template.render({ 'url' : url })  

View:

<template id='framed_page'>
     <iframe t-att-src="url"
     marginheight="0" marginwidth="0" frameborder="0"
     width="100%" height="1000"></iframe>
</template>


<record id="view_item_stocks_form" model="ir.ui.view">
     <field name="name">item.stocks.form</field>
     <field name="model">item.stocks</field>
     <field name="arch" type="xml">
         <form string="Item Stocks"> ...
            <page string="Live Site">
                 <form string="Embedded Webpage" version="7.0" edit="false">
                <field name="framed_page_rendered" widget="html"/>
                 </form>
         </page> ...
        </form>
     </field>
</record>

Avatar
Buang
Jawaban Terbai

Also Refer this site:

@V11 odoo Community

https://www.odoo.com/forum/help-1/question/i-want-to-add-an-iframe-in-openerp-with-a-dynamic-src-36038

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
6
Sep 17
7461
0
Jul 17
4487
1
Apr 16
5171
1
Mar 15
3895
2
Mar 15
9415