# -*- coding: utf-8 -*- ###################################################################################### # # A part of Open HRMS Project # # Copyright (C) 2025-TODAY Cybrosys Technologies(). # Author: Cybrosys Techno Solutions (odoo@cybrosys.com) # # This program is under the terms of the Odoo Proprietary License v1.0 (OPL-1) # It is forbidden to publish, distribute, sublicense, or sell copies of the Software # or modified copies of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # ######################################################################################## from odoo import fields, models from odoo.osv import expression class HREmployee(models.Model): """Inherited hr_employee to add new functions""" _inherit = 'hr.employee' def generate_work_entries(self, date_start, date_stop): """ function is used for Generate work entries When Contract State in Probation,Running,Expired """ date_start = fields.Date.to_date(date_start) date_stop = fields.Date.to_date(date_stop) if self: current_contracts = self._get_contracts(date_start, date_stop, states=['probation', 'open', 'close']) else: current_contracts = self._get_all_contracts(date_start, date_stop, states=['probation', 'open', 'close']) return bool( current_contracts._generate_work_entries(date_start, date_stop)) def _get_contracts(self, date_from, date_to, states=['open', 'probation'], kanban_state=False): """ Returns the contracts of the employee between date_from and date_to """ state_domain = [('state', 'in', states)] if kanban_state: state_domain = expression.AND( [state_domain, [('kanban_state', 'in', kanban_state)]]) return self.env['hr.contract'].search( expression.AND([[('employee_id', 'in', self.ids)], state_domain, [('date_start', '<=', date_to), '|', ('date_end', '=', False), ('date_end', '>=', date_from)]]))