Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
10799 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
6
sept 17
7635
0
jul 17
4538
1
abr 16
5250
1
mar 15
4014
2
mar 15
9549