34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from odoo import api, fields, models
|
|
|
|
|
|
class HRCandidate(models.Model):
|
|
_inherit = 'hr.candidate'
|
|
|
|
current_offer_letter_id = fields.Many2one(
|
|
'offer.letter',
|
|
string='Current Offer Letter',
|
|
compute='_compute_current_offer_letter',
|
|
store=False,
|
|
)
|
|
offer_release_status = fields.Selection(
|
|
selection=[
|
|
('requested', 'Requested'),
|
|
('sent', 'Sent to Applicant'),
|
|
('accepted', 'Accepted'),
|
|
('rejected', 'Rejected'),
|
|
('expired', 'Expired'),
|
|
],
|
|
string='Offer Status',
|
|
related='current_offer_letter_id.state',
|
|
readonly=True,
|
|
store=False,
|
|
)
|
|
|
|
@api.depends('applicant_ids.current_offer_letter_id', 'applicant_ids.current_offer_letter_id.create_date')
|
|
def _compute_current_offer_letter(self):
|
|
for candidate in self:
|
|
offer_letters = candidate.applicant_ids.mapped('current_offer_letter_id').sorted(
|
|
key=lambda offer: (offer.create_date or fields.Datetime.from_string('1970-01-01 00:00:00'), offer.id)
|
|
)
|
|
candidate.current_offer_letter_id = offer_letters[-1] if offer_letters else False
|