This question has been flagged
855 Views

I am working on adding a smart button inside the model: hr.employee. I have in my system different kind of leaves and I need this smart button to show the count of only 1 leave out of the total leaves. Here is my code:

View:



" rel="ugc">ir.ui.view">
hr.leave.calculation
hr.employee









python:


from odoo import api, fields, models, _
from odoo.tools import float_round


class HREmployeeInherit(models.Model):
_inherit = 'hr.employee'

allocation_display = fields.Char(compute='_compute_allocation_counts')
allocation_used_display = fields.Char(compute='_compute_total_allocation_used')

def compute_allocation_counts(self):
data = self.env['hr.leave.allocation'].read_group([
('employee_id', 'in', self.ids),
('holiday_status_id.active', '=', True),
('state', '=', 'validate'),
], ['number_of_days:sum', 'employee_id'], ['employee_id'])
rg_results = dict(
(d['employee_id'][0], {"employee_id_count": d['employee_id_count'], "number_of_days": d['number_of_days']})
for d in data)
for employee in self:
result = rg_results.get(employee.id)
employee.allocation_count = float_round(result['number_of_days'], precision_digits=2) if result else 0.0
employee.allocation_display = "%g" % employee.allocation_count
employee.allocations_count = result['employee_id_count'] if result else 0.0
#
# def _compute_total_allocation_used(self):
# for employee in self:
# if employee.current_leave_id.name=='Annual Leave - MSSKSA':
# employee.allocation_used_count = float_round(employee.allocation_count - employee.remaining_leaves,
# precision_digits=2)
# employee.allocation_used_display = "%g" % employee.allocation_used_count

Avatar
Discard