[FIX] project: allows to quick create record from My Tasks kanban
The refactor of the kanban quick create implemented in https://github.com/odoo/odoo/pull/117449 introduced a traceback when creating a task from the My Tasks kanban view due to the presence of 'default_personal_stage_type_ids' key in the context. This commit fix that by removing this key from the context in the customization of the kanban view for project.task model. It also add a js tour test to ensure that personal tasks can be created from the quick create form in the My Tasks kanban view. Steps ===== - Install module project - Go to the view "Tasks -> My Tasks" - In the main Kanban View click on "New" - Enter a Task title and clicl on "ADD" Issue ===== A traceback appears indicating that the value of the field user_id is missing for the model project.task.stage.personal and the task is not created. Cause ===== In kanban and list views, when the records a grouped by a given field, a key is added in the context when creating a record from one of the resulting categories. This key is of the form: `default_fieldGroupedBy: current_category_value` In the case of the view My Tasks, the records are grouped by their fields personal_stage_type_ids (M2M). Therefore, the key default_personal_stage_type_ids will results in a write in that M2M table when creating the record. But the way personal stages are managed in project is as confusing as it is mindblowing and the M2M table storing the relation between task and personal stages is also the table that store records from the model project.task.stage.personal. And this model also as a field user_id that is required. Therefore at creation of the project.task record with that key, the orm will miss a user_id for the newly created project.task.stage.personal. Fix === The correct way to add/modify a record project.task by setting its personal stage is actually to use the already existing methods of project.task, i.e. _inverse_personal_stage_type_id. Therfore, instead of modifying directly the M2M relation, update the computed M2O field and let the inverse method to the job of personal stage assignment. To do that, the value contained in the context for the M2M relation is copied in the write value of the M2O (personal_stage_type_id) and the key in the context corresponding to the M2M relation is deleted. task-3281005 closes odoo/odoo#119055 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -858,11 +858,17 @@ class Task(models.Model):
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
new_context = dict(self.env.context)
|
||||
default_personal_stage = new_context.pop('default_personal_stage_type_ids', False)
|
||||
self = self.with_context(new_context)
|
||||
|
||||
is_portal_user = self.env.user.has_group('base.group_portal')
|
||||
if is_portal_user:
|
||||
self.check_access_rights('create')
|
||||
default_stage = dict()
|
||||
for vals in vals_list:
|
||||
if default_personal_stage and 'personal_stage_type_id' not in vals:
|
||||
vals['personal_stage_type_id'] = default_personal_stage[0]
|
||||
if not vals.get('name') and vals.get('display_name'):
|
||||
vals['name'] = vals['display_name']
|
||||
if is_portal_user:
|
||||
|
||||
@@ -63,4 +63,18 @@ registry.category("web_tour.tours").add('personal_stage_tour', {
|
||||
}, {
|
||||
content: "Check that column was updated",
|
||||
trigger: '.o_kanban_header:contains("Todo")',
|
||||
}, {
|
||||
content: "Create a personal task from the quick create form",
|
||||
trigger: '.o-kanban-button-new',
|
||||
}, {
|
||||
content: "Create a new personal task",
|
||||
trigger: 'input.o_input',
|
||||
run: 'text New Test Task',
|
||||
}, {
|
||||
content: "Confirm create",
|
||||
trigger: '.o_kanban_add',
|
||||
}, {
|
||||
content: "Check that task exists",
|
||||
trigger: '.o_kanban_record_title:contains("New Test Task")',
|
||||
run: function () {},
|
||||
}]});
|
||||
|
||||
Reference in New Issue
Block a user