Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
10728 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
6
sept. 17
7493
0
juil. 17
4493
1
avr. 16
5181
1
mars 15
3910
2
mars 15
9444