1
votes

TLDR; how can I show records with flag active=False in one2many relation in Odoo 13? I cannot see them neither in xml nor in python.


I want to show all meetings (active+inactive) in res.partner form view in Odoo13 while still showing only active in calendar.

I defined one2many relation:

class ResPartner(models.Model):
    _inherit = 'res.partner'
    event_ids = fields.One2many('calendar.event', 'partner_id', 
                                 domain=['|', ('active', '=', True), ('active', '=', False)])

and placed a one2many field into a view.

            <field name="event_ids" mode="tree"
                   domain="[('partner_id', '=', active_id), 
                            '|', ('active','=', True), ('active', '=', False),
                   context="{'default_active': False, 'active_test': False}">
                <tree string="Events">
                    .... columns
                    .... button to add to calendar (or checkbox to toggle?)
                </tree>
            </field>

But I cannot see the inactive events. As you can see I also tried to add active_test to context, I also explicitly defined domain in field/relation definition. It does not work.

I can create inactive event and see it while editing a parent record. However, it will disappear after saving the parent record. My goal is to allow add or remove it from calendar view with a single inline button. AFAIK it used to work in Odoo9.

I don't even see the inactive event_ids while debugging when I call partner.event_ids, if I need them I can call

self.env['calendar.event'].with_context(active_test=False).search([('partner_id','=',self.id)])

which is not very handy and I can not use it in xml anyway.

Is it even possible to show inactive records with one2many relationship in Odoo or should I add a flag to calendar.event model which will control visibility in calendar view?

1
channel_last_seen_partner_ids use context="{'active_test': False}" and it is a One2many field.Kenly
@Kenly thank you for information. It works for channel_last_seen_partner_ids but not in my case. I changed the field definition and xml according to linked code but still cannot see the inactive records. But now, at least I know it is possible.Juraj Bezručka

1 Answers

0
votes

In fields add attribute context={'active_test': False}

class ResPartner(models.Model):
    _inherit = 'res.partner'
    event_ids = fields.One2many(
        'calendar.event', 'partner_id', 
        domain=['|', ('active', '=', True), ('active', '=', False)],
        context={'active_test': False})