Skip to content
Permalink
Browse files

[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 #38270

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information...
agr-odoo committed Oct 9, 2019
1 parent 1210cb7 commit 71a79f26e6319c6987397950c7f9df6c61dfb0d9
Showing with 14 additions and 2 deletions.
  1. +1 −1 addons/project/models/project.py
  2. +13 −1 addons/project/tests/test_project_base.py
@@ -318,7 +318,7 @@ def write(self, vals):

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
@@ -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 @@ def format_and_process(self, template, to='groups@example.com, other@gmail.com',
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()

0 comments on commit 71a79f2

Please sign in to comment.
You can’t perform that action at this time.