[FIX] project: resolving validation error in quick create
Steps: - Open Project - Go to Tasks > My Tasks or All Tasks - Create New Task - Create Project from Quick Create - Clicking on Save, will give a Validation Error Issue: - Validation Error is raised and thus, we aren't able to add the project and thus creating a task. Cause: - Due to the addition of context, the default_type_ids isn't obtained, and thus the SQL error occurs as the name of the task stage isn't set which is a mandatory field. Fix: - removing the context from the form view of Quick Create and set the stage closes odoo/odoo#145599 Task: 3378510 X-original-commit: 83119d5de49ae69d08a0f798453d9c5c56b2276a Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
committed by
mash
parent
8114099ce7
commit
74c80cee6c
@@ -830,6 +830,15 @@ class Task(models.Model):
|
||||
if field not in self.SELF_WRITABLE_FIELDS:
|
||||
raise AccessError(_('You have not write access of %s field.', field))
|
||||
|
||||
def _set_stage_on_project_from_task(self):
|
||||
stage_ids_per_project = defaultdict(list)
|
||||
for task in self:
|
||||
if task.stage_id and task.stage_id not in task.project_id.type_ids and task.stage_id.id not in stage_ids_per_project[task.project_id]:
|
||||
stage_ids_per_project[task.project_id].append(task.stage_id.id)
|
||||
|
||||
for project, stage_ids in stage_ids_per_project.items():
|
||||
project.write({'type_ids': [Command.link(stage_id) for stage_id in stage_ids]})
|
||||
|
||||
def _load_records_create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
if vals.get('recurring_task'):
|
||||
@@ -840,13 +849,6 @@ class Task(models.Model):
|
||||
if project_id:
|
||||
self = self.with_context(default_project_id=project_id)
|
||||
tasks = super()._load_records_create(vals_list)
|
||||
stage_ids_per_project = defaultdict(list)
|
||||
for task in tasks:
|
||||
if task.stage_id and task.stage_id not in task.project_id.type_ids and task.stage_id.id not in stage_ids_per_project[task.project_id]:
|
||||
stage_ids_per_project[task.project_id].append(task.stage_id.id)
|
||||
|
||||
for project, stage_ids in stage_ids_per_project.items():
|
||||
project.write({'type_ids': [Command.link(stage_id) for stage_id in stage_ids]})
|
||||
|
||||
return tasks
|
||||
|
||||
@@ -943,6 +945,8 @@ class Task(models.Model):
|
||||
# if the portal user could really create the tasks based on the ir rule.
|
||||
tasks.with_user(self.env.user).check_access_rule('create')
|
||||
current_partner = self.env.user.partner_id
|
||||
if tasks.project_id:
|
||||
tasks._set_stage_on_project_from_task()
|
||||
for task in tasks:
|
||||
if task.project_id.privacy_visibility == 'portal':
|
||||
task._portal_ensure_token()
|
||||
|
||||
@@ -58,3 +58,14 @@ class TestProjectTaskQuickCreate(TestProjectCommon):
|
||||
task = task_form.save()
|
||||
results = (task.name, len(task.tag_ids), len(task.user_ids), task.priority, task.allocated_hours)
|
||||
self.assertEqual(results, (expression, 0, 0, '0', 0))
|
||||
|
||||
def test_set_stage_on_project_from_task(self):
|
||||
new_stage = self.env['project.task.type'].create({
|
||||
'name': 'New Stage',
|
||||
})
|
||||
self.env['project.task'].create({
|
||||
'name': 'Test Task',
|
||||
'stage_id': new_stage.id,
|
||||
'project_id': self.project_pigs.id,
|
||||
})
|
||||
self.assertEqual(self.project_pigs.type_ids, new_stage, "Task stage is not set in project")
|
||||
|
||||
@@ -507,7 +507,6 @@
|
||||
placeholder="Private"
|
||||
class="o_project_task_project_field"
|
||||
domain="[('type_ids', 'in', context['default_stage_id'])] if context.get('default_stage_id') else []"
|
||||
context="{'default_type_ids': [(4, context.get('default_stage_id', False))]}"
|
||||
/>
|
||||
<field name="user_ids" options="{'no_open': True, 'no_quick_create': True}" domain="[('share', '=', False), ('active', '=', True)]"
|
||||
widget="many2many_avatar_user"/>
|
||||
|
||||
Reference in New Issue
Block a user