Browse Source

[ADD] cron to generate next planning + [CHANGE] shift generated are already confirmed

pull/105/head
Thibault Francois 7 years ago
committed by Elouan
parent
commit
87341433aa
  1. 35
      beesdoo_shift/data/cron.xml
  2. 8
      beesdoo_shift/data/system_parameter.xml
  3. 32
      beesdoo_shift/models/planning.py
  4. 19
      beesdoo_shift/views/planning.xml

35
beesdoo_shift/data/cron.xml

@ -1,12 +1,27 @@
<odoo>
<record id="ir_cron_update_today" model="ir.cron">
<field name="name">Update Cooperatoor status base on the date</field>
<field name="interval_number">24</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">cooperative.status</field>
<field name="function">_set_today</field>
<field name="args">()</field>
</record>
<data noupdate="1">
<record id="ir_cron_update_today" model="ir.cron">
<field name="name">Update Cooperatoor status base on the date</field>
<field name="interval_number">24</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">cooperative.status</field>
<field name="function">_set_today</field>
<field name="args">()</field>
</record>
<record id="ir_cron_update_today" model="ir.cron">
<field name="name">Generate Next Planning</field>
<field name="interval_number">1</field>
<field name="interval_type">weeks</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">beesdoo.shift.planning</field>
<field name="function">_generate_next_planning</field>
<field name="args">()</field>
<field name="active" eval="False" />
</record>
</data>
</odoo>

8
beesdoo_shift/data/system_parameter.xml

@ -15,4 +15,12 @@
<field name="key">always_update</field>
<field name="value">0</field>
</record>
<record id="last_planning_seq" model="ir.config_parameter">
<field name="key">last_planning_seq</field>
<field name="value">0</field>
</record>
<record id="next_planning_date" model="ir.config_parameter">
<field name="key">next_planning_date</field>
<field name="value">1970-01-01</field>
</record>
</odoo>

32
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

19
beesdoo_shift/views/planning.xml

@ -1,14 +1,4 @@
<odoo>
<record model="ir.ui.view" id="planning_view_tree">
<field name="name">Planning List</field>
<field name="model">beesdoo.shift.planning</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_shift_template">
<field name="name">Planning Action</field>
<field name="res_model">beesdoo.shift.template</field>
@ -32,7 +22,9 @@
<field name="arch" type="xml">
<form>
<header>
<button type="action"
name="%(action_generate_shift_wizard)d"
string="Generate shifts" colspan="2" />
</header>
<sheet>
<div class="oe_button_box" name="button_box">
@ -49,9 +41,7 @@
</h1>
</div>
<group>
<button type="action"
name="%(action_generate_shift_wizard)d"
string="Generate shifts" colspan="2" />
<field name="sequence" />
</group>
</sheet>
</form>
@ -63,6 +53,7 @@
<field name="model">beesdoo.shift.planning</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" />
<field name="name" />
<button type="action" name="%(action_shift_template)d"
string="Shifts Template" />

Loading…
Cancel
Save