Multi is the default api for methods, it is not necessary to explicitly decorate methods with it, adds clutter and most people use it because they see that the rest of the code uses it. Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
57 lines
2.7 KiB
Python
57 lines
2.7 KiB
Python
# -*- 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
|
|
|
|
|
|
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')
|
|
total_employee = fields.Integer(
|
|
compute='_compute_total_employee', string='Total Employee')
|
|
|
|
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 _compute_total_employee(self):
|
|
emp_data = self.env['hr.employee'].read_group([('department_id', 'in', self.ids)], ['department_id'], ['department_id'])
|
|
result = dict((data['department_id'][0], data['department_id_count']) for data in emp_data)
|
|
for department in self:
|
|
department.total_employee = result.get(department.id, 0)
|