Home > OS >  Element cannot be located in parent view: Why im getting that error?
Element cannot be located in parent view: Why im getting that error?

Time:02-04

Hi I am trying to call a function from xml view using function tag. Im getting the next error and I dont get it: Element '<function model="website.track" name="reconoce">' cannot be located in parent view. Any help would be apreciated.

XML code:

<odoo>
    <record id="vista_track" model="ir.ui.view">
        <field name="name">vista.Web</field>
        <field name="model">website.track</field>
        <field name="inherit_id" ref="website.website_visitor_track_view_tree"></field> 
        <field name="arch" type="xml">
            
               
                <field name="page_id" position="after">
                    <field name="partner_id"/>
                </field>
                <function model="website.track" name="reconoce">
                </function>
            
            
        </field>
    </record>
</odoo>

PYTHON code:

class visita(models.Model):
    _inherit = 'website.track'
    
    #prueba = fields.Char()
    partner_id = fields.Many2one(comodel_name = 'mailing.contact',string='visitante')
    
    @api.model
    @api.depends("url")
    def reconoce(self):
        for a in self:
            var = a.url
            if "?" in var:
                try:
                    var2 = int(var[var.find('?') 1:var.find('%')])
                    a['partner_id'] = self.env['mailing.contact'].browse(var2)
                except:
                    a['partner_id'] = False

The thing is this code should call the function properly

CodePudding user response:

You added the function tag inside an inherited view arch, Odoo will try to find it in the parent view which is not what you want.

The function tag can be used in data files. when evaluated Odoo will call the function on the corresponding model, we add it as a child odoo tag.

The function tag can't be used as a child of a tree view, you can check the tree view rng file used to validate tree views

  • Related