콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7908 화면

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!

아바타
취소
관련 게시물 답글 화면 활동
3
10월 19
12842
0
3월 15
5701
1
9월 25
87
2
8월 25
423
1
9월 25
414