57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models, api
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
class GnCareerContract(models.Model):
|
|
_inherit = "hr.contract"
|
|
|
|
career_ids = fields.One2many("gn_career.career", 'contract_id',
|
|
string="Analyses du poste")
|
|
active_career_id = fields.Many2one('gn_career.career', string="Fiche de poste en cours", compute='_compute_active_career', store=True)
|
|
has_active_career = fields.Integer(compute='_has_active_career')
|
|
|
|
@api.depends('career_ids')
|
|
def _compute_active_career(self):
|
|
for record in self:
|
|
active_careers = record.career_ids.filtered(lambda c: c.status == 'active').sorted(key=lambda c: c.start_date, reverse=True)
|
|
record.active_career_id = active_careers[0] if active_careers else False
|
|
|
|
@api.depends('active_career_id')
|
|
def _has_active_career(self):
|
|
for record in self:
|
|
record.has_active_career = True if record.active_career_id else False
|
|
|
|
#@api.model
|
|
def open_associated_careers(self):
|
|
_logger.warning("Open Active Career called on records: %s", self)
|
|
self.ensure_one() # Ensure that the method is called on a single record
|
|
|
|
associated_contract_ids = [self.id,]
|
|
if self.previous_contract_id:
|
|
previous_contract = self.previous_contract_id
|
|
while previous_contract:
|
|
associated_contract_ids.append(previous_contract.id)
|
|
previous_contract = previous_contract.previous_contract_id
|
|
|
|
action = {
|
|
'type': 'ir.actions.act_window',
|
|
"views": [[False, "tree"], [False, "form"]],
|
|
'res_model': 'gn_career.career',
|
|
'target': 'current',
|
|
'domain': [('contract_id', 'in', associated_contract_ids)],
|
|
}
|
|
return action
|
|
|
|
def open_active_career(self):
|
|
action = {
|
|
'type': 'ir.actions.act_window',
|
|
"views": [[False, "form"]],
|
|
'res_model': 'gn_career.career',
|
|
'res_id': self.active_career_id.id, # ID of the career to open
|
|
'target': 'current',
|
|
}
|
|
return action |