| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo import Command |
| 4 |
from odoo.tests import TransactionCase, tagged |
| 5 |
|
| 6 |
|
| 7 |
@tagged('post_install', '-at_install') |
| 8 |
class TestProjectProject(TransactionCase): |
| 9 |
|
| 10 |
def test_create_projects(self): |
| 11 |
""" |
| 12 |
Test creating some projects and check analytic account generated |
| 13 |
|
| 14 |
Test case: |
| 15 |
========= |
| 16 |
- Create 4 projects and 2 of them should have timesheets feature enabled |
| 17 |
- Check the projects with timesheets enabled have an analytic account generated |
| 18 |
""" |
| 19 |
project1, project2, project3, project4 = self.env['project.project'].create([{ |
| 20 |
'name': 'Project 1 (no timesheets)', |
| 21 |
'allow_timesheets': False, |
| 22 |
}, { |
| 23 |
'name': 'Project 2 (timesheets)', |
| 24 |
'allow_timesheets': True, |
| 25 |
}, { |
| 26 |
'name': 'Project 3 (no timesheets)', |
| 27 |
'allow_timesheets': False, |
| 28 |
}, { |
| 29 |
'name': 'Project 4 (timesheets)', |
| 30 |
'allow_timesheets': True, |
| 31 |
}]) |
| 32 |
|
| 33 |
self.assertFalse(project1.account_id, 'Project 1 should not have an analytic account') |
| 34 |
self.assertTrue(project2.account_id, 'Project 2 should have an analytic account') |
| 35 |
self.assertEqual( |
| 36 |
project2.name, |
| 37 |
project2.account_id.name, |
| 38 |
'Project 2 should have the same name as its analytic account' |
| 39 |
) |
| 40 |
self.assertFalse(project3.account_id, 'Project 3 should not have an analytic account') |
| 41 |
self.assertTrue(project4.account_id, 'Project 4 should have an analytic account') |
| 42 |
self.assertEqual( |
| 43 |
project4.name, |
| 44 |
project4.account_id.name, |
| 45 |
'Project 4 should have the same name as its analytic account' |
| 46 |
) |
| 47 |
|
| 48 |
def test_create_projects_with_default_analytic_account(self): |
| 49 |
project_plan_id = int(self.env['ir.config_parameter'].sudo().get_param('analytic.analytic_plan_projects')) |
| 50 |
if not project_plan_id: |
| 51 |
project_plan, _other_plans = self.env['account.analytic.plan']._get_all_plans() |
| 52 |
project_plan_id = project_plan.id |
| 53 |
analytic_account = self.env['account.analytic.account'].create({'name': 'Test Analytic Account', 'plan_id': project_plan_id}) |
| 54 |
project1, project2 = self.env['project.project'].with_context(default_account_id=analytic_account.id).create([{ |
| 55 |
'name': 'Project 1 (no timesheets)', |
| 56 |
'allow_timesheets': False, |
| 57 |
'account_id': analytic_account.id, |
| 58 |
}, { |
| 59 |
'name': 'Project 2 (timesheets)', |
| 60 |
'allow_timesheets': True, |
| 61 |
'account_id': analytic_account.id, |
| 62 |
}]) |
| 63 |
self.assertEqual(project1.account_id, analytic_account, 'Project 1 should have the default analytic account') |
| 64 |
self.assertEqual(project2.account_id, analytic_account, 'Project 2 should have the default analytic account') |
| 65 |
|
| 66 |
def test_compute_total_timesheet_time(self): |
| 67 |
employee = self.env['hr.employee'].create({ |
| 68 |
'name': 'Test Employee', |
| 69 |
}) |
| 70 |
|
| 71 |
project = self.env['project.project'].create({ |
| 72 |
'name': 'Test Project', |
| 73 |
'allocated_hours': 1.0, |
| 74 |
}) |
| 75 |
|
| 76 |
self.env['project.task'].create({ |
| 77 |
'name': 'Test Task', |
| 78 |
'project_id': project.id, |
| 79 |
'timesheet_ids': [ |
| 80 |
Command.create({ |
| 81 |
'name': '/', |
| 82 |
'employee_id': employee.id, |
| 83 |
'unit_amount': 0.5, |
| 84 |
}), |
| 85 |
Command.create({ |
| 86 |
'name': '/', |
| 87 |
'employee_id': employee.id, |
| 88 |
'unit_amount': 0.25, |
| 89 |
}), |
| 90 |
], |
| 91 |
}) |
| 92 |
|
| 93 |
self.assertEqual(project.total_timesheet_time, 0.75, 'The total timesheet time should be 0.75 (00:45) hours.') |