Skip to content

Commit

Permalink
[FIX] hr_holidays: days allocated
Browse files Browse the repository at this point in the history
- Go to Leaves > Managers > All > Allocations
- Create an allocation for:
  Leave Type: Legal Leaves
  Mode: By Department
- Validate

When going to the Legal Leaves form view, the days allocated are not
shown.

This is because the domain is too restrictive. The allocation has a
`date_from` which is `False`, since it is only set for Accrual leaves.

We adapt the domain accordingly.

opw-1921338

closes odoo#30152
  • Loading branch information
nim-odoo committed Jan 11, 2019
1 parent 8da3f0c commit 0238699
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions addons/hr_holidays/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.osv import expression
from odoo.tools.translate import _
from odoo.tools.float_utils import float_round

Expand Down Expand Up @@ -204,9 +205,18 @@ def _compute_leaves(self):

@api.multi
def _compute_group_days_allocation(self):
domain = [
('holiday_status_id', 'in', self.ids),
('holiday_type', '!=', 'employee'),
('state', '=', 'validate'),
]
domain2 = [
'|',
('date_from', '>=', fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0))),
('date_from', '=', False),
]
grouped_res = self.env['hr.leave.allocation'].read_group(
[('holiday_status_id', 'in', self.ids), ('holiday_type', '!=', 'employee'), ('state', '=', 'validate'),
('date_from', '>=', fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)))],
expression.AND([domain, domain2]),
['holiday_status_id', 'number_of_days'],
['holiday_status_id'],
)
Expand Down Expand Up @@ -267,11 +277,16 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, access_ri
def action_see_days_allocated(self):
self.ensure_one()
action = self.env.ref('hr_holidays.hr_leave_allocation_action_all').read()[0]
action['domain'] = [
domain = [
('holiday_status_id', 'in', self.ids),
('holiday_type', '!=', 'employee'),
('holiday_status_id', '=', self.ids[0]),
('date_from', '>=', fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)))
]
domain2 = [
'|',
('date_from', '>=', fields.Datetime.to_string(datetime.datetime.now().replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0))),
('date_from', '=', False),
]
action['domain'] = expression.AND([domain, domain2])
action['context'] = {
'default_holiday_type': 'department',
'default_holiday_status_id': self.ids[0],
Expand Down

0 comments on commit 0238699

Please sign in to comment.