Fill default timesheet work from project relate

We set in the context a specific key to search for project work in
default_work. And the relate fills this context key.

issue7777
review48641002
This commit is contained in:
Cédric Krier
2018-10-25 21:01:10 +02:00
parent 08d23afa74
commit 573cabd6b1
5 changed files with 87 additions and 8 deletions
+2
View File
@@ -1,3 +1,5 @@
* Fill default timesheet work from project relate
Version 5.0.0 - 2018-10-01
* Bug fixes (see mercurial logs for details)
* Remove support for Python 2.7
+5 -4
View File
@@ -2,15 +2,16 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
from .work import *
from .timesheet import *
from . import work
from . import timesheet
from . import party
def register():
Pool.register(
Work,
TimesheetWork,
work.Work,
timesheet.Line,
timesheet.Work,
module='project', type_='model')
Pool.register(
party.PartyReplace,
+53
View File
@@ -129,6 +129,59 @@ class ProjectTestCase(ModuleTestCase):
ProjectWork.delete([p_work])
self.assertEqual(TimesheetWork.search([]), [])
@with_transaction()
def test_timesheet_default_work_empty(self):
"Test timesheet default work with no context"
pool = Pool()
ProjectWork = pool.get('project.work')
TimesheetLine = pool.get('timesheet.line')
company = create_company()
with set_company(company):
p_work = ProjectWork()
p_work.name = "Work"
p_work.timesheet_available = True
p_work.save()
self.assertFalse(TimesheetLine.default_work())
@with_transaction()
def test_timesheet_default_work_single(self):
"Test timesheet default work with 1 work in context"
pool = Pool()
ProjectWork = pool.get('project.work')
TimesheetLine = pool.get('timesheet.line')
company = create_company()
with set_company(company):
p_work = ProjectWork()
p_work.name = "Work"
p_work.timesheet_available = True
p_work.save()
with Transaction().set_context({'project.work': [p_work.id]}):
self.assertEqual(
TimesheetLine.default_work(),
p_work.timesheet_works[0].id)
@with_transaction()
def test_timesheet_default_work_multiple(self):
"Test timesheet default work with multiple work in context"
pool = Pool()
ProjectWork = pool.get('project.work')
TimesheetLine = pool.get('timesheet.line')
company = create_company()
with set_company(company):
works = ProjectWork.create([
{'name': "Work 1", 'timesheet_available': True},
{'name': "Work 2", 'timesheet_available': True},
])
with Transaction().set_context(
{'project.work': map(int, works)}):
self.assertFalse(TimesheetLine.default_work())
def suite():
suite = trytond.tests.test_tryton.suite()
+23 -4
View File
@@ -1,22 +1,41 @@
# 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
from trytond.transaction import Transaction
__all__ = ['TimesheetWork']
class Line(metaclass=PoolMeta):
__name__ = 'timesheet.line'
@classmethod
def default_work(cls):
pool = Pool()
Work = pool.get('timesheet.work')
try:
default = super().default_work()
except AttributeError:
default = None
project_works = Transaction().context.get('project.work')
if project_works is not None:
works = Work.search([
('origin.id', 'in', project_works, 'project.work'),
])
if len(works) == 1:
default = works[0].id
return default
class TimesheetWork(metaclass=PoolMeta):
class Work(metaclass=PoolMeta):
__name__ = 'timesheet.work'
@classmethod
def _get_origin(cls):
return super(TimesheetWork, cls)._get_origin() + ['project.work']
return super()._get_origin() + ['project.work']
def _validate_company(self):
pool = Pool()
ProjectWork = pool.get('project.work')
result = super(TimesheetWork, self)._validate_company()
result = super()._validate_company()
if isinstance(self.origin, ProjectWork):
result &= self.company == self.origin.company
return result
+4
View File
@@ -9,6 +9,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="domain"
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('work.origin.id', '=', Eval('active_id'), 'project.work'), ('work.origin.id', 'in', Eval('active_ids'), 'project.work'))]"
pyson="1"/>
<field
name="context"
eval="{'project.work': Eval('active_ids')}"
pyson="1"/>
</record>
<record model="ir.action.keyword"
id="act_timesheet_line_form_work_keyword1">