| 1 |
from odoo.tests import TransactionCase, tagged |
| 2 |
|
| 3 |
|
| 4 |
@tagged('post_install', '-at_install') |
| 5 |
class TestProjectProjectTemplate(TransactionCase): |
| 6 |
|
| 7 |
def test_template_created_not_having_analytic_account(self): |
| 8 |
template_project, normal_project = self.env["project.project"].create( |
| 9 |
[ |
| 10 |
{ |
| 11 |
"name": "Template Project", |
| 12 |
"is_template": True, |
| 13 |
"allow_timesheets": True, |
| 14 |
}, |
| 15 |
{ |
| 16 |
"name": "Normal Project", |
| 17 |
"is_template": False, |
| 18 |
"allow_timesheets": True, |
| 19 |
}, |
| 20 |
] |
| 21 |
) |
| 22 |
|
| 23 |
self.assertFalse(template_project.account_id, "The template project shouldn't have analytic account") |
| 24 |
self.assertTrue(normal_project.account_id, "A normal project should have a analytic account") |
| 25 |
|
| 26 |
def test_project_created_from_template_to_have_analytic_account(self): |
| 27 |
template_project_timesheet, template_project_no_timesheet = self.env['project.project'].create([ |
| 28 |
{ |
| 29 |
"name": "Template Project Timesheet", |
| 30 |
"is_template": True, |
| 31 |
"allow_timesheets": True, |
| 32 |
}, |
| 33 |
{ |
| 34 |
"name": "Template Project No Timesheet", |
| 35 |
"is_template": True, |
| 36 |
"allow_timesheets": False, |
| 37 |
}, |
| 38 |
]) |
| 39 |
|
| 40 |
new_project_1 = template_project_timesheet.action_create_from_template() |
| 41 |
self.assertTrue(new_project_1.account_id, "A project created from template allowing timesheet should have an analytic account") |
| 42 |
new_project_2 = template_project_no_timesheet.action_create_from_template() |
| 43 |
self.assertFalse(new_project_2.account_id, "A project created from template disabling timesheet should not have an analytic account") |
| 44 |
|
| 45 |
def test_convert_project_template_into_regular_project_analytics(self): |
| 46 |
template_project = self.env["project.project"].create( |
| 47 |
{ |
| 48 |
"name": "Template Project Timesheet", |
| 49 |
"is_template": True, |
| 50 |
"allow_timesheets": True, |
| 51 |
} |
| 52 |
) |
| 53 |
self.assertFalse(template_project.account_id, "The template project shouldn't have analytic account before conversion") |
| 54 |
template_project.action_undo_convert_to_template() |
| 55 |
self.assertFalse(template_project.is_template, "The project should not be a template anymore after conversion") |
| 56 |
self.assertTrue(template_project.account_id, "Converting a template project with timesheets enabled into a regular project should create an analytic account") |