mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-27 12:52:01 +02:00
Initial commit: Hr packages
This commit is contained in:
commit
62531cd146
2820 changed files with 1432848 additions and 0 deletions
|
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
import ast
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
|
||||
_inherit = 'hr.department'
|
||||
|
||||
absence_of_today = fields.Integer(
|
||||
compute='_compute_leave_count', string='Absence by Today')
|
||||
leave_to_approve_count = fields.Integer(
|
||||
compute='_compute_leave_count', string='Time Off to Approve')
|
||||
allocation_to_approve_count = fields.Integer(
|
||||
compute='_compute_leave_count', string='Allocation to Approve')
|
||||
|
||||
def _compute_leave_count(self):
|
||||
Requests = self.env['hr.leave']
|
||||
Allocations = self.env['hr.leave.allocation']
|
||||
today_date = datetime.datetime.utcnow().date()
|
||||
today_start = fields.Datetime.to_string(today_date) # get the midnight of the current utc day
|
||||
today_end = fields.Datetime.to_string(today_date + relativedelta(hours=23, minutes=59, seconds=59))
|
||||
|
||||
leave_data = Requests._read_group(
|
||||
[('department_id', 'in', self.ids),
|
||||
('state', '=', 'confirm')],
|
||||
['department_id'], ['department_id'])
|
||||
allocation_data = Allocations._read_group(
|
||||
[('department_id', 'in', self.ids),
|
||||
('state', '=', 'confirm')],
|
||||
['department_id'], ['department_id'])
|
||||
absence_data = Requests._read_group(
|
||||
[('department_id', 'in', self.ids), ('state', 'not in', ['cancel', 'refuse']),
|
||||
('date_from', '<=', today_end), ('date_to', '>=', today_start)],
|
||||
['department_id'], ['department_id'])
|
||||
|
||||
res_leave = dict((data['department_id'][0], data['department_id_count']) for data in leave_data)
|
||||
res_allocation = dict((data['department_id'][0], data['department_id_count']) for data in allocation_data)
|
||||
res_absence = dict((data['department_id'][0], data['department_id_count']) for data in absence_data)
|
||||
|
||||
for department in self:
|
||||
department.leave_to_approve_count = res_leave.get(department.id, 0)
|
||||
department.allocation_to_approve_count = res_allocation.get(department.id, 0)
|
||||
department.absence_of_today = res_absence.get(department.id, 0)
|
||||
|
||||
def _get_action_context(self):
|
||||
return {
|
||||
'search_default_approve': 1,
|
||||
'search_default_active_employee': 2,
|
||||
'search_default_department_id': self.id,
|
||||
'default_department_id': self.id,
|
||||
'searchpanel_default_department_id': self.id,
|
||||
}
|
||||
|
||||
def action_open_leave_department(self):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("hr_holidays.hr_leave_action_action_approve_department")
|
||||
action['context'] = {
|
||||
**self._get_action_context(),
|
||||
'search_default_active_time_off': 3,
|
||||
'hide_employee_name': 1,
|
||||
'holiday_status_name_get': False
|
||||
}
|
||||
return action
|
||||
|
||||
def action_open_allocation_department(self):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("hr_holidays.hr_leave_allocation_action_approve_department")
|
||||
action['context'] = self._get_action_context()
|
||||
action['context']['search_default_second_approval'] = 3
|
||||
action['domain'] = expression.AND([ast.literal_eval(action['domain']), [('state', '=', 'confirm')]])
|
||||
return action
|
||||
Loading…
Add table
Add a link
Reference in a new issue