I have a entity "request" that has a Many2one "department_id" attribute (hr.department). I have also extended the res.users models to have a reference of the department of that user (department_id)
I want to create a filter in the search view to get all requests of the department of the current user. I've tried with this code but when i clic the filter it shows "Error: AttributeError: object has no attribute 'department_id'"
Search view of the request entity:
<filter name="my_department" string="From my department" domain="[('department_id','=', uid.department_id)]"/>
Extending res.users:
class User(models.Model):
_inherit = ['res.users']
department_id = fields.Many2one(comodel_name='hr.department',
compute="_compute_departament",
string="Departament")
@api.multi
@api.depends('employee_ids')
def _compute_departament(self):
for record in self:
if record.employee_ids and record.employee_ids[0].department_id:
record.departament_id = record.employee_ids[0].department_id
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
6233
Lượt xem
Hi Ernesto:
uid contains just the numeric id of the department and cannot be used for looking up the department_id using the dot notation.
Try the reverse i.e. looking up the user id based on the department.
<filter name="my_department" string="From my department" domain="[('department_id.member_ids.user_id.id','=', uid)]"/>
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 11 22
|
4675 | ||
|
1
thg 7 25
|
180 | ||
Search a message
Đã xử lý
|
|
1
thg 2 25
|
1064 | |
|
0
thg 11 23
|
1022 | ||
|
0
thg 9 23
|
2072 |