Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
10764 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
6
set 17
7594
0
lug 17
4524
1
apr 16
5234
1
mar 15
3977
2
mar 15
9509