Skip to content
Snippets Groups Projects
Commit b609b429 authored by Rémi - Le Filament's avatar Rémi - Le Filament
Browse files

[enh] Fix code layout and typos

parent a316de6a
No related branches found
No related tags found
No related merge requests found
# © 2019 Le Filament (<http://www.le-filament.com>) # © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import pytz
from datetime import timedelta from datetime import timedelta
import pytz
from odoo import models, fields, api from odoo import models, fields, api
from odoo.fields import Date from odoo.fields import Date
...@@ -29,7 +29,8 @@ class CGScopCalendar(models.Model): ...@@ -29,7 +29,8 @@ class CGScopCalendar(models.Model):
def _default_coop_id(self): def _default_coop_id(self):
if self.env.context.get('default_res_model') == 'res.partner': if self.env.context.get('default_res_model') == 'res.partner':
if self.env.context.get('default_res_id'): if self.env.context.get('default_res_id'):
return self.env['res.partner'].browse(self.env.context.get('default_res_id')) return self.env['res.partner'].browse(
self.env.context.get('default_res_id'))
return False return False
def _default_ur(self): def _default_ur(self):
...@@ -37,8 +38,8 @@ class CGScopCalendar(models.Model): ...@@ -37,8 +38,8 @@ class CGScopCalendar(models.Model):
partner_ids = fields.Many2many(domain=[ partner_ids = fields.Many2many(domain=[
('user_ids', '!=', False)]) ('user_ids', '!=', False)])
type = fields.Selection([ type = fields.Selection(
('outside', 'Extérieur'), [('outside', 'Extérieur'),
('ur', 'UR'), ('ur', 'UR'),
('absent', 'Absence, Congés, Divers')], ('absent', 'Absence, Congés, Divers')],
string="Type de Réunion") string="Type de Réunion")
...@@ -78,8 +79,8 @@ class CGScopCalendar(models.Model): ...@@ -78,8 +79,8 @@ class CGScopCalendar(models.Model):
attendees_initial = fields.Char( attendees_initial = fields.Char(
string='Initiales Participants', string='Initiales Participants',
compute='_compute_attendees_initial') compute='_compute_attendees_initial')
state = fields.Selection([ state = fields.Selection(
('needsAction', 'Non répondu'), [('needsAction', 'Non répondu'),
('tentative', 'Incertain'), ('tentative', 'Incertain'),
('declined', 'Refusé'), ('declined', 'Refusé'),
('accepted', 'Accepté')], ('accepted', 'Accepté')],
...@@ -118,7 +119,8 @@ class CGScopCalendar(models.Model): ...@@ -118,7 +119,8 @@ class CGScopCalendar(models.Model):
for event in self: for event in self:
initials = '' initials = ''
for partner in event.partner_ids: for partner in event.partner_ids:
initials += partner.lastname[0] + '.' + partner.firstname[0] + ', ' initials += (partner.lastname[0] + '.' + partner.firstname[0]
+ ', ')
event.attendees_initial = initials event.attendees_initial = initials
def _compute_attendee_state(self): def _compute_attendee_state(self):
...@@ -176,7 +178,8 @@ class CGScopCalendar(models.Model): ...@@ -176,7 +178,8 @@ class CGScopCalendar(models.Model):
self.ur_financial_system_id = self.coop_id.ur_financial_system_id self.ur_financial_system_id = self.coop_id.ur_financial_system_id
if not self.coop_id.ur_regional_convention_date or \ if not self.coop_id.ur_regional_convention_date or \
fields.Datetime.now() > self.coop_id.ur_regional_convention_date: fields.Datetime.now() > self.coop_id.ur_regional_convention_date:
self.ur_regional_convention_id = self.coop_id.ur_regional_convention_id self.ur_regional_convention_id = self.coop_id.\
ur_regional_convention_id
# ------------------------------------------------------ # ------------------------------------------------------
# Contrains # Contrains
...@@ -279,9 +282,11 @@ class CGScopCalendar(models.Model): ...@@ -279,9 +282,11 @@ class CGScopCalendar(models.Model):
for i in range((event.stop - event.start).days + 1): for i in range((event.stop - event.start).days + 1):
values['date'] = event.start + timedelta(days=i) values['date'] = event.start + timedelta(days=i)
values['unit_amount'] = 8.0 values['unit_amount'] = 8.0
ts = self.env['account.analytic.line'].create(values) ts = self.env['account.analytic.line'].create(
values)
attendee.write({'timesheet_id': ts.id}) attendee.write({'timesheet_id': ts.id})
# Gestion des évènements sur plusieurs jours non flagués allday # Gestion des évènements sur plusieurs jours non flagués
# allday
elif (event.stop - event.start).days > 0: elif (event.stop - event.start).days > 0:
user_tz = self.env.user.tz user_tz = self.env.user.tz
local = pytz.timezone(user_tz) local = pytz.timezone(user_tz)
...@@ -295,7 +300,8 @@ class CGScopCalendar(models.Model): ...@@ -295,7 +300,8 @@ class CGScopCalendar(models.Model):
start_tz = fields.Datetime.context_timestamp( start_tz = fields.Datetime.context_timestamp(
record=self.env.user, record=self.env.user,
timestamp=event.start) timestamp=event.start)
hours_cal = (end_day_tz - start_tz).seconds//3600 hours_cal = ((end_day_tz - start_tz).seconds
// 3600)
hours = hours_cal if hours_cal <= 8 else 8.0 hours = hours_cal if hours_cal <= 8 else 8.0
# si dernier jour # si dernier jour
elif i == (event.stop - event.start).days: elif i == (event.stop - event.start).days:
...@@ -304,13 +310,15 @@ class CGScopCalendar(models.Model): ...@@ -304,13 +310,15 @@ class CGScopCalendar(models.Model):
stop_tz = fields.Datetime.context_timestamp( stop_tz = fields.Datetime.context_timestamp(
record=self.env.user, record=self.env.user,
timestamp=event.stop) timestamp=event.stop)
hours_cal = (stop_tz - start_day_tz).seconds//3600 hours_cal = ((stop_tz - start_day_tz).seconds
// 3600)
hours = hours_cal if hours_cal <= 8 else 8.0 hours = hours_cal if hours_cal <= 8 else 8.0
else: else:
hours = 8.0 hours = 8.0
values['date'] = day values['date'] = day
values['unit_amount'] = hours values['unit_amount'] = hours
ts = self.env['account.analytic.line'].create(values) ts = self.env['account.analytic.line'].create(
values)
attendee.write({'timesheet_id': ts.id}) attendee.write({'timesheet_id': ts.id})
# Gestion des évènements classiques # Gestion des évènements classiques
else: else:
...@@ -353,33 +361,34 @@ class CGScopCalendar(models.Model): ...@@ -353,33 +361,34 @@ class CGScopCalendar(models.Model):
""" Surcharge la fonction read de calendar pour gérer le transfert des """ Surcharge la fonction read de calendar pour gérer le transfert des
lignes de temps sur les virtual events. lignes de temps sur les virtual events.
Ajoute le calcul de la valeur du champs 'is_tansfered' dans la Ajoute le calcul de la valeur du champs 'is_transfered' dans la
boucle 'for calendar_id, real_id in select' boucle 'for calendar_id, real_id in select'
""" """
if not fields: if not fields:
fields = list(self._fields) fields = list(self._fields)
fields2 = fields and fields[:] fields2 = fields and fields[:]
EXTRAFIELDS = ('privacy', 'user_id', 'duration', 'allday', 'start', 'rrule') EXTRAFIELDS = ('privacy', 'user_id', 'duration', 'allday', 'start',
'rrule')
for f in EXTRAFIELDS: for f in EXTRAFIELDS:
if fields and (f not in fields): if fields and (f not in fields):
fields2.append(f) fields2.append(f)
select = [(x, calendar_id2real_id(x)) for x in self.ids] select = [(x, calendar_id2real_id(x)) for x in self.ids]
real_events = self.browse([real_id for calendar_id, real_id in select]) real_events = self.browse([real_id for calendar_id, real_id in select])
real_data = super(CGScopCalendar, real_events).read(fields=fields2, load=load) real_data = super(CGScopCalendar, real_events).read(fields=fields2,
load=load)
real_data = dict((d['id'], d) for d in real_data) real_data = dict((d['id'], d) for d in real_data)
# print("real_data")
# print(real_data)
# print(real_events)
# print(select)
result = [] result = []
for calendar_id, real_id in select: for calendar_id, real_id in select:
if not real_data.get(real_id): if not real_data.get(real_id):
continue continue
res = real_data[real_id].copy() res = real_data[real_id].copy()
ls = calendar_id2real_id(calendar_id, with_date=res and res.get('duration', 0) > 0 and res.get('duration') or 1) ls = calendar_id2real_id(calendar_id, with_date=res
if not isinstance(ls, (pycompat.string_types, pycompat.integer_types)) and len(ls) >= 2: and res.get('duration', 0) > 0
and res.get('duration') or 1)
if not isinstance(ls, (pycompat.string_types,
pycompat.integer_types)) and len(ls) >= 2:
res['start'] = ls[1] res['start'] = ls[1]
res['stop'] = ls[2] res['stop'] = ls[2]
...@@ -391,7 +400,8 @@ class CGScopCalendar(models.Model): ...@@ -391,7 +400,8 @@ class CGScopCalendar(models.Model):
res['stop_datetime'] = ls[2] res['stop_datetime'] = ls[2]
if 'display_time' in fields: if 'display_time' in fields:
res['display_time'] = self._get_display_time(ls[1], ls[2], res['duration'], res['allday']) res['display_time'] = self._get_display_time(
ls[1], ls[2], res['duration'], res['allday'])
attendee = self.env['calendar.attendee'].search([ attendee = self.env['calendar.attendee'].search([
('event_id', '=', ls[0]), ('event_id', '=', ls[0]),
...@@ -409,21 +419,29 @@ class CGScopCalendar(models.Model): ...@@ -409,21 +419,29 @@ class CGScopCalendar(models.Model):
for r in result: for r in result:
if r['user_id']: if r['user_id']:
user_id = type(r['user_id']) in (tuple, list) and r['user_id'][0] or r['user_id'] user_id = (type(r['user_id']) in (tuple, list)
and r['user_id'][0] or r['user_id'])
partner_id = self.env.user.partner_id.id partner_id = self.env.user.partner_id.id
if user_id == self.env.user.id or partner_id in r.get("partner_ids", []): if user_id == (self.env.user.id
or partner_id in r.get("partner_ids", [])):
continue continue
if r['privacy'] == 'private': if r['privacy'] == 'private':
for f in r: for f in r:
recurrent_fields = self._get_recurrent_fields() recurrent_fields = self._get_recurrent_fields()
public_fields = list(set(recurrent_fields + ['id', 'allday', 'start', 'stop', 'display_start', 'display_stop', 'duration', 'user_id', 'state', 'interval', 'count', 'recurrent_id_date', 'rrule'])) public_fields = list(set(recurrent_fields
+ ['id', 'allday', 'start',
'stop', 'display_start',
'display_stop', 'duration',
'user_id', 'state', 'interval',
'count', 'recurrent_id_date',
'rrule']))
if f not in public_fields: if f not in public_fields:
if isinstance(r[f], list): if isinstance(r[f], list):
r[f] = [] r[f] = []
else: else:
r[f] = False r[f] = False
if f == 'name': if f == 'name':
r[f] = _('Busy') r[f] = ('Busy')
for r in result: for r in result:
for k in EXTRAFIELDS: for k in EXTRAFIELDS:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment