summaryrefslogtreecommitdiff
path: root/addons/hr_contract/models
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2018-10-26 09:10:51 +0000
committerYannick Tivisse <yti@odoo.com>2018-10-29 09:29:52 +0000
commitb1449d24a3446d30ed9b0e07447ab35361a6d380 (patch)
tree73788911d0e47d2c96b65af86a50c6c9a1653d7a /addons/hr_contract/models
parent1f37ec3b0b009b8dfd679a58bb68eb9d138c6e02 (diff)
[IMP] hr_payroll: Move get_contract method to hr_contract module
Purpose ======= This method has nothing to do on the payslip model. Specification ============= Move the method on the hr_contract module, on the hr.employee model. Rename the method and return and recordset instead of a list of ids.
Diffstat (limited to 'addons/hr_contract/models')
-rw-r--r--addons/hr_contract/models/hr_contract.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py
index a98bb326846..7cecfe096dc 100644
--- a/addons/hr_contract/models/hr_contract.py
+++ b/addons/hr_contract/models/hr_contract.py
@@ -6,10 +6,10 @@ from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
+from odoo.osv import expression
class Employee(models.Model):
-
_inherit = "hr.employee"
manager = fields.Boolean(string='Is a Manager')
@@ -32,6 +32,22 @@ class Employee(models.Model):
for employee in self:
employee.contracts_count = result.get(employee.id, 0)
+ def _get_contracts(self, date_from, date_to):
+ """
+ Returns the contracts of the employee between date_from and date_to
+ """
+ self.ensure_one()
+ # 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', '=', self.id), ('state', '=', 'open')],
+ expression.OR([clause_1, clause_2, clause_3])])
+ return self.env['hr.contract'].search(clause_final)
+
class ContractType(models.Model):