Commit b56f67f4 by François C.

Shifts generation modifications (requests and cron)

parent 5bf8985b
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<field name="name">Generate shifts (La Cagette version)</field> <field name="name">Generate shifts (La Cagette version)</field>
<field name="user_id" ref="base.user_root" /> <field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field> <field name="interval_number">1</field>
<field name="interval_type">weeks</field> <field name="interval_type">days</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field name="doall" eval="False"/> <field name="doall" eval="False"/>
<field name="model" eval="'lacagette.shift.template'"/> <field name="model" eval="'lacagette.shift.template'"/>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from openerp import _, api, models, fields from openerp import _, api, models, fields
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import locale
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -105,11 +106,19 @@ class ShiftTemplate(models.Model): ...@@ -105,11 +106,19 @@ class ShiftTemplate(models.Model):
@api.model @api.model
def run_shift_creation(self): def run_shift_creation(self):
# This method is called by the cron task # This method is called by the cron task
locale.setlocale(locale.LC_TIME, 'en_US.UTF-8')
conf = self.env['ir.config_parameter'] conf = self.env['ir.config_parameter']
shift_creation_days = int(conf.get_param("lacagette_membership.shift_creation_days")) shift_creation_days = int(conf.get_param("lacagette_membership.shift_creation_days"))
#templates = self.env['shift.template'].search([('recurrency', '=', True)]) today = datetime.today()
templates = self.env['shift.template'].search([('id', '=', 60)]) futur = today + timedelta(days=shift_creation_days)
filters = [('recurrency', '=', True),
('week_list', '=', today.strftime('%a').upper()[0:2]),
('last_shift_date', '<=', datetime.strftime(futur, "%Y-%m-%d"))]
templates = self.env['shift.template'].search(filters)
# templates = self.env['shift.template'].search([('id', '=', 60)])
for template in templates: for template in templates:
# _logger.info("Shift template = %s", str(template))
self.ng_create_shifts_from_template( instance=template, self.ng_create_shifts_from_template( instance=template,
before=fields.Datetime.to_string( before=fields.Datetime.to_string(
datetime.today() + timedelta(days=shift_creation_days))) datetime.today() + timedelta(days=shift_creation_days)))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment