54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
#
|
|
# Clear Groups for Odoo
|
|
# Copyright (C) 2016 Bytebrand GmbH (<http://www.bytebrand.net>).
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Lesser General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
|
|
import math
|
|
from openerp import models, api, _
|
|
from datetime import datetime
|
|
from openerp.exceptions import ValidationError
|
|
|
|
|
|
class HrAttendance(models.Model):
|
|
_inherit = "hr.attendance"
|
|
|
|
# ref: https://bugs.launchpad.net/openobject-client/+bug/887612
|
|
# test: 0.9853 - 0.0085
|
|
|
|
def float_time_convert(self, float_val):
|
|
hours = math.floor(abs(float_val))
|
|
mins = abs(float_val) - hours
|
|
mins = round(mins * 60)
|
|
if mins >= 60.0:
|
|
hours += 1
|
|
mins = 0.0
|
|
float_time = '%02d:%02d' % (hours, mins)
|
|
return float_time
|
|
|
|
@api.model
|
|
def create(self, values):
|
|
if values.get('name'):
|
|
times = datetime.strptime(values.get('name'), "%Y-%m-%d %H:%M:%S")
|
|
if datetime.now() < times:
|
|
raise ValidationError(
|
|
_('You can not set time of Sing In (resp. Sing Out) which '
|
|
'is later than a current time'))
|
|
return super(HrAttendance, self).create(values)
|