changeset 9119aa23dfe9 in modules/project:default details: https://hg.tryton.org/modules/project?cmd=changeset&node=9119aa23dfe9 description: Copy children works and timesheets
issue11525 review435211004 diffstat: tests/test_module.py | 19 +++++++++++++++++++ work.py | 13 +++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diffs (54 lines): diff -r b0d32940a379 -r 9119aa23dfe9 tests/test_module.py --- a/tests/test_module.py Tue May 31 10:13:13 2022 +0200 +++ b/tests/test_module.py Thu Jun 16 14:32:44 2022 +0200 @@ -181,5 +181,24 @@ {'project.work': map(int, works)}): self.assertFalse(TimesheetLine.default_work()) + @with_transaction() + def test_copy_work_with_children(self): + "Test copy work with children" + pool = Pool() + ProjectWork = pool.get('project.work') + + company = create_company() + with set_company(company): + work, = ProjectWork.create([ + {'name': "Parent", 'children': [('create', [ + {'name': "Work 1", 'timesheet_available': True}, + {'name': "Work 2", 'timesheet_available': False}, + ])]}]) + new_work, = ProjectWork.copy([work]) + + child1, child2 = new_work.children + self.assertTrue(child1.timesheet_available) + self.assertFalse(child2.timesheet_available) + del ModuleTestCase diff -r b0d32940a379 -r 9119aa23dfe9 work.py --- a/work.py Tue May 31 10:13:13 2022 +0200 +++ b/work.py Thu Jun 16 14:32:44 2022 +0200 @@ -505,11 +505,20 @@ default = {} else: default = default.copy() - default.setdefault('children', None) default.setdefault('progress', None) default.setdefault( 'status', lambda data: WorkStatus.get_default_status(data['type'])) - return super().copy(project_works, default=default) + new_works = super().copy(project_works, default=default) + to_save = [] + for work, new_work in zip(project_works, new_works): + if work.timesheet_available: + new_work.timesheet_available = work.timesheet_available + new_work.timesheet_start_date = work.timesheet_start_date + new_work.timesheet_end_date = work.timesheet_end_date + to_save.append(new_work) + if to_save: + cls.save(to_save) + return new_works @classmethod def delete(cls, project_works):