[IMP] hr_attendance: Separate the attendance report in functions to allow inheritance.
TT36461 closes odoo/odoo#98037 X-original-commit: 9468c62a470455043c1fc45edf18df614c2d2d18 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
committed by
Kevin Baptiste
parent
25d2654b3b
commit
77c6b0146f
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, tools
|
||||
from odoo import api, fields, models, tools
|
||||
|
||||
|
||||
class HRAttendanceReport(models.Model):
|
||||
@@ -16,39 +16,52 @@ class HRAttendanceReport(models.Model):
|
||||
worked_hours = fields.Float("Hours Worked", readonly=True)
|
||||
overtime_hours = fields.Float("Extra Hours", readonly=True)
|
||||
|
||||
@api.model
|
||||
def _select(self):
|
||||
return """
|
||||
SELECT
|
||||
hra.id,
|
||||
hr_employee.department_id,
|
||||
hra.employee_id,
|
||||
hr_employee.company_id,
|
||||
hra.check_in,
|
||||
hra.worked_hours,
|
||||
coalesce(ot.duration, 0) as overtime_hours
|
||||
"""
|
||||
|
||||
@api.model
|
||||
def _from(self):
|
||||
return """
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
row_number() over (partition by employee_id, CAST(check_in AS DATE)) as ot_check,
|
||||
employee_id,
|
||||
CAST(check_in as DATE) as check_in,
|
||||
worked_hours
|
||||
FROM
|
||||
hr_attendance
|
||||
) as hra
|
||||
"""
|
||||
|
||||
def _join(self):
|
||||
return """
|
||||
LEFT JOIN hr_employee ON hr_employee.id = hra.employee_id
|
||||
LEFT JOIN hr_attendance_overtime ot
|
||||
ON hra.ot_check = 1
|
||||
AND ot.employee_id = hra.employee_id
|
||||
AND ot.date = hra.check_in
|
||||
AND ot.adjustment = FALSE
|
||||
"""
|
||||
|
||||
def init(self):
|
||||
tools.drop_view_if_exists(self.env.cr, self._table)
|
||||
|
||||
self.env.cr.execute("""
|
||||
CREATE OR REPLACE VIEW %s AS (
|
||||
(
|
||||
SELECT
|
||||
hra.id,
|
||||
hr_employee.department_id,
|
||||
hra.employee_id,
|
||||
hr_employee.company_id,
|
||||
hra.check_in,
|
||||
hra.worked_hours,
|
||||
coalesce(ot.duration, 0) as overtime_hours
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
row_number() over (partition by employee_id, CAST(check_in AS DATE)) as ot_check,
|
||||
employee_id,
|
||||
CAST(check_in as DATE) as check_in,
|
||||
worked_hours
|
||||
FROM
|
||||
hr_attendance
|
||||
) as hra
|
||||
LEFT JOIN
|
||||
hr_employee
|
||||
ON hr_employee.id = hra.employee_id
|
||||
LEFT JOIN
|
||||
hr_attendance_overtime ot
|
||||
ON hra.ot_check = 1
|
||||
AND ot.employee_id = hra.employee_id
|
||||
AND ot.date = hra.check_in
|
||||
AND ot.adjustment = FALSE
|
||||
)
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
)
|
||||
""" % (self._table))
|
||||
""" % (self._table, self._select(), self._from(), self._join())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user