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

Is it possible to "lock" a task when it gets to a certain stage so it can't be moved or data edited?

Normally I do this with a bool field that I set to true and then check it at the beginning of the write method and when it's TRUE it just raises a validation that the record cannot be changed. But when I try this approach on the task it doesn't work because moving a task in kanban triggers the write method 2 times, first it writes the new stage_id and second it writes a sequence.

So is there a way that when the task is moved to a certain stage, that one prevents the task to be edited and have still have the kanban view? 

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

This just can't be done with the write method. Had to disable moving  the task to certain stages with the @api.constrain('stage_id'). And allow to move to them only with a button. The button then executes a query.

self.env.cr.execute('UPDATE project_task '
                    'SET stage_id = %(stage_id)s, locked = TRUE, write_date = %(write_date)s '
                    'WHERE id IN %(task_id)s ', ({'stage_id': stage_id, 'task_id': tuple(task_ids), 'write_date': write_timestamp}))

After that I just check the locked field in the write method

if self.locked:
	raise ValidationError(_(u'Task cannot be changed!'))
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
at what level in developer mode we will enter the code

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 25
2046
3
thg 9 19
7852
1
thg 3 17
4875
1
thg 6 23
3467
2
thg 3 23
2613