Ejemplo n.º 1
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 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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 5
0
 def _update_wizard_vals(self, wiz_vals):
     tz = self.env.user.tz
     date_start = self.date_start or self.event_id.date_begin
     date_end = self.date_end or self.event_id.date_end
     from_date = _convert_to_local_date(date_start, tz=tz)
     start_time = _convert_time_to_float(date_start, tz=tz)
     to_date = _convert_to_local_date(date_end, tz=tz)
     end_time = _convert_time_to_float(date_end, tz=tz)
     wiz_vals.update({
         'from_date': from_date.date(),
         'start_time': start_time,
         'to_date': to_date.date(),
         'end_time': end_time,
     })
     return wiz_vals
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)