From f1fff63d302ff1ac00682d3fa6a9743a056e5fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 24 Jun 2016 09:29:57 +0200 Subject: [PATCH] Use origin on timesheet work and make timesheet available editable issue5599 review25361002 --- CHANGELOG | 3 + __init__.py | 2 + doc/index.rst | 2 +- tests/test_project.py | 60 ++++++++----------- timesheet.py | 23 ++++++++ view/work_form.xml | 7 ++- view/work_list_simple.xml | 1 - work.py | 120 ++++++++++++++++++++++++++++---------- 8 files changed, 147 insertions(+), 71 deletions(-) create mode 100644 timesheet.py diff --git a/CHANGELOG b/CHANGELOG index 3fd4af3cf8..1d9a812c1c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Use origin on Timesheet Work +* Make timesheet available editable + Version 4.0.0 - 2016-05-02 * Bug fixes (see mercurial logs for details) * Add Python3 support diff --git a/__init__.py b/__init__.py index 46c526f9be..4be0f8e9b7 100644 --- a/__init__.py +++ b/__init__.py @@ -3,9 +3,11 @@ from trytond.pool import Pool from .work import * +from .timesheet import * def register(): Pool.register( Work, + TimesheetWork, module='project', type_='model') diff --git a/doc/index.rst b/doc/index.rst index 2f1841b328..901c272684 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -14,13 +14,13 @@ be split. The following fields are defined on the model: - Name: The name of the Project/Task. -- Work: The linked timesheet work. - Type: Can be *Project* or *Task*. - State: Can be *Opened* or *Done*. - Parent and Children: Define the tree structure of projects and tasks. - Party and Party Address: The optional party (and the contact address) for which the project is made. Available on projects. +- Timesheet Available: Register the work for timesheets. - Effort: The estimated effort of a task. - Total Effort: Available on projects. Gives the total effort of the sub-tasks (I.E. tasks of the project and tasks of the sub-projects) diff --git a/tests/test_project.py b/tests/test_project.py index 0be88ea52c..fe0d90bd69 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -18,84 +18,48 @@ class ProjectTestCase(ModuleTestCase): def test_sum_tree(self): 'Test sum_tree' pool = Pool() - TimesheetWork = pool.get('timesheet.work') ProjectWork = pool.get('project.work') company = create_company() with set_company(company): - t_work_1, = TimesheetWork.create([{ - 'name': 'Work 1', - 'company': company.id, - }]) p_work_1, = ProjectWork.create([{ 'name': 'Work 1', 'company': company.id, - 'work': t_work_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) - t_work_1_1, = TimesheetWork.create([{ - 'name': 'Work 1 1', - 'company': company.id, - 'parent': t_work_1.id, - }]) p_work_1_1, = ProjectWork.create([{ 'name': 'Work 1 1', 'company': company.id, 'parent': p_work_1.id, - 'work': t_work_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) - t_work_1_2, = TimesheetWork.create([{ - 'name': 'Work 1 1', - 'company': company.id, - 'parent': t_work_1.id, - }]) p_work_1_2, = ProjectWork.create([{ 'name': 'Work 1 2', 'company': company.id, 'parent': p_work_1.id, - 'work': t_work_1_2.id, 'effort_duration': datetime.timedelta(hours=1), }]) - t_work_1_1_1, = TimesheetWork.create([{ - 'name': 'Work 1 1 1', - 'company': company.id, - 'parent': t_work_1_1.id, - }]) p_work_1_1_1, = ProjectWork.create([{ 'name': 'Work 1 1 1', 'company': company.id, 'parent': p_work_1_1.id, - 'work': t_work_1_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) - t_work_1_1_2, = TimesheetWork.create([{ - 'name': 'Work 1 1 2', - 'company': company.id, - 'parent': t_work_1_1.id, - }]) p_work_1_1_2, = ProjectWork.create([{ 'name': 'Work 1 1 2', 'company': company.id, 'parent': p_work_1_1.id, - 'work': t_work_1_1_2.id, 'effort_duration': datetime.timedelta(hours=1), }]) - t_work_1_1_3, = TimesheetWork.create([{ - 'name': 'Work 1 1 3', - 'company': company.id, - 'parent': t_work_1_1.id, - }]) p_work_1_1_3, = ProjectWork.create([{ 'name': 'Work 1 1 3', 'company': company.id, 'parent': p_work_1_1.id, - 'work': t_work_1_1_3.id, 'effort_duration': datetime.timedelta(hours=1), }]) @@ -110,6 +74,30 @@ class ProjectTestCase(ModuleTestCase): self.assertEqual(work.total_effort, datetime.timedelta(hours=total_effort)) + @with_transaction() + def test_timesheet_available(self): + 'Test timesheet available' + pool = Pool() + ProjectWork = pool.get('project.work') + + company = create_company() + with set_company(company): + p_work = ProjectWork() + p_work.name = 'Project Work' + p_work.save() + + self.assertFalse(p_work.timesheet_works) + + p_work.timesheet_available = True + p_work.save() + + self.assertEqual(len(p_work.timesheet_works), 1) + + p_work.timesheet_available = False + p_work.save() + + self.assertFalse(p_work.timesheet_works) + def suite(): suite = trytond.tests.test_tryton.suite() diff --git a/timesheet.py b/timesheet.py new file mode 100644 index 0000000000..b8181907af --- /dev/null +++ b/timesheet.py @@ -0,0 +1,23 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.pool import PoolMeta, Pool + + +__all__ = ['TimesheetWork'] + + +class TimesheetWork: + __metaclass__ = PoolMeta + __name__ = 'timesheet.work' + + @classmethod + def _get_origin(cls): + return super(TimesheetWork, cls)._get_origin() + ['project.work'] + + def _validate_company(self): + pool = Pool() + ProjectWork = pool.get('project.work') + result = super(TimesheetWork, self)._validate_company() + if isinstance(self.origin, ProjectWork): + result &= self.company == self.origin.company + return result diff --git a/view/work_form.xml b/view/work_form.xml index 6481bbd43e..b520c0182c 100644 --- a/view/work_form.xml +++ b/view/work_form.xml @@ -18,11 +18,12 @@ this repository contains the full copyright notices and license terms. --> -