Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
8000 Zobrazení

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:

Action:

        <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.
              </p>
            </field>
        </record>   

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">
                        <button
                            class="oe_inline oe_stat_button"
                            attrs="{'invisible': [('customer', '=', False)]}"
                            name="%(calendar_service.action_calendar_service)d"
                            icon="fa-star"
                            type="action"
                            context="{'search_default_partner_id': active_id}">
                            <field name="service_count" string="Services" widget="statinfo"/>
                        </button>
                    </button>
            </field>
        </record>

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')

    @api.one
    @api.depends('service_ids')
    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?

Avatar
Zrušit
Autor

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

Autor Nejlepší odpověď

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.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
pro 23
2490
2
lis 20
11475
1
dub 17
3785
3
bře 16
3890
2
zář 15
7303