<commit_before># Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class HrEmployee(models.Model):
    _inherit = "hr.employee"

    first_contract_id = fields.Many2one(
        "hr.contract",
        compute="_compute_first_contract_id",
        string="First Contract",
        help="First contract of the employee",
    )
    last_contract_id = fields.Many2one(
        "hr.contract",
        compute="_compute_last_contract_id",
        string="Last Contract",
        help="Last contract of the employee",
    )
    service_start_date = fields.Date(
        string="Start Date", readonly=True, related="first_contract_id.date_start",
    )
    service_termination_date = fields.Date(
        string="Termination Date", readonly=True, related="last_contract_id.date_end",
    )

    @api.depends("contract_ids")
    def _compute_first_contract_id(self):
        Contract = self.env["hr.contract"]
        for employee in self:
            employee.first_contract_id = Contract.search(
                employee._get_contract_filter(), order="date_start asc", limit=1
            )

    @api.depends("contract_ids")
    def _compute_last_contract_id(self):
        Contract = self.env["hr.contract"]
        for employee in self:
            employee.last_contract_id = Contract.search(
                employee._get_contract_filter(), order="date_end desc", limit=1
            )

    @api.onchange("service_hire_date")
    def _onchange_service_hire_date(self):  # pragma: no cover
        # Do nothing
        pass

    def _get_contract_filter(self):
        self.ensure_one()

        return [
            ("employee_id", "=", self.id),
            ("state", "in", self._get_service_contract_states()),
        ]

    @api.model
    def _get_service_contract_states(self):
        return ["open", "pending", "close"]<commit_msg>[FIX] hr_employee_service_contract: _compute when date_end changed<commit_after># Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class HrEmployee(models.Model):
    _inherit = "hr.employee"

    first_contract_id = fields.Many2one(
        "hr.contract",
        compute="_compute_first_contract_id",
        string="First Contract",
        help="First contract of the employee",
    )
    last_contract_id = fields.Many2one(
        "hr.contract",
        compute="_compute_last_contract_id",
        string="Last Contract",
        help="Last contract of the employee",
    )
    service_start_date = fields.Date(
        string="Start Date", readonly=True, related="first_contract_id.date_start",
    )
    service_termination_date = fields.Date(
        string="Termination Date", readonly=True, related="last_contract_id.date_end",
    )

    @api.depends("contract_ids", "contract_ids.date_start")
    def _compute_first_contract_id(self):
        Contract = self.env["hr.contract"]
        for employee in self:
            employee.first_contract_id = Contract.search(
                employee._get_contract_filter(), order="date_start asc", limit=1
            )

    @api.depends("contract_ids", "contract_ids.date_end")
    def _compute_last_contract_id(self):
        Contract = self.env["hr.contract"]
        for employee in self:
            employee.last_contract_id = Contract.search(
                employee._get_contract_filter(), order="date_end desc", limit=1
            )

    @api.onchange("service_hire_date")
    def _onchange_service_hire_date(self):  # pragma: no cover
        # Do nothing
        pass

    def _get_contract_filter(self):
        self.ensure_one()

        return [
            ("employee_id", "=", self.id),
            ("state", "in", self._get_service_contract_states()),
        ]

    @api.model
    def _get_service_contract_states(self):
        return ["open", "pending", "close"]
{'fraction_non_alphanumeric': 0.11427856964241061, 'fraction_numerical': 0.005001250312578144, 'mean_word_length': 2.838771593090211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2761519', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1160, 'n_words': 226}