Odoo Help

Welcome!

This community 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.

0

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

By
Duncan
on 6/5/14, 1:33 AM 487 views

Hiya,

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">
                <data>
                    <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"/>
                    </xpath>
                </data>
            </field>
        </record>

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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