diff --git a/models/calendar.py b/models/calendar.py index e394c9ef37f0831e89960fa0e82e5c6ed6ff54e5..8cd5e2c070d148807b20a2dd026f315c33e1070b 100644 --- a/models/calendar.py +++ b/models/calendar.py @@ -1,8 +1,8 @@ # © 2019 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import pytz from datetime import timedelta +import pytz from odoo import models, fields, api from odoo.fields import Date @@ -29,7 +29,8 @@ class CGScopCalendar(models.Model): def _default_coop_id(self): if self.env.context.get('default_res_model') == 'res.partner': 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 def _default_ur(self): @@ -37,10 +38,10 @@ class CGScopCalendar(models.Model): partner_ids = fields.Many2many(domain=[ ('user_ids', '!=', False)]) - type = fields.Selection([ - ('outside', 'Extérieur'), - ('ur', 'UR'), - ('absent', 'Absence, Congés, Divers')], + type = fields.Selection( + [('outside', 'Extérieur'), + ('ur', 'UR'), + ('absent', 'Absence, Congés, Divers')], string="Type de Réunion") location = fields.Text() coop_id = fields.Many2one( @@ -78,11 +79,11 @@ class CGScopCalendar(models.Model): attendees_initial = fields.Char( string='Initiales Participants', compute='_compute_attendees_initial') - state = fields.Selection([ - ('needsAction', 'Non répondu'), - ('tentative', 'Incertain'), - ('declined', 'Refusé'), - ('accepted', 'Accepté')], + state = fields.Selection( + [('needsAction', 'Non répondu'), + ('tentative', 'Incertain'), + ('declined', 'Refusé'), + ('accepted', 'Accepté')], string='Statut', compute='_compute_attendee_state', help="Statut du participant", @@ -118,7 +119,8 @@ class CGScopCalendar(models.Model): for event in self: initials = '' for partner in event.partner_ids: - initials += partner.lastname[0] + '.' + partner.firstname[0] + ', ' + initials += (partner.lastname[0] + '.' + partner.firstname[0] + + ', ') event.attendees_initial = initials def _compute_attendee_state(self): @@ -176,7 +178,8 @@ class CGScopCalendar(models.Model): self.ur_financial_system_id = self.coop_id.ur_financial_system_id if not self.coop_id.ur_regional_convention_date or \ 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 @@ -279,9 +282,11 @@ class CGScopCalendar(models.Model): for i in range((event.stop - event.start).days + 1): values['date'] = event.start + timedelta(days=i) 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}) - # 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: user_tz = self.env.user.tz local = pytz.timezone(user_tz) @@ -295,7 +300,8 @@ class CGScopCalendar(models.Model): start_tz = fields.Datetime.context_timestamp( record=self.env.user, 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 # si dernier jour elif i == (event.stop - event.start).days: @@ -304,13 +310,15 @@ class CGScopCalendar(models.Model): stop_tz = fields.Datetime.context_timestamp( record=self.env.user, 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 else: hours = 8.0 values['date'] = day 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}) # Gestion des évènements classiques else: @@ -353,33 +361,34 @@ class CGScopCalendar(models.Model): """ Surcharge la fonction read de calendar pour gérer le transfert des 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' """ if not fields: fields = list(self._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: if fields and (f not in fields): fields2.append(f) 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_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) - # print("real_data") - # print(real_data) - # print(real_events) - # print(select) result = [] for calendar_id, real_id in select: if not real_data.get(real_id): continue 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) - if not isinstance(ls, (pycompat.string_types, pycompat.integer_types)) and len(ls) >= 2: + ls = calendar_id2real_id(calendar_id, with_date=res + 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['stop'] = ls[2] @@ -391,7 +400,8 @@ class CGScopCalendar(models.Model): res['stop_datetime'] = ls[2] 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([ ('event_id', '=', ls[0]), @@ -409,21 +419,29 @@ class CGScopCalendar(models.Model): for r in result: 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 - 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 if r['privacy'] == 'private': for f in r: 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 isinstance(r[f], list): r[f] = [] else: r[f] = False if f == 'name': - r[f] = _('Busy') + r[f] = ('Busy') for r in result: for k in EXTRAFIELDS: