[FIX] hr_payrol,hr_benefit: contract search

For a given date range, user can switch contract.

closes odoo/odoo#33103

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Nicolas Seinlet
2019-05-02 10:56:11 +00:00
parent b6f185b45d
commit 25e53ecf71
2 changed files with 9 additions and 10 deletions
+7 -10
View File
@@ -29,16 +29,13 @@ class Employee(models.Model):
"""
Returns the contracts of the employee between date_from and date_to
"""
# a contract is valid if it ends between the given dates
clause_1 = ['&', ('date_end', '<=', date_to), ('date_end', '>=', date_from)]
# OR if it starts between the given dates
clause_2 = ['&', ('date_start', '<=', date_to), ('date_start', '>=', date_from)]
# OR if it starts before the date_from and finish after the date_end (or never finish)
clause_3 = ['&', ('date_start', '<=', date_from), '|', ('date_end', '=', False), ('date_end', '>=', date_to)]
clause_final = expression.AND([
[('employee_id', 'in', self.ids), ('state', 'in', states)],
expression.OR([clause_1, clause_2, clause_3])])
return self.env['hr.contract'].search(clause_final)
return self.env['hr.contract'].search([
'&', '&', '&',
('employee_id', 'in', self.ids),
('state', 'in', states),
('date_start', '<=', date_to),
'|', ('date_end', '=', False), ('date_end', '>=', date_from)
])
@api.model
def _get_all_contracts(self, date_from, date_to, states=['open', 'pending']):
+2
View File
@@ -22,6 +22,8 @@ class HrLeave(models.Model):
vals_list = []
for leave in self:
contract = leave.employee_id._get_contracts(leave.date_from, leave.date_to, states=['open', 'pending', 'close'])
if contract and len(contract) > 0:
contract = contract[0]
start = max(leave.date_from, datetime.combine(contract.date_start, datetime.min.time()))
end = min(leave.date_to, datetime.combine(contract.date_end or date.max, datetime.max.time()))
benefit_type = leave.holiday_status_id.benefit_type_id