Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
7843 Vistas

Hello all,

We have this new field on the res.partner model :

partner_territory = fields.Many2one('res.territory', string='Partner\'s territory')


We also have this new field on the res.users model :

user_of_territory_ids = fields.Many2many('res.territory', 'res_territory_users_rel', 'user_id', 'territory_id', string='Allowed Territories for this user')


Both new fields work well!

We want to write the domain on the action base.action_partner_form to display ONLY partners with a territory allowed to connected user.

For the moment, I have this domain in this action :

[('partner_territory', 'in', uid.user_of_territory_ids)]

But Odoo says that :

Uncaught Error: AttributeError: object has no attribute 'user_of_territory_ids'


How to write this domain please???


EDIT #1

I have tried these domains, without success :

[  (  'partner_territory','in',[id for id in uid.user_of_territory_ids[0][2]]  )  ]




Avatar
Descartar
Autor

I always have problem with this kind of domains. One day, I will understand...

Autor Mejor respuesta

Here is my solution. I'm proud of it! I hope this is the best solution for this problem.


We already had this new field on the res.partner model :

partner_territory = fields.Many2one('res.territory', string='Partner\'s territory')


We also already had this new field on the res.users model :

user_of_territory_ids = fields.Many2many('res.territory', 'res_territory_users_rel', 'user_id', 'territory_id', string='Allowed Territories for this user')


 We added this new field on res.territory. This field is the inverse (don't know if it is an acceptable term...) of user_of_territory_ids on res.users. This new user_ids field use the same table of user_of_territory_ids on res.users.

user_ids = fields.Many2many('res.users', 'res_territory_users_rel', 'territory_id', 'user_id', string='Users who have this territory allowed', readonly=True)


And we override the base.action_partner_form with this new domain.

<record id="base.action_partner_form" model="ir.actions.act_window">
    <field name="domain">[ (  'partner_territory.user_ids','in', uid  )  ]</field>
</record>


Once again, it is like magic! Good! Good!

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
oct 19
12747
0
mar 15
5609
1
ago 25
202
1
ago 25
91
0
ago 25
124