Browse Source

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

pull/26/head
Thibault Francois 7 years ago
parent
commit
789dc5018f
  1. 15
      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

15
beesdoo_shift/data/cron.xml

@ -1,4 +1,5 @@
<odoo> <odoo>
<data noupdate="1">
<record id="ir_cron_update_today" model="ir.cron"> <record id="ir_cron_update_today" model="ir.cron">
<field name="name">Update Cooperatoor status base on the date</field> <field name="name">Update Cooperatoor status base on the date</field>
<field name="interval_number">24</field> <field name="interval_number">24</field>
@ -9,4 +10,18 @@
<field name="function">_set_today</field> <field name="function">_set_today</field>
<field name="args">()</field> <field name="args">()</field>
</record> </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> </odoo>

8
beesdoo_shift/data/system_parameter.xml

@ -15,4 +15,12 @@
<field name="key">always_update</field> <field name="key">always_update</field>
<field name="value">0</field> <field name="value">0</field>
</record> </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> </odoo>

32
beesdoo_shift/models/planning.py

@ -38,9 +38,39 @@ class DayNumber(models.Model):
class Planning(models.Model): class Planning(models.Model):
_name = 'beesdoo.shift.planning' _name = 'beesdoo.shift.planning'
_order = 'sequence asc'
sequence = fields.Integer()
name = fields.Char() name = fields.Char()
task_template_ids = fields.One2many('beesdoo.shift.template', 'planning_id') 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): class TaskTemplate(models.Model):
_name = 'beesdoo.shift.template' _name = 'beesdoo.shift.template'
@ -120,6 +150,6 @@ class TaskTemplate(models.Model):
'is_regular': True if worker_id else False, 'is_regular': True if worker_id else False,
'start_time' : rec.start_date, 'start_time' : rec.start_date,
'end_time' : rec.end_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 return tasks

19
beesdoo_shift/views/planning.xml

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

Loading…
Cancel
Save