Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2864 Lượt xem

My question from https://www.odoo.com/forum/help-1/many2many-domain-not-working-189817 is not working again.


To recap I got a answer and my current code is this:


class Example(models.Model):
_name = "example.model"
team = fields.Many2one("maintenance.team", "Team")
work_shift_lines_ids = fields.Many2many("hr.employee", relation="shift_one_relation")

@api.onchange("team")
def onchange_team_id(self):
team_employees_domain = [("user_id", "in", self.team.member_ids.ids)]
return {"domain": {"shift_one_lines_ids": team_employees_domain}}

Now this works but the problem is (ofc) it doesn't work when team isn't changed.

One example of this is when the form view is created and saved, so when you load it again for modifications (for example just want to add another employee to lines) the field work_shift_lines_ids will have no domain and all employees will be available (because in this case team is not changed thus onchange was not triggered).


I tried many way to actually set the domain in model field or even in the view form but it does not work. I need a concrete example on how to do this because there was not a single answer on the whole internet that helped me, even by a bit.



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Solved this with web_domain_field addon.

Ảnh đại diện
Huỷ bỏ

For those people who needs to know about this addons, see: https://www.youtube.com/watch?v=dq5Vtj_pwuI

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 11 22
80
1
thg 6 22
7312
1
thg 7 21
4334
9
thg 2 16
49379
1
thg 10 15
10908