/addons/hr_holidays/report/hr_leave_report.py

https://github.com/cvinh/odoo · Python · 78 lines · 70 code · 6 blank · 2 comment · 0 complexity · e439eeff3763ab8fda9099f9f52289bb MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, tools
  4. class LeaveReport(models.Model):
  5. _name = "hr.leave.report"
  6. _auto = False
  7. employee_id = fields.Many2one('hr.employee', string="Employee", readonly=True)
  8. name = fields.Char('Description', readonly=True)
  9. number_of_days = fields.Float('Number of Days', readonly=True)
  10. type = fields.Selection([
  11. ('allocation', 'Allocation Request'),
  12. ('request', 'Leave Request')
  13. ], string='Request Type', readonly=True)
  14. department_id = fields.Many2one('hr.department', string='Department', readonly=True)
  15. category_id = fields.Many2one('hr.employee.category', string='Employee Tag', readonly=True)
  16. holiday_status_id = fields.Many2one("hr.leave.type", string="Leave Type", readonly=True)
  17. state = fields.Selection([
  18. ('draft', 'To Submit'),
  19. ('cancel', 'Cancelled'),
  20. ('confirm', 'To Approve'),
  21. ('refuse', 'Refused'),
  22. ('validate1', 'Second Approval'),
  23. ('validate', 'Approved')
  24. ], string='Status', readonly=True)
  25. holiday_type = fields.Selection([
  26. ('employee', 'By Employee'),
  27. ('category', 'By Employee Tag')
  28. ], string='Allocation Mode', readonly=True)
  29. date_from = fields.Datetime('Start Date', readonly=True)
  30. date_to = fields.Datetime('End Date', readonly=True)
  31. payslip_status = fields.Boolean('Reported in last payslips', readonly=True)
  32. def init(self):
  33. tools.drop_view_if_exists(self._cr, 'hr_leave_report')
  34. self._cr.execute("""
  35. CREATE or REPLACE view hr_leave_report as (
  36. SELECT row_number() over(ORDER BY leaves.employee_id) as id,
  37. leaves.employee_id as employee_id, leaves.name as name,
  38. leaves.number_of_days as number_of_days, leaves.type as type,
  39. leaves.category_id as category_id, leaves.department_id as department_id,
  40. leaves.holiday_status_id as holiday_status_id, leaves.state as state,
  41. leaves.holiday_type as holiday_type, leaves.date_from as date_from,
  42. leaves.date_to as date_to, leaves.payslip_status as payslip_status
  43. from (select
  44. allocation.employee_id as employee_id,
  45. allocation.name as name,
  46. allocation.number_of_days as number_of_days,
  47. allocation.category_id as category_id,
  48. allocation.department_id as department_id,
  49. allocation.holiday_status_id as holiday_status_id,
  50. allocation.state as state,
  51. allocation.holiday_type,
  52. null as date_from,
  53. null as date_to,
  54. FALSE as payslip_status,
  55. 'allocation' as type
  56. from hr_leave_allocation as allocation
  57. union select
  58. request.employee_id as employee_id,
  59. request.name as name,
  60. request.number_of_days as number_of_days,
  61. request.category_id as category_id,
  62. request.department_id as department_id,
  63. request.holiday_status_id as holiday_status_id,
  64. request.state as state,
  65. request.holiday_type,
  66. request.date_from as date_from,
  67. request.date_to as date_to,
  68. request.payslip_status as payslip_status,
  69. 'request' as type
  70. from hr_leave as request) leaves
  71. );
  72. """)