|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +################################################################################### |
| 3 | +# |
| 4 | +# Cybrosys Technologies Pvt. Ltd. |
| 5 | +# Copyright (C) 2018-TODAY Cybrosys Technologies(<http://www.cybrosys.com>). |
| 6 | +# Author: cybrosys(<https://www.cybrosys.com>) |
| 7 | +# |
| 8 | +# This program is free software: you can modify |
| 9 | +# it under the terms of the GNU Affero General Public License (AGPL) as |
| 10 | +# published by the Free Software Foundation, either version 3 of the |
| 11 | +# License, or (at your option) any later version. |
| 12 | +# |
| 13 | +# This program is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU Affero General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU Affero General Public License |
| 19 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +# |
| 21 | +################################################################################### |
| 22 | +from odoo import tools |
| 23 | +from odoo import models, fields, api, _ |
| 24 | + |
| 25 | + |
| 26 | +class HrEmployee(models.Model): |
| 27 | + _inherit = 'hr.employee' |
| 28 | + |
| 29 | + device_id = fields.Char(string='Biometric Device ID') |
| 30 | + |
| 31 | + |
| 32 | +class ZkMachine(models.Model): |
| 33 | + _name = 'zk.machine.attendance' |
| 34 | + _inherit = 'hr.attendance' |
| 35 | + |
| 36 | + @api.constrains('check_in', 'check_out', 'employee_id') |
| 37 | + def _check_validity(self): |
| 38 | + """overriding the __check_validity function for employee attendance.""" |
| 39 | + pass |
| 40 | + |
| 41 | + device_id = fields.Char(string='Biometric Device ID') |
| 42 | + punch_type = fields.Selection([('0', 'Check In'), |
| 43 | + ('1', 'Check Out'), |
| 44 | + ('2', 'Break Out'), |
| 45 | + ('3', 'Break In'), |
| 46 | + ('4', 'Overtime In'), |
| 47 | + ('5', 'Overtime Out')], |
| 48 | + string='Punching Type') |
| 49 | + |
| 50 | + attendance_type = fields.Selection([('1', 'Finger'), |
| 51 | + ('15', 'Face'), |
| 52 | + ('2','Type_2'), |
| 53 | + ('3','Password'), |
| 54 | + ('4','Card')], string='Category') |
| 55 | + punching_time = fields.Datetime(string='Punching Time') |
| 56 | + address_id = fields.Many2one('res.partner', string='Working Address') |
| 57 | + |
| 58 | + |
| 59 | +class ReportZkDevice(models.Model): |
| 60 | + _name = 'zk.report.daily.attendance' |
| 61 | + _auto = False |
| 62 | + _order = 'punching_day desc' |
| 63 | + |
| 64 | + name = fields.Many2one('hr.employee', string='Employee') |
| 65 | + punching_day = fields.Datetime(string='Date') |
| 66 | + address_id = fields.Many2one('res.partner', string='Working Address') |
| 67 | + attendance_type = fields.Selection([('1', 'Finger'), |
| 68 | + ('15', 'Face'), |
| 69 | + ('2','Type_2'), |
| 70 | + ('3','Password'), |
| 71 | + ('4','Card')], |
| 72 | + string='Category') |
| 73 | + punch_type = fields.Selection([('0', 'Check In'), |
| 74 | + ('1', 'Check Out'), |
| 75 | + ('2', 'Break Out'), |
| 76 | + ('3', 'Break In'), |
| 77 | + ('4', 'Overtime In'), |
| 78 | + ('5', 'Overtime Out')], string='Punching Type') |
| 79 | + punching_time = fields.Datetime(string='Punching Time') |
| 80 | + |
| 81 | + def init(self): |
| 82 | + tools.drop_view_if_exists(self._cr, 'zk_report_daily_attendance') |
| 83 | + query = """ |
| 84 | + create or replace view zk_report_daily_attendance as ( |
| 85 | + select |
| 86 | + min(z.id) as id, |
| 87 | + z.employee_id as name, |
| 88 | + z.write_date as punching_day, |
| 89 | + z.address_id as address_id, |
| 90 | + z.attendance_type as attendance_type, |
| 91 | + z.punching_time as punching_time, |
| 92 | + z.punch_type as punch_type |
| 93 | + from zk_machine_attendance z |
| 94 | + join hr_employee e on (z.employee_id=e.id) |
| 95 | + GROUP BY |
| 96 | + z.employee_id, |
| 97 | + z.write_date, |
| 98 | + z.address_id, |
| 99 | + z.attendance_type, |
| 100 | + z.punch_type, |
| 101 | + z.punching_time |
| 102 | + ) |
| 103 | + """ |
| 104 | + self._cr.execute(query) |
| 105 | + |
| 106 | + |
0 commit comments