[FIX] project: can delete archived project with tasks

Create a Project with tasks, archive it, delete it.

The project is deleted, but this should not happen:
tasks are present, but they are hidden because when the project is
archived all its tasks are archived too (active flag is set to false).
On project unlinking only active tasks are checked, thus allowing the
deletion. Using a context flag to avoid filtering the non active tasks.

opw-2080515

closes odoo/odoo#38320

X-original-commit: 71a79f26e6319c6987397950c7f9df6c61dfb0d9
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2019-10-10 06:28:20 +00:00
committed by fw-bot
parent 421d76b04c
commit a128fb5b03
2 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ class Project(models.Model):
def unlink(self):
# Check project is empty
for project in self:
for project in self.with_context(active_test=False):
if project.tasks:
raise UserError(_('You cannot delete a project containing tasks. You can either archive it or first delete all of its tasks.'))
# Delete the empty related analytic account
+13 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from odoo.tests.common import SavepointCase
from odoo.exceptions import UserError
class TestProjectBase(SavepointCase):
@@ -89,3 +89,15 @@ class TestProjectBase(SavepointCase):
mail = template.format(to=to, subject=subject, cc=cc, extra=extra, email_from=email_from, msg_id=msg_id)
self.env['mail.thread'].with_context(mail_channel_noautofollow=True).message_process(model, mail)
return self.env[target_model].search([(target_field, '=', subject)])
def test_delete_project_with_tasks(self):
"""User should never be able to delete a project with tasks"""
with self.assertRaises(UserError):
self.project_pigs.unlink()
# click on the archive button
self.project_pigs.write({'active': False})
with self.assertRaises(UserError):
self.project_pigs.unlink()