Odoo Help


Adding a custom function to a filter for a field in a view

on 6/5/14, 1:33 AM 784 views


I have a dropdown that I require to be populated based upon the input from another dropdown. The logic side of this should be fine, my problem comes with actually using the function that I have defined within my view where I am filtering the dropdown.

I get this error: "Validate Error Error occurred while validating the field(s) arch: Invalid XML for View Architecture!" and if I look back into the logs it seems that it's because it can't find the place where I have referenced my function. I have tried putting <field name="get_parent_id" /> and many variants of this in different locations throughout the view but I seem to always end back with the problem of my code not being able to find the function. Help here would be greatly appreciated!

The function in account_invoice.py (overridden) is:

    def get_parent_id(self, cr, uid, ids, field_name, arg, context=None):
        """Returns the parent id to supply the dropdown with relevant 'attention' details"""
        result = {}
        if not ids:
            return result
        for record in self.browse(cr, uid, ids, context=context):
            result[record.id] = record.partner_id.id
        return result

My view account_invoice_view.xml is:

        <record id="invoice_form" model="ir.ui.view">
            <field name="get_parent_id" />
            <field name="name">account.invoice.form</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="catalyst_setup.invoice_form" />
            <field name="arch" type="xml">
                    <xpath expr="//field[@name='po_number']" position="before">
                        <field name="attn" domain="[('parent_id','=',get_parent_id)]" on_change="onchange_attn(attn)" widget="many2many_tags"/>

(I hope those put themselves in blocks, I haven't been able to see how to do that in the wysiwyg)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/5/14, 1:33 AM
Seen: 784 times
Last updated: 3/16/15, 8:10 AM