|
| 1 | +# Copyright 2021 Berezi - Iker - AvanzOSC |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
| 3 | +from odoo import models, api, _ |
| 4 | +from odoo.exceptions import ValidationError |
| 5 | + |
| 6 | + |
| 7 | +class HrApplicant(models.Model): |
| 8 | + _inherit = 'hr.applicant' |
| 9 | + |
| 10 | + @api.onchange('partner_mobile', 'email_from') |
| 11 | + def onchange_applicant_duplicate(self): |
| 12 | + if self.partner_mobile: |
| 13 | + cond1 = [ |
| 14 | + ('partner_mobile', '=', self.partner_mobile), |
| 15 | + ('active', '=', True)] |
| 16 | + cond2 = [ |
| 17 | + ('partner_mobile', '=', self.partner_mobile), |
| 18 | + ('active', '=', False)] |
| 19 | + employee1 = self.env['hr.applicant'].search(cond1, limit=1) |
| 20 | + employee2 = self.env['hr.applicant'].search(cond2, limit=1) |
| 21 | + if employee1 or employee2: |
| 22 | + raise ValidationError( |
| 23 | + _("Applicant duplicated or discarded.")) |
| 24 | + if self.email_from: |
| 25 | + cond3 = [ |
| 26 | + ('email_from', '=', self.email_from), ('active', '=', True)] |
| 27 | + cond4 = [ |
| 28 | + ('email_from', '=', self.email_from), ('active', '=', False)] |
| 29 | + employee3 = self.env['hr.applicant'].search(cond3, limit=1) |
| 30 | + employee4 = self.env['hr.applicant'].search(cond4, limit=1) |
| 31 | + if employee3 or employee4: |
| 32 | + raise ValidationError( |
| 33 | + _("Applicant duplicated or discarded.")) |
0 commit comments