From 87341433aa84f4f880186a42e48ab85d1ca11e27 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Mon, 16 Oct 2017 22:59:21 +0200 Subject: [PATCH] [ADD] cron to generate next planning + [CHANGE] shift generated are already confirmed --- beesdoo_shift/data/cron.xml | 35 ++++++++++++++++++------- beesdoo_shift/data/system_parameter.xml | 8 ++++++ beesdoo_shift/models/planning.py | 32 +++++++++++++++++++++- beesdoo_shift/views/planning.xml | 19 ++++---------- 4 files changed, 69 insertions(+), 25 deletions(-) diff --git a/beesdoo_shift/data/cron.xml b/beesdoo_shift/data/cron.xml index f534dc2..9b94c34 100644 --- a/beesdoo_shift/data/cron.xml +++ b/beesdoo_shift/data/cron.xml @@ -1,12 +1,27 @@ - - Update Cooperatoor status base on the date - 24 - hours - -1 - - cooperative.status - _set_today - () - + + + Update Cooperatoor status base on the date + 24 + hours + -1 + + cooperative.status + _set_today + () + + + + + Generate Next Planning + 1 + weeks + -1 + + beesdoo.shift.planning + _generate_next_planning + () + + + \ No newline at end of file diff --git a/beesdoo_shift/data/system_parameter.xml b/beesdoo_shift/data/system_parameter.xml index 1aef808..cc5a4ec 100644 --- a/beesdoo_shift/data/system_parameter.xml +++ b/beesdoo_shift/data/system_parameter.xml @@ -15,4 +15,12 @@ always_update 0 + + last_planning_seq + 0 + + + next_planning_date + 1970-01-01 + \ No newline at end of file diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py index 18a4781..0e0e95b 100644 --- a/beesdoo_shift/models/planning.py +++ b/beesdoo_shift/models/planning.py @@ -38,9 +38,39 @@ class DayNumber(models.Model): class Planning(models.Model): _name = 'beesdoo.shift.planning' + _order = 'sequence asc' + + sequence = fields.Integer() name = fields.Char() task_template_ids = fields.One2many('beesdoo.shift.template', 'planning_id') + @api.model + def _get_next_planning(self, sequence): + next_planning = self.search([('sequence', '>', sequence)]) + if not next_planning: + return self.search([])[0] + return next_planning[0] + + @api.multi + def _get_next_planning_date(self, date): + self.ensure_one() + nb_of_day = max(self.task_template_ids.mapped('day_nb_id.number')) + return fields.Date.to_string(fields.Date.from_string(date) + timedelta(days=nb_of_day)) + + @api.model + def _generate_next_planning(self): + config = self.env['ir.config_parameter'] + last_seq = int(config.get_param('last_planning_seq', 0)) + date = config.get_param('next_planning_date', 0) + + planning = self._get_next_planning(last_seq) + planning = planning.with_context(visualize_date=date) + planning.task_template_ids._generate_task_day() + + next_date = planning._get_next_planning_date(date) + config.set_param('last_planning_seq', planning.sequence) + config.set_param('next_planning_date', next_date) + class TaskTemplate(models.Model): _name = 'beesdoo.shift.template' @@ -120,6 +150,6 @@ class TaskTemplate(models.Model): 'is_regular': True if worker_id else False, 'start_time' : rec.start_date, 'end_time' : rec.end_date, - 'stage_id': self.env.ref('beesdoo_shift.draft').id, + 'stage_id': self.env.ref('beesdoo_shift.open').id, }) return tasks \ No newline at end of file diff --git a/beesdoo_shift/views/planning.xml b/beesdoo_shift/views/planning.xml index 3a644d0..f7326b5 100644 --- a/beesdoo_shift/views/planning.xml +++ b/beesdoo_shift/views/planning.xml @@ -1,14 +1,4 @@ - - Planning List - beesdoo.shift.planning - - - - - - - Planning Action beesdoo.shift.template @@ -32,7 +22,9 @@
- +
@@ -49,9 +41,7 @@
-