This question has been flagged
10 Replies
33941 Views

Hi!

I want to show active and non-active records (here: of a one2many relationship) in the tree view of a subview together.

I tried

domain="['|',('active','=',True),('active','=',False)]"

to show both, but this had no effect - only active=True is shown. Even

domain=[('active','=',False)]

to show only non-active records does not work: it shows only active records, still.

Any hints or ideas? Is the many2one view broken in some way in 6.1?

<record id="model_form" model="ir.ui.view">
        <field name="name">model.form</field>
        <field name="model">model</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
                <form string="model">
                       <field name="name" colspan="4" />
                       ...
                       <separator colspan="4" string="Remotes" />
                            <field name="remote_ids" nolabel="1" colspan="4"
                            domain="['|',('active','=',True),('active','=',False)]">
                                    <tree string="Remote">
                                            <field name="name" />
                        ...
                                    </tree>
                                    <form string="Remote">
                                            <field name="name" colspan="4" />
                        ...
Avatar
Discard
Best Answer

Option 1:

Put context on your field definition:

remote_ids = fields.One2many(comodel_name='model.remote', inverse_name='remote_inverse', string='Remote IDs', context={'active_test': False})

Note: This context is only applied when searching values.


Option 2:

You can add the context with {'active_test': False} on the action that opens directly the tree/form view, but if you enter on the register vía relational link (click on many2one or something that not implies Menús or Actions), you will not have the context because you are not using the action (and don't see the registers).


Avatar
Discard
Best Answer

Try to specify active_test in context to ignore active field


 <field name="remote_ids" context="{'active_test':False}">...
Avatar
Discard
Best Answer
  • Adding a filter in the search view for model.form should do.
  • You must have a "active" field in the form view of model.form view to use this,
  • <filter icon="terp-personal+" domain="[('active','=',True)]" name="active" string="Active"/>

Hope it Helps..

Avatar
Discard
Author

Sorry, I don't have a search view when the object is embedded as one2many field :)

Then you must inherit one from the model.from

Author

It's not about showing active lines from model.form, it's about the a subform view of the model related via remote_ids (in model.form), and the implicitly included subform defined by tree and form in field name="remote_ids".

(And yes, of course field name="active" is in the remote_ids block form, as invisible="1". I also tried to add it to tree.)

Your one2many field object is 'res.users' ?

Author

No, it's not res.users, it's an own module in development. But it shouldn't matter at all, which object is related. (As long as it has an "active" field.)

Best Answer

I think you should override the search function of the one2many field object.

Avatar
Discard
Best Answer

I wrote some code here the example.. it works for me

'jo_ids' : fields.one2many('jo.jo', 'employee_id', domain=['|',('active','=',False),('active','=',True)], string='No Jo'),
Avatar
Discard