Beispiel #1
0
 def button_group_description(self):
     tz = self.env.user.tz
     for line in self:
         description = u'{}-{}'.format(line.order_id.name, line.sequence)
         if line.courses:
             description += '-' + line.courses
         if line.monday:
             description += '-' + _('Monday')
         if line.tuesday:
             description += '-' + _('Tuesday')
         if line.wednesday:
             description += '-' + _('Wednesday')
         if line.thursday:
             description += '-' + _('Thursday')
         if line.friday:
             description += '-' + _('Friday')
         if line.saturday:
             description += '-' + _('Saturday')
         if line.sunday:
             description += '-' + _('Sunday')
         if line.product_id.recurring_service:
             utc_dt = _convert_to_utc_date(line.start_date, line.start_hour,
                                           tz)
             local = _convert_to_local_date(utc_dt, tz)
             description += '-' + str(local)[11:16]
             utc_dt = _convert_to_utc_date(line.end_date, line.end_hour, tz)
             local = _convert_to_local_date(utc_dt, tz)
             description += '-' + str(local)[11:16]
         line.group_description = description
Beispiel #2
0
 def _prepare_session_data_from_sale_line(self, event, num_session, line,
                                          date):
     vals = super(SaleOrder, self)._prepare_session_data_from_sale_line(
         event, num_session, line, date)
     vals['name'] = (_('Session %s for %s') %
                     (str(num_session), line.session_description))
     new_date = False
     if line.order_id.project_id:
         new_date = _convert_to_utc_date(
             date,
             time=line.order_id.project_id.start_time,
             tz=self.env.user.tz)
         duration = (line.order_id.project_id.end_time -
                     line.order_id.project_id.start_time)
         if line.order_id.project_id.working_hours:
             from_date = _convert_to_local_date(date, self.env.user.tz)
             day = str(from_date.date().weekday())
             lines = line.order_id.project_id.working_hours.attendance_ids
             for line2 in lines:
                 if line2.dayofweek == day:
                     new_date = _convert_to_utc_date(date,
                                                     time=line2.hour_from,
                                                     tz=self.env.user.tz)
                     duration = line2.hour_to - line2.hour_from
     if line.start_hour or line.end_hour:
         new_date = _convert_to_utc_date(date,
                                         time=line.start_hour,
                                         tz=self.env.user.tz)
         duration = line.end_hour - line.start_hour
     if new_date:
         vals.update({'date': new_date, 'duration': duration})
     return vals
 def revert_dates(self):
     tz = self.env.user.tz
     super(WizEventDeleteAssistant, self).revert_dates()
     self.start_time = _convert_time_to_float(_convert_to_utc_date(
         self.min_from_date, tz=tz), tz=tz)
     self.end_time = _convert_time_to_float(_convert_to_utc_date(
         self.max_to_date, tz=tz), tz=tz)
Beispiel #4
0
 def _prepare_dates_for_registration(self, line):
     tz = self.env.user.tz
     vals = {
         'event_id': line.event.id,
         'partner_id': line.employee.address_home_id.id,
         'replaces_to': self.holiday.employee_id.address_home_id.id
     }
     start_time = _convert_time_to_float(line.event.date_begin, tz=tz)
     vals['date_start'] = max(
         _convert_to_utc_date(_convert_to_local_date(line.event.date_begin,
                                                     tz=tz).date(),
                              start_time,
                              tz=tz),
         _convert_to_utc_date(_convert_to_local_date(self.holiday.date_from,
                                                     tz=tz).date(),
                              start_time,
                              tz=tz))
     end_time = _convert_time_to_float(line.event.date_end, tz=tz)
     vals['date_end'] = min(
         _convert_to_utc_date(_convert_to_local_date(line.event.date_end,
                                                     tz=tz).date(),
                              end_time,
                              tz=tz),
         _convert_to_utc_date(_convert_to_local_date(self.holiday.date_to,
                                                     tz=tz).date(),
                              end_time,
                              tz=tz))
     return vals
 def button_substitution_employee(self):
     registration_obj = self.env['event.registration']
     tz = self.env.user.tz
     self.ensure_one()
     for line in self.lines:
         vals = {
             'event_id': line.event.id,
             'partner_id': line.employee.address_home_id.id,
             'replaces_to': self.holiday.employee_id.address_home_id.id
         }
         event_date = _convert_to_local_date(line.event.date_begin,
                                             tz=tz).date()
         holiday_date = _convert_to_local_date(self.holiday.date_from,
                                               tz=tz).date()
         if holiday_date < event_date:
             vals['date_start'] = line.event.date_begin
         else:
             start_time = _convert_time_to_float(line.event.date_begin,
                                                 tz=tz)
             vals['date_start'] = _convert_to_utc_date(holiday_date,
                                                       start_time,
                                                       tz=tz)
         event_date = _convert_to_local_date(line.event.date_end,
                                             tz=tz).date()
         holiday_date = _convert_to_local_date(self.holiday.date_to,
                                               tz=tz).date()
         if holiday_date > event_date:
             vals['date_end'] = line.event.date_end
         else:
             start_time = _convert_time_to_float(line.event.date_end, tz=tz)
             vals['date_end'] = _convert_to_utc_date(holiday_date,
                                                     start_time,
                                                     tz=tz)
         registration = registration_obj.create(vals)
         if len(registration.contracts_permitted) == 1:
             registration.contract = registration.contracts_permitted[0].id
         m = (
             "<p> " + fields.Date.context_today(self) + ': ' +
             _('The employee: %s, replaces the employee: %s, from date %s,'
               ' to date %s') %
             (line.employee.address_home_id.name,
              self.holiday.employee_id.address_home_id.name,
              date2str(_convert_to_local_date(self.holiday.date_from,
                                              tz=tz)),
              date2str(_convert_to_local_date(self.holiday.date_to, tz=tz)))
             + "<br>")
         m += "<br> <br>"
         vals = {
             'type': 'comment',
             'model': 'event.event',
             'record_name': line.event.name,
             'res_id': line.event.id,
             'body': m
         }
         self.env['mail.message'].create(vals)
     self.holiday.signal_workflow('validate')
     self.holiday._update_presences_validate_holiday()
     self.holiday._update_partner_calendar_day(
         self.holiday, absence_type=self.holiday.holiday_status_id.id)
 def default_get(self, var_fields):
     tz = self.env.user.tz
     res = super(WizEventDeleteAssistant, self).default_get(var_fields)
     res.update({
         'start_time': _convert_time_to_float(
             _convert_to_utc_date(res.get('min_from_date'), tz=tz), tz=tz),
         'end_time': _convert_time_to_float(
             _convert_to_utc_date(res.get('max_to_date'), tz=tz), tz=tz),
     })
     return res
Beispiel #7
0
 def _validate_create_session_from_sale_order(
         self, event, num_session, line):
     task_obj = self.env['project.task']
     tz = self.env.user.tz
     if line.project_by_task == 'yes':
         fec_ini = _convert_to_utc_date(
             line.start_date, line.start_hour, tz=tz)
         fec_limit = _convert_to_utc_date(
             line.end_date, line.end_hour, tz=tz)
     else:
         fec_ini = fields.Datetime.from_string(
             self.project_id.date_start)
         fec_limit = fields.Datetime.from_string(
             self.project_id.date)
     fec_ini = fec_ini.replace(day=1)
     if fec_ini.weekday() == 0:
         num_week = 0
     else:
         num_week = 1
     month = fec_ini.month
     while fec_ini.date() <= fec_limit.date():
         if month != fec_ini.month:
             month = fec_ini.month
             if fec_ini.weekday() == 0:
                 num_week = 0
             else:
                 num_week = 1
         if fec_ini.weekday() == 0:
             num_week += 1
         valid = False
         if line.project_by_task == 'yes':
             line_fec_ini = _convert_to_utc_date(
                 line.start_date, line.start_hour, tz=tz)
             if fec_ini.date() >= line_fec_ini.date():
                 valid = True
         else:
             if (fec_ini.date() >= fields.Datetime.from_string(
                     self.project_id.date_start).date()):
                 valid = True
         if valid:
             valid = task_obj._validate_event_session_month(line, fec_ini)
             if valid:
                 valid = task_obj._validate_event_session_week(
                     line, num_week)
             if valid:
                 valid = task_obj._validate_event_session_day(line, fec_ini)
             if valid:
                 num_session += 1
                 self._create_session_from_sale_line(
                     event, num_session, line, fec_ini)
         fec_ini = fec_ini + relativedelta(days=+1)
Beispiel #8
0
 def _account_info_for_create_task_service_project(self, vals, procurement):
     tz = self.env.user.tz
     vals = super(
         ProjectTask, self)._account_info_for_create_task_service_project(
         vals, procurement)
     project = procurement.sale_line_id.order_id.project_id
     if project.date_start and project.start_time:
         date_start = _convert_to_local_date(
             project.date_start, tz=tz).date()
         time = project.start_time
         vals['date_start'] = _convert_to_utc_date(date_start, time, tz=tz)
     if project.date and project.end_time:
         date_end = _convert_to_local_date(project.date, tz=tz).date()
         time = project.end_time
         vals['date_end'] = _convert_to_utc_date(date_end, time, tz=tz)
     return vals
Beispiel #9
0
 def _prepare_event_data(self, sale, line, name, project):
     res = super(SaleOrder,
                 self)._prepare_event_data(sale, line, name, project)
     if not line or (line and line.project_by_task == 'no'):
         utc_dt = _convert_to_utc_date(self.project_id.date_start,
                                       time=self.project_id.start_time,
                                       tz=self.env.user.tz)
         res['date_begin'] = utc_dt
     if not line or (line and line.project_by_task == 'no'):
         utc_dt = _convert_to_utc_date(self.project_id.date,
                                       time=self.project_id.end_time,
                                       tz=self.env.user.tz)
         res['date_end'] = utc_dt
     if sale.project_id.type_hour:
         res['type_hour'] = sale.project_id.type_hour.id
     return res
Beispiel #10
0
 def _update_employee_calendar_days(
         self, contract=False, cancel_presence=False):
     tz = self.env.user.tz
     holidays_obj = self.env['hr.holidays']
     day = self.partner_calendar_day
     if not day:
         raise exceptions.Warning(
             _('Calendar not found for employee %s')
             % self.partner.name)
     if contract:
         day.contract = contract.id
     if self.absence_type:
         day.write({'festive': True,
                    'absence_type': self.absence_type.id})
     if cancel_presence:
         day.write({'festive': False,
                    'absence_type': False})
         if day.absence_type_from_employee_contract:
             absence_type = day.absence_type_from_employee_contract
             day.write({'festive': True,
                        'absence_type': absence_type.id})
     presence_date = datetime2str(_convert_to_utc_date(
         self.session_date_without_hour, time=0.0, tz=tz))
     cond = [('employee_id', '=', self.partner.id),
             ('date_from', '>=', presence_date),
             ('date_to', '<=', presence_date),
             ('type', '=', 'remove'),
             ('state', '=', 'validate')]
     holiday = holidays_obj.search(cond, limit=1)
     if holiday:
         day.write({'absence': True,
                    'absence_type': holiday.holiday_status_id.id})
 def _update_registration_date_end(self, registration):
     super(WizEventDeleteAssistant, self)._update_registration_date_end(
         registration)
     reg_date_end = str2datetime(registration.date_end)
     wiz_from_date = _convert_to_utc_date(
         self.from_date, time=self.start_time, tz=self.env.user.tz)
     if wiz_from_date != reg_date_end:
         registration.date_end = wiz_from_date
Beispiel #12
0
 def _find_contracts_for_employee(self):
     tz = self.env.user.tz
     permitted_contracts = self._search_permitted_contracts(self)
     self.contracts_permitted = [(6, 0, permitted_contracts.ids)]
     if len(permitted_contracts) == 1:
         self.contract = permitted_contracts[0].id
         from_date = date2str(_convert_to_local_date(
             self.date_start, tz=tz).date())
         if self.contract.date_start > from_date:
             start_time = _convert_time_to_float(self.date_start, tz=tz)
             self.date_start = _convert_to_utc_date(
                 self.contract.date_start, start_time, tz=tz)
         to_date = date2str(_convert_to_local_date(
             self.date_end, tz=tz).date())
         if self.contract.date_end and self.contract.date_end < to_date:
             end_time = _convert_time_to_float(self.date_end, tz=tz)
             self.date_end = _convert_to_utc_date(
                 self.contract.date_end, end_time, tz=tz)
Beispiel #13
0
 def _update_registration_date_end(self, registration):
     super(WizEventAppendAssistant,
           self)._update_registration_date_end(registration)
     reg_date_end = str2datetime(registration.date_end)
     if self.end_time:
         wiz_to_date = _convert_to_utc_date(self.to_date,
                                            time=self.end_time,
                                            tz=self.env.user.tz)
         if wiz_to_date != reg_date_end:
             registration.date_end = wiz_to_date
 def _prepare_data_confirm_assistant(self, reg):
     session_obj = self.env['event.track']
     tz = self.env.user.tz
     tasks = self.env['project.task']
     append_vals = super(WizEventConfirmAssistant,
                         self)._prepare_data_confirm_assistant(reg)
     from_date = _convert_to_local_date(reg.date_start, tz=tz).date()
     from_date = datetime2str(_convert_to_utc_date(from_date, 0.0, tz=tz))
     to_date = _convert_to_local_date(reg.date_end, tz=tz).date()
     to_date = datetime2str(_convert_to_utc_date(to_date, 0.0, tz=tz))
     cond = [('event_id', '=', reg.event_id.id), ('date', '>=', from_date),
             ('date', '<=', to_date), ('date', '!=', False)]
     sessions = session_obj.search(cond)
     tasks = sessions.mapped('tasks')
     append_vals.update({
         'permitted_tasks': [(6, 0, tasks.ids)],
         'tasks': [(6, 0, tasks.ids)]
     })
     return append_vals
Beispiel #15
0
 def _prepare_session_data_from_task(self, event, num_session, date):
     tz = self.env.user.tz
     vals = super(ProjectTask, self)._prepare_session_data_from_task(
         event, num_session, date)
     account = self.service_project_sale_line.order_id.project_id
     vals.update({
         'date': _convert_to_utc_date(date, account.start_time, tz=tz),
         'type_hour': account.type_hour.id,
     })
     return vals
Beispiel #16
0
 def _update_registration_start_date(self, registration):
     super(WizEventAppendAssistant,
           self)._update_registration_start_date(registration)
     reg_date_start = str2datetime(registration.date_start)
     if self.start_time:
         wiz_from_date = _convert_to_utc_date(self.from_date,
                                              time=self.start_time,
                                              tz=self.env.user.tz)
         if wiz_from_date != reg_date_start:
             registration.date_start = wiz_from_date
Beispiel #17
0
 def _prepare_event_data(self, sale, line, name, project):
     tz = self.env.user.tz
     date_begin = _convert_to_utc_date(
         self.project_id.date_start, 0.0, tz=tz)
     date_end = _convert_to_utc_date(self.project_id.date, 0.0, tz=tz)
     if line and line.project_by_task == 'yes':
         date_begin = _convert_to_utc_date(
             line.start_date, line.start_hour, tz=tz)
         date_end = _convert_to_utc_date(
             line.end_date, line.end_hour, tz=tz)
     event_vals = {
         'name': name,
         'timezone_of_event': self.env.user.tz,
         'date_tz': self.env.user.tz,
         'project_id': project.id,
         'sale_order': sale.id,
         'date_begin': date_begin,
         'date_end': date_end,
     }
     return event_vals
Beispiel #18
0
 def _prepare_registration_data(self, event):
     vals = super(WizEventAppendAssistant,
                  self)._prepare_registration_data(event)
     date_start = _convert_to_local_date(self.from_date).date()
     date_start = _convert_to_utc_date(date_start,
                                       time=self.start_time,
                                       tz=self.env.user.tz)
     date_end = _convert_to_local_date(self.to_date).date()
     date_end = _convert_to_utc_date(date_end,
                                     time=self.end_time,
                                     tz=self.env.user.tz)
     vals.update({
         'date_start':
         event.date_begin
         if datetime2string(date_start) < event.date_begin else date_start,
         'date_end':
         event.date_end
         if datetime2string(date_end) > event.date_end else date_end,
     })
     return vals
 def _calc_date_and_duration(self, date):
     lines = self.mapped('attendance_ids').filtered(
         lambda x: x.dayofweek == str(date.date().weekday()))
     if not lines:
         return False, False
     min_h = min(lines, key=lambda x: x.hour_from)
     new_date = _convert_to_utc_date(date,
                                     min_h.hour_from,
                                     tz=self.env.user.tz)
     duration = sum(x['hour_to'] - x['hour_from'] for x in lines)
     return new_date, duration
Beispiel #20
0
 def _onchange_contract(self):
     self.ensure_one()
     tz = self.env.user.tz
     if self.contract:
         if not self.date_start:
             self.date_start = self.event_id.date_begin
         if not self.date_end:
             self.date_end = self.event_id.date_end
         from_date = date2str(_convert_to_local_date(
             self.date_start, tz=tz).date())
         if self.contract.date_start and\
                 self.contract.date_start > from_date:
             start_time = _convert_time_to_float(self.date_start, tz=tz)
             self.date_start = _convert_to_utc_date(
                 self.contract.date_start, start_time, tz=tz)
         to_date = date2str(_convert_to_local_date(
             self.date_end, tz=tz).date())
         if self.contract.date_end and self.contract.date_end < to_date:
             end_time = _convert_time_to_float(self.date_end, tz=tz)
             self.date_end = _convert_to_utc_date(
                 self.contract.date_end, end_time, tz=tz)
Beispiel #21
0
 def _prepare_session_data_from_sale_line(self, event, num_session, line,
                                          date):
     vals = super(SaleOrder, self)._prepare_session_data_from_sale_line(
         event, num_session, line, date)
     if line.project_by_task == 'no':
         new_date = False
         if self.project_id.working_hours:
             working = self.project_id.working_hours
             new_date, duration = working._calc_date_and_duration(date)
         vals['date'] = new_date or _convert_to_utc_date(
             date, time=self.project_id.start_time, tz=self.env.user.tz)
     if line.order_id.project_id.type_hour:
         vals['type_hour'] = line.order_id.project_id.type_hour.id
     return vals
Beispiel #22
0
 def _generate_lines_end_date(self, lines):
     task_obj = self.env['project.task']
     tz = self.env.user.tz
     for l in lines:
         fec_ini = (
             l.project_by_task == 'yes'
             and _convert_to_utc_date(l.start_date, l.start_hour, tz=tz)
             or fields.Datetime.from_string(self.project_id.date_start))
         fec_ini = fec_ini.replace(day=1)
         num_week = fec_ini.weekday() == 0 and 0 or 1
         month = fec_ini.month
         session_number = 0
         end_date = ''
         while session_number <= l.session_number:
             if month != fec_ini.month:
                 month = fec_ini.month
                 num_week = fec_ini.weekday() == 0 and 0 or 1
             if fec_ini.weekday() == 0:
                 num_week += 1
             l_fec_ini = (
                 l.project_by_task == 'yes'
                 and _convert_to_utc_date(l.start_date, l.start_hour, tz=tz)
                 or fields.Datetime.from_string(self.project_id.date_start))
             if fec_ini.date() >= l_fec_ini.date():
                 valid = task_obj._validate_event_session_month(l, fec_ini)
                 if valid:
                     valid = task_obj._validate_event_session_week(
                         l, num_week)
                 if valid:
                     valid = task_obj._validate_event_session_day(
                         l, fec_ini)
                 if valid:
                     session_number += 1
                     end_date = fec_ini
                     if session_number == l.session_number:
                         l.end_date = end_date
             fec_ini = fec_ini + relativedelta(days=+1)
Beispiel #23
0
 def _prepare_session_data_from_sale_line(
         self, event, num_session, line, date):
     tz = self.env.user.tz
     new_date = False
     duration = False
     if self.project_id.working_hours:
         new_date, duration = (
             self.project_id.working_hours._calc_date_and_duration(date))
     if not duration:
         duration = line.product_uom_qty
         if line.performance:
             duration = ((line.performance * line.product_uom_qty)
                         if line.apply_performance_by_quantity else
                         line.performance)
     if not new_date:
         utc_dt = _convert_to_utc_date(
             date, line.start_hour if line.project_by_task == 'yes' else
             0.0, tz=tz)
     vals = {'name': (_('Session %s for %s') % (str(num_session),
                                                line.product_id.name)),
             'event_id': event.id,
             'date': new_date or utc_dt,
             'duration': duration}
     return vals