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

I've got a wizard that I call whit method that executes on button click. In the wizard I have a Many2one field on project.task that I want to filter. So in the method that calls the wizard, I get the action for the wizard popup, search the task ids that I want to show and then pass them into the actions domain. But when the wizard shows the field is not filtered.

Wizard:

parent_id = fields.Many2one('project.task')

Task:

def add_as_subtask_wizard(self):
action = self.env.ref('tabla_bi_subtask_extension.action_add_as_subtask_wizard').read()[0]
if action:
            tasks_ids = self.search([ 
('id', '!=', self.id),
('project_id', '=', self.project_id.id),
('parent_id', '=', False),
]).ids
if len(tasks_ids) > 0:
action['domain'] = {'parent_id': [('id', 'in', tasks_ids)]}
return action


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

Try this:

def add_as_subtask_wizard(self):
action = self.env.ref('tabla_bi_subtask_extension.action_add_as_subtask_wizard').read()[0]
if action:
            tasks_ids = self.search([ 
('id', '!=', self.id),
('project_id', '=', self.project_id.id),
('parent_id', '=', False),
]).ids
if len(tasks_ids) > 0:
action['context'] = {'task_ids': tasks_ids}
return action
And in your xml, set the domain of your field:
<field name="parent_id" domain="[('id', 'in', context.get('task_ids', []))]"/>


Ảnh đại diện
Huỷ bỏ
Tác giả

Sam, thank you! Damn, I was to focused to do this with action['domain'].

Câu trả lời hay nhất

hope this works 



def add_as_subtask_wizard(self):
action = self.env.ref('tabla_bi_subtask_extension.action_add_as_subtask_wizard').read()[0]
if action:
tasks_ids = self.search([
('id', '!=', self.id),
('project_id', '=', self.project_id.id),
('parent_id', '=', False),
]).ids
if len(tasks_ids) > 0:
action['domain'] = [('parent_id', 'in',[tasks_ids])] #use appropriate field 

return action
Ảnh đại diện
Huỷ bỏ
Tác giả

It's a relation field so this cannot work. So the appropriate field is 'id'.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 23
2864
2
thg 4 24
4924
1
thg 1 22
11266
1
thg 10 20
5025
0
thg 10 19
2844