From 568fe9134111c08de149ca0d5c2bfcc26e57bec1 Mon Sep 17 00:00:00 2001 From: "Francois (fge)" Date: Tue, 15 Sep 2020 11:15:44 +0000 Subject: [PATCH] [FIX] project: fix various bugs Restore Project Kanban view for mobile. Added a name for the default stage of the tasks in the Internal project Removal of redundancy for the creation of the Internal project and its tasks Fix task_reccurrence for the type 'after'. (too much task created or bad task created) Task-2326258 closes odoo/odoo#64607 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_timesheet/__init__.py | 15 +-------- .../hr_timesheet/data/hr_timesheet_data.xml | 5 +++ addons/hr_timesheet/models/res_company.py | 24 ++++++-------- addons/project/models/project.py | 14 +++++--- .../project/models/project_task_recurrence.py | 2 +- addons/project/views/project_views.xml | 32 ++++++++++++++++++- .../models/res_company.py | 6 ++-- 7 files changed, 61 insertions(+), 37 deletions(-) diff --git a/addons/hr_timesheet/__init__.py b/addons/hr_timesheet/__init__.py index 0fa9235b104..ea15e1da791 100644 --- a/addons/hr_timesheet/__init__.py +++ b/addons/hr_timesheet/__init__.py @@ -19,20 +19,7 @@ def create_internal_project(cr, registry): admin = env.ref('base.user_admin', raise_if_not_found=False) if not admin: return - project_vals = [] - for company in env['res.company'].search([]): - company = company.with_company(company) - project_vals += [{ - 'name': _('Internal'), - 'allow_timesheets': True, - 'company_id': company.id, - 'task_ids': [(0, 0, { - 'name': name, - 'company_id': company.id, - }) for name in [_('Training'), _('Meeting')]] - }] - project_ids = env['project.project'].create(project_vals) - + project_ids = env['res.company'].search([])._create_internal_project_task() env['account.analytic.line'].create([{ 'name': _("Analysis"), 'user_id': admin.id, diff --git a/addons/hr_timesheet/data/hr_timesheet_data.xml b/addons/hr_timesheet/data/hr_timesheet_data.xml index fb2d8e194df..a8ee4d0ab55 100644 --- a/addons/hr_timesheet/data/hr_timesheet_data.xml +++ b/addons/hr_timesheet/data/hr_timesheet_data.xml @@ -24,4 +24,9 @@ 15 + + 1 + Internal + + diff --git a/addons/hr_timesheet/models/res_company.py b/addons/hr_timesheet/models/res_company.py index 429799ec54e..f22d7f9d60f 100644 --- a/addons/hr_timesheet/models/res_company.py +++ b/addons/hr_timesheet/models/res_company.py @@ -48,22 +48,18 @@ class ResCompany(models.Model): def _create_internal_project_task(self): results = [] + type_ids = [(4, self.env.ref('hr_timesheet.internal_project_default_stage').id)] for company in self: company = company.with_company(company) - internal_project = company.env['project.project'].sudo().create({ + results += [{ 'name': _('Internal'), 'allow_timesheets': True, 'company_id': company.id, - }) - - company.env['project.task'].sudo().create([{ - 'name': _('Training'), - 'project_id': internal_project.id, - 'company_id': company.id, - }, { - 'name': _('Meeting'), - 'project_id': internal_project.id, - 'company_id': company.id, - }]) - results.append(internal_project) - return results + 'type_ids': type_ids, + 'task_ids': [(0, 0, { + 'name': name, + 'company_id': company.id, + }) for name in [_('Training'), _('Meeting')]] + }] + project_ids = self.env['project.project'].create(results) + return project_ids diff --git a/addons/project/models/project.py b/addons/project/models/project.py index f8076869dd2..ca53912c012 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -774,7 +774,8 @@ class Task(models.Model): self.recurrence_message = False for task in self.filtered(lambda t: t.recurring_task and t._is_recurrence_valid()): date = fields.Date.today() - number_occurrences = min(5, task.repeat_number if task.repeat_type == 'after' else 5) + recurrence_left = task.recurrence_id.recurrence_left if task.recurrence_id else task.repeat_number + number_occurrences = min(5, recurrence_left if task.repeat_type == 'after' else 5) delta = task.repeat_interval if task.repeat_unit == 'day' else 1 recurring_dates = self.env['project.task.recurrence']._get_next_recurring_dates( date + timedelta(days=delta), @@ -790,10 +791,13 @@ class Task(models.Model): task.repeat_month, count=number_occurrences) date_format = self.env['res.lang']._lang_get(self.env.user.lang).date_format - task.recurrence_message = '