Odoo Help


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.


search_default does not work?..

Andrius Laukavičius
on 8/21/14, 3:27 AM 791 views

I created button in partner form to show another models relation with it. It is same button like Opportunities, Meetings, Sales button at partners form showing all its Opportunities, Meetings, Sales etc.

Code looks like this:


        <record id="action_calendar_service" model="ir.actions.act_window">
            <field name="name">Services</field>
            <field name="res_model">calendar.service</field>
            <field name="view_mode">tree,calendar,form</field>
            <field name="view_id" ref="view_calendar_service_tree"/>
            <field name="search_view_id" ref="view_calendar_service_search"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create new service.

inherited view:

        <record id="view_partners_form_service1" model="ir.ui.view">
            <field name="name">view.res.partner.form.crm.inherited1</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="crm.view_partners_form_crm1"/>
            <field eval="18" name="priority"/>
            <field name="arch" type="xml">
                    <button name="schedule_meeting" position="after">
                            class="oe_inline oe_stat_button"
                            attrs="{'invisible': [('customer', '=', False)]}"
                            context="{'search_default_partner_id': active_id}">
                            <field name="service_count" string="Services" widget="statinfo"/>

code in res.partner model:


class res_partner(models.Model):
    _inherit = 'res.partner'

    service_ids = fields.One2many('calendar.service', 'partner_id', 'Calendar Services')
    service_count = fields.Integer('Services', compute='_count_services')

    def _count_services(self):
        self.service_count = len(self.service_ids)

So everything works, except it always opens all 'calendar.service' records without filtering with 'partner_id' (the one that button was pressed from). Is there something I miss?

If I change action id in name attribute for example to opportunity action. Then search_default works and filters it. But if I use it with my view, it does not work for some reason

NOD Baltic, UAB, Andrius Laukavičius
on 9/18/14, 9:13 AM
Andrius Laukavičius
On 9/18/14, 9:34 AM

Finally found what was missing. I needed to add this line:

`<field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>`

In my model search view. Without that it does not use search_default filter.

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

2 follower(s)


Asked: 8/21/14, 3:27 AM
Seen: 791 times
Last updated: 3/16/15, 8:10 AM