diff options
| author | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2019-10-09 07:44:05 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-10 06:28:20 +0000 |
| commit | a128fb5b035725c5eaeca81d2d9f56173c070577 (patch) | |
| tree | 1f7d01c3c292e1fac57fec21c5553a1e41e8d067 /addons | |
| parent | 421d76b04c4fcde05510300767ead999bf0d450c (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/project/models/project.py | 2 | ||||
| -rw-r--r-- | addons/project/tests/test_project_base.py | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/addons/project/models/project.py b/addons/project/models/project.py index ee1c5e9a236..d7d10055c7f 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -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 diff --git a/addons/project/tests/test_project_base.py b/addons/project/tests/test_project_base.py index 8fcc5939185..795834e73c1 100644 --- a/addons/project/tests/test_project_base.py +++ b/addons/project/tests/test_project_base.py @@ -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() |
