Browse Source

[FIX] Date, datetime and strings conflicts from migration to 12.0

pull/105/head
Elouan Le Bars 5 years ago
parent
commit
eafcadbfcf
  1. 4
      beesdoo_shift/models/cooperative_status.py
  2. 5
      beesdoo_shift/models/planning.py
  3. 22
      beesdoo_shift/models/task.py
  4. 13
      beesdoo_shift/views/task.xml
  5. 1
      beesdoo_shift/views/task_template.xml
  6. 2
      beesdoo_shift/wizard/holiday.py
  7. 4
      beesdoo_shift/wizard/temporary_exemption.py
  8. 6
      beesdoo_website_shift/controllers/main.py
  9. 26
      beesdoo_website_shift/views/my_shift_website_templates.xml

4
beesdoo_shift/models/cooperative_status.py

@ -39,7 +39,7 @@ class CooperativeStatus(models.Model):
cooperator_id = fields.Many2one('res.partner')
active = fields.Boolean(related="cooperator_id.active", store=True, index=True)
info_session = fields.Boolean('Information Session ?')
info_session_date = fields.Datetime('Information Session Date')
info_session_date = fields.Date('Information Session Date')
super = fields.Boolean("Super Cooperative")
sr = fields.Integer("Compteur shift regulier", default=0)
sc = fields.Integer("Compteur shift de compensation", default=0)
@ -420,7 +420,7 @@ class ResPartner(models.Model):
cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True)
super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True)
info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True)
info_session_date = fields.Datetime(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True)
exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True)
state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True)

5
beesdoo_shift/models/planning.py

@ -154,11 +154,12 @@ class TaskTemplate(models.Model):
#remove worker in holiday and temporary exempted
if worker_id and worker_id.cooperative_status_ids:
status = worker_id.cooperative_status_ids[0]
import pdb; pdb.set_trace()
if status.holiday_start_time and status.holiday_end_time and \
status.holiday_start_time <= rec.start_date[:10] and status.holiday_end_time >= rec.end_date[:10]:
status.holiday_start_time <= rec.start_date and status.holiday_end_time >= rec.end_date:
worker_id = False
if status.temporary_exempt_start_date and status.temporary_exempt_end_date and \
status.temporary_exempt_start_date <= rec.start_date[:10] and status.temporary_exempt_end_date >= rec.end_date[:10]:
status.temporary_exempt_start_date <= rec.start_date and status.temporary_exempt_end_date >= rec.end_date:
worker_id = False
tasks |= tasks.create({
'name' : "%s %s (%s - %s) [%s]" % (rec.name, rec.day_nb_id.name, float_to_time(rec.start_time), float_to_time(rec.end_time), i),

22
beesdoo_shift/models/task.py

@ -1,5 +1,8 @@
from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError
from datetime import date, datetime, time, timedelta
import json
class TaskStage(models.Model):
@ -38,7 +41,7 @@ class Task(models.Model):
stage_id = fields.Many2one('beesdoo.shift.stage', required=True, track_visibility='onchange', default=lambda self: self.env.ref('beesdoo_shift.open'))
super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('partner_id.super', '=', True)], track_visibility='onchange')
color = fields.Integer(related="stage_id.color", readonly=True)
# TODO: Maybe is_regular and is_compensation must be merged in a
# TODO: Maybe is_regular and is_compensation have to be merged in a
# selection field as they are mutually exclusive.
is_regular = fields.Boolean(default=False, string="Regular shift")
is_compensation = fields.Boolean(default=False, string="Compensation shift")
@ -105,9 +108,10 @@ class Task(models.Model):
@api.model
def unsubscribe_from_today(self, worker_ids, today=None, end_date=None):
today = today or fields.Date.today()
today += ' 00:00:00'
# Date to Datetime
today = datetime.combine(today, time())
if end_date:
end_date += ' 23:59:59'
end_date = datetime.combine(end_date,time(hour=23, minute=59, second=59))
# date_domain = [('worker_id', 'in', worker_ids), ('start_time', '>=', today)]
date_domain = [('start_time', '>=', today)]
if end_date:
@ -179,20 +183,20 @@ class Task(models.Model):
self.ensure_one()
self._revert()
update = int(self.env['ir.config_parameter'].get_param('always_update', False))
new_stage = self.env['beesdoo.shift.stage'].browse(new_stage)
data = {}
DONE = self.env.ref('beesdoo_shift.done')
ABSENT = self.env.ref('beesdoo_shift.absent')
EXCUSED = self.env.ref('beesdoo_shift.excused')
NECESSITY = self.env.ref('beesdoo_shift.excused_necessity')
if not (self.worker_id or self.replaced_id) and new_stage in (DONE, ABSENT, EXCUSED, NECESSITY):
raise UserError(_("You cannot change to the status %s if the is no worker defined on the shift") % new_stage.name)
if update or not (self.worker_id or self.replaced_id):
return
if self.worker_id.working_mode == 'regular':
if not self.replaced_id: #No replacement case
status = self.worker_id.cooperative_status_ids[0]
@ -206,14 +210,14 @@ class Task(models.Model):
data['sc'] = 1
else:
data['sr'] = 1
if new_stage == ABSENT and not self.replaced_id:
data['sr'] = - 1
if status.sr <= 0:
data['sc'] = -1
if new_stage == ABSENT and self.replaced_id:
data['sr'] = -1
if new_stage == EXCUSED:
data['sr'] = -1

13
beesdoo_shift/views/task.xml

@ -106,13 +106,11 @@
options="{'no_create': True, 'no_open': True}"
domain="[('working_mode', '=', 'regular')]"
attrs="{'invisible': [('working_mode', '!=', 'regular')]}" />
<group>
<field name="is_regular"
attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="is_compensation"
attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="working_mode" invisible="1"/>
</group>
<field name="is_regular"
attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="is_compensation"
attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="working_mode" invisible="1"/>
</group>
<group>
<field name="start_time" />
@ -148,6 +146,7 @@
t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
<div class="o_dropdown_kanban dropdown"
groups="base.group_user">
<!-- Following block raises a warning -->
<a class="dropdown-toggle btn"
data-toggle="dropdown" href="#">
<span class="fa fa-bars fa-lg" />

1
beesdoo_shift/views/task_template.xml

@ -106,6 +106,7 @@
<t t-if="widget.editable">
<div class="o_dropdown_kanban dropdown"
groups="base.group_user">
<!-- Following block raises a warning -->
<a class="dropdown-toggle btn"
data-toggle="dropdown" href="#">
<span class="fa fa-bars fa-lg" />

2
beesdoo_shift/wizard/holiday.py

@ -12,7 +12,7 @@ class Subscribe(models.TransientModel):
def holidays(self):
self = self._check() #maybe a different group
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id.holiday_end_time >= status_id.today:
if status_id.holiday_end_time and status_id.holiday_end_time >= status_id.today:
raise ValidationError(_("You cannot encode new holidays since the previous holidays encoded are not over yet"))
status_id.sudo().write({'holiday_start_time': self.holiday_start_day, 'holiday_end_time': self.holiday_end_day})
self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.holiday_start_day, end_date=self.holiday_end_day)

4
beesdoo_shift/wizard/temporary_exemption.py

@ -13,8 +13,8 @@ class TemporaryExemption(models.TransientModel):
def exempt(self):
self = self._check() #maybe a different group
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id.temporary_exempt_end_date >= status_id.today:
raise ValidationError(_("You cannot encode new temporary exemptuon since the previous one are not over yet"))
if status_id.temporary_exempt_end_date and status_id.temporary_exempt_end_date >= status_id.today:
raise ValidationError(_("You cannot encode new temporary exemption since the previous one are not over yet"))
status_id.sudo().write({
'temporary_exempt_start_date': self.temporary_exempt_start_date,
'temporary_exempt_end_date': self.temporary_exempt_end_date,

6
beesdoo_website_shift/controllers/main.py

@ -34,7 +34,7 @@ class WebsiteShiftController(http.Controller):
def is_user_regular_without_shift(self):
user = request.env['res.users'].browse(request.uid)
return (not user.partner_id.subscribed_shift_ids.id
return (not len(user.partner_id.subscribed_shift_ids)
and self.is_user_regular())
def is_user_exempted(self):
@ -412,11 +412,11 @@ class WebsiteShiftController(http.Controller):
shift.revert_info = main_shift.revert_info
# Set new date
shift.start_time = self.add_days(
main_shift.start_time.to_datetime(),
main_shift.start_time,
days=i * PERIOD
)
shift.end_time = self.add_days(
main_shift.end_time.to_datetime(),
main_shift.end_time,
days=i * PERIOD
)
# Add the fictive shift to the list of shift

26
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -86,12 +86,12 @@
<p t-if="status.holiday_start_time and status.holiday_start_time > status.today or status.status == 'holiday'">
<label for="holiday_start_time">Begin of Holiday:</label>
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(status.holiday_start_time, '%Y-%m-%d'))"/>
<t t-esc="holiday_start_time.strftime('%A %d %B %Y')"/>
</p>
<p t-if="status.holiday_end_time and status.holiday_end_time > status.today or status.status == 'holiday'">
<label for="holiday_end_time">End of Holiday:</label>
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(status.holiday_end_time, '%Y-%m-%d'))"/>
<t t-esc="holiday_end_time.strftime('%A %d %B %Y')"/>
</p>
</template>
@ -173,7 +173,7 @@
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="panel-title">
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A %d %B %Y')"/>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/>
<t t-call="beesdoo_website_shift.shift_status_label">
@ -209,10 +209,10 @@
<t t-foreach="subscribed_shifts" t-as="shift">
<tr t-att-class="'danger text-danger' if shift.stage_id.code == 'cancel' else ''">
<td>
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A')"/>
</td>
<td>
<t t-esc="time.strftime('%d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%d %B %Y')"/>
</td>
<td>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
@ -306,7 +306,7 @@
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="panel-title">
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A %d %B %Y')"/>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/>
<t t-call="beesdoo_website_shift.shift_status_label">
@ -334,10 +334,10 @@
<t t-foreach="past_shifts" t-as="shift">
<tr>
<td>
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A')"/>
</td>
<td>
<t t-esc="time.strftime('%d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%d %B %Y')"/>
</td>
<td>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
@ -385,7 +385,7 @@
<div t-att-class="'panel %s' % highlight_class">
<div class="panel-heading clearfix">
<div class="panel-title pull-left">
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A %d %B %Y')"/>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/>
</div>
@ -431,10 +431,10 @@
<t t-set="has_enough_workers" t-value="shift_count_subscribed[3]"/>
<tr t-attf-class="{{ 'warning' if not has_enough_workers else '' }}">
<td>
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A')"/>
</td>
<td>
<t t-esc="time.strftime('%d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%d %B %Y')"/>
</td>
<td>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
@ -484,8 +484,8 @@
</h4>
</div>
<div class="modal-body">
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="time.strftime('%d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="shift.start_time.strftime('%A')"/>
<t t-esc="shift.start_time.strftime('%d %B %Y')"/>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/><br/>
<t t-esc="shift.task_type_id.name"/><br/>

Loading…
Cancel
Save