This question has been flagged
4533 Views

I am trying to figure out how to add the ability to add the custom module to the advanced filter so that we can search for customer that have a particular series of dongle associated with them.

Here is my res_parter.py

from osv import fields, osv   

class res_partner(osv.osv):
    """ Inherits partner and adds CRM information in the partner form """
    _inherit = 'res.partner'


    def _dongle_count(self, cr, uid, ids, field_name, arg, context=None):
        res = dict(map(lambda x: (x,0), ids))
        # The current user may not have access rights for sale orders
        try:
            for partner in self.browse(cr, uid, ids, context):
                res[partner.id] = len(partner.sale_order_ids)
        except:
            pass
        return res

    _columns = {
        'dongle_count': fields.function(_dongle_count, string='# of Dongles', type='integer'),
        'dongle_ids': fields.one2many('dongle', 'partner_id', 'Dongles')
    }


res_partner()

and my res_partner_view.xml

<?xml version="1.0"?>
<openerp>
    <data>
        <record id="act_res_partner_2_dongle" model="ir.actions.act_window">
            <field name="name">Dongles</field>
            <field name="res_model">dongle</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'search_default_partner_id': active_id}</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create a dongle for this customer.

              </p>
            </field>
        </record>

        <!-- Partner kanban view inhert -->


        <record id="res_partner_view_buttons" model="ir.ui.view">
            <field name="name">res.partner.view.buttons</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="priority" eval="20"/>
            <field name="arch" type="xml">
                <xpath expr="//div[@name='buttons']" position="inside">
                    <button name="%(act_res_partner_2_dongle)d" type="action"
                        string="Dongles"
                        attrs="{'invisible': [('customer', '=', False)]}"/>
                </xpath>
            </field>
        </record>       

    </data>
</openerp>

After looking at the various other modules that include this, I can't seem to figure out where/what else I am supposed to add to make my new module show up in the advanced search drop down.

Avatar
Discard