Browse Source

[MIG] b_shift : adapt date objects

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
3bc58ed61e
  1. 4
      beesdoo_shift/models/planning.py
  2. 12
      beesdoo_shift/models/task.py

4
beesdoo_shift/models/planning.py

@ -61,7 +61,9 @@ class Planning(models.Model):
def _generate_next_planning(self): def _generate_next_planning(self):
config = self.env['ir.config_parameter'].sudo() config = self.env['ir.config_parameter'].sudo()
last_seq = int(config.get_param('last_planning_seq', 0)) last_seq = int(config.get_param('last_planning_seq', 0))
date = config.get_param('next_planning_date', 0)
date = fields.Date.from_string(
config.get_param('next_planning_date', 0)
)
planning = self._get_next_planning(last_seq) planning = self._get_next_planning(last_seq)
planning = planning.with_context(visualize_date=date) planning = planning.with_context(visualize_date=date)

12
beesdoo_shift/models/task.py

@ -1,5 +1,5 @@
import json import json
from datetime import datetime, timedelta
from datetime import datetime, time, timedelta
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
@ -132,17 +132,17 @@ class Task(models.Model):
If *now* is given workers are unsubscribed from all shifts starting *now* and later. If *now* is given workers are unsubscribed from all shifts starting *now* and later.
If *now* is given, *end_date* is not taken into account. If *now* is given, *end_date* is not taken into account.
:type today: fields.Date
:type end_date: fields.Date
:type now: fields.Datetime
:type today: date
:type end_date: date
:type now: datetime
""" """
if now: if now:
if len(now) != 19:
if not isinstance(now, datetime):
raise UserError (_("'Now' must be a datetime.")) raise UserError (_("'Now' must be a datetime."))
date_domain = [('start_time', '>', now)] date_domain = [('start_time', '>', now)]
else: else:
today = today or fields.Date.today() today = today or fields.Date.today()
today += ' 00:00:00'
today = datetime.combine(today, time())
date_domain = [('start_time', '>', today)] date_domain = [('start_time', '>', today)]
if end_date: if end_date:
end_date = datetime.combine(end_date,time(hour=23, minute=59, second=59)) end_date = datetime.combine(end_date,time(hour=23, minute=59, second=59))

Loading…
Cancel
Save