Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from openerp import fields, models, api
- class tc_timesheet_simplified(models.Model):
- _name = "tc_timesheet_simplified"
- # ritorna la data attuale
- def _today(self):
- return fields.Date.today()
- # ritorna la data e l'ora attuali
- def _now(self):
- return fields.Datetime.now()
- # ritorna l'id del dipendente corrente
- def _employee(self):
- ids = self.env['hr.employee'].search([('user_id', '=', self._uid)])
- return ids and ids[0] or False
- # controlla la validità delle ore inserite (sign IN/OUT)
- @api.one
- @api.onchange('signin','signout')
- def _check_hours(self):
- # TODO: controllo signin < signout
- if (self.signin > self.signout):
- self.signout = 0
- # crea una nuova presenza in 'hr.attendance' con i dati inseriti
- def create_attendance(self, action, employee_id, name):
- attendance = self.env['hr.attendance'].create({'action': action, 'employee_id': employee_id, 'name': name, 'action_desc': False})
- # alla creazione di una nuova entry, genera sign IN e sign OUT in 'hr.attendance'
- @api.model
- def create(self, values):
- new_id = super(tc_timesheet_simplified, self).create(values)
- signin_name = new_id.date + ' ' + new_id.signin[11:16] + ':00'
- signout_name = new_id.date + ' ' + new_id.signout[11:16] + ':00'
- self.create_attendance('sign_in', new_id.employee.id, signin_name)
- self.create_attendance('sign_out', new_id.employee.id, signout_name)
- return new_id
- date = fields.Date(default=_today, required=True)
- signin = fields.Datetime(string='Sign in', default=_now, required=True)
- signout = fields.Datetime(string='Sign out', default=_now, required=True)
- hours = fields.Float(string='Hours', default=0.0, required=True)
- note = fields.Text()
- action = fields.Selection([('ferie','Ferie'), ('permesso','Permesso'), ('malattia','Malattia')], string='Action')
- employee = fields.Many2one('hr.employee', string='Dipendente', ondelete='cascade', default=_employee, required=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement