Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
7859 มุมมอง

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




อวตาร
ละทิ้ง
ผู้เขียน

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

ผู้เขียน คำตอบที่ดีที่สุด

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!

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ต.ค. 19
12749
0
มี.ค. 15
5635
0
ส.ค. 25
8
0
ส.ค. 25
8
0
ส.ค. 25
8