Exemple #1
0
 def _check_validity_check_in_check_out(self):
     """ verifies if check_in is earlier than check_out. """
     for attendance in self:
         if attendance.check_in and attendance.check_out:
             if attendance.check_out < attendance.check_in:
                 raise exceptions.ValidationError(
                     _('"Check Out" time cannot be earlier than "Check In" time.'
                       ))
 def _check_reference(self):
     for transaction in self.filtered(lambda tx: tx.state not in
                                      ('cancel', 'error')):
         if self.search_count([('reference', '=', transaction.reference)
                               ]) != 1:
             raise exceptions.ValidationError(
                 _('The payment transaction reference must be unique!'))
     return True
 def _check_authorize_state(self):
     failed_tx = self.filtered(
         lambda tx: tx.state == 'authorized' and tx.acquirer_id.
         provider not in self.env['payment.acquirer']._get_feature_support(
         )['authorize'])
     if failed_tx:
         raise exceptions.ValidationError(
             _('The %s payment acquirers are not allowed to manual capture mode!'
               % failed_tx.mapped('acquirer_id.name')))
Exemple #4
0
    def _check_validity(self):
        """ Verifies the validity of the attendance record compared to the others from the same employee.
            For the same employee we must have :
                * maximum 1 "open" attendance record (without check_out)
                * no overlapping time slices with previous employee records
        """
        for attendance in self:
            # we take the latest attendance before our check_in time and check it doesn't overlap with ours
            last_attendance_before_check_in = self.env['hr.attendance'].search(
                [
                    ('employee_id', '=', attendance.employee_id.id),
                    ('check_in', '<=', attendance.check_in),
                    ('id', '!=', attendance.id),
                ],
                order='check_in desc',
                limit=1)
            if last_attendance_before_check_in and last_attendance_before_check_in.check_out and last_attendance_before_check_in.check_out > attendance.check_in:
                raise exceptions.ValidationError(
                    _("Cannot create new attendance record for %(empl_name)s, the employee was already checked in on %(datetime)s"
                      ) % {
                          'empl_name':
                          attendance.employee_id.name,
                          'datetime':
                          fields.Datetime.to_string(
                              fields.Datetime.context_timestamp(
                                  self,
                                  fields.Datetime.from_string(
                                      attendance.check_in))),
                      })

            if not attendance.check_out:
                # if our attendance is "open" (no check_out), we verify there is no other "open" attendance
                no_check_out_attendances = self.env['hr.attendance'].search(
                    [
                        ('employee_id', '=', attendance.employee_id.id),
                        ('check_out', '=', False),
                        ('id', '!=', attendance.id),
                    ],
                    order='check_in desc',
                    limit=1)
                if no_check_out_attendances:
                    raise exceptions.ValidationError(
                        _("Cannot create new attendance record for %(empl_name)s, the employee hasn't checked out since %(datetime)s"
                          ) % {
                              'empl_name':
                              attendance.employee_id.name,
                              'datetime':
                              fields.Datetime.to_string(
                                  fields.Datetime.context_timestamp(
                                      self,
                                      fields.Datetime.from_string(
                                          no_check_out_attendances.check_in))),
                          })
            else:
                # we verify that the latest attendance with check_in time before our check_out time
                # is the same as the one before our check_in time computed before, otherwise it overlaps
                last_attendance_before_check_out = self.env[
                    'hr.attendance'].search([
                        ('employee_id', '=', attendance.employee_id.id),
                        ('check_in', '<', attendance.check_out),
                        ('id', '!=', attendance.id),
                    ],
                                            order='check_in desc',
                                            limit=1)
                if last_attendance_before_check_out and last_attendance_before_check_in != last_attendance_before_check_out:
                    raise exceptions.ValidationError(
                        _("Cannot create new attendance record for %(empl_name)s, the employee was already checked in on %(datetime)s"
                          ) % {
                              'empl_name':
                              attendance.employee_id.name,
                              'datetime':
                              fields.Datetime.to_string(
                                  fields.Datetime.context_timestamp(
                                      self,
                                      fields.Datetime.from_string(
                                          last_attendance_before_check_out.
                                          check_in))),
                          })
 def _verify_pin(self):
     for employee in self:
         if employee.pin and not employee.pin.isdigit():
             raise exceptions.ValidationError(
                 _("The PIN must be a sequence of digits."))