diff --git a/hr_applicant_duplicate/README.rst b/hr_applicant_duplicate/README.rst new file mode 100644 index 0000000..b84487e --- /dev/null +++ b/hr_applicant_duplicate/README.rst @@ -0,0 +1,28 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================== +Hr applicant duplicate +====================== + +* Onchange in phone and email to see if the applicant is duplicated or discarded. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Berezi Amubieta +* Alfredo de la Fuente diff --git a/hr_applicant_duplicate/__init__.py b/hr_applicant_duplicate/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/hr_applicant_duplicate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_applicant_duplicate/__manifest__.py b/hr_applicant_duplicate/__manifest__.py new file mode 100644 index 0000000..30a4bc4 --- /dev/null +++ b/hr_applicant_duplicate/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Berezi - Iker - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Hr Applicant Duplicate", + 'version': '14.0.1.0.0', + "author": "Avanzosc", + "category": "Sales", + "depends": [ + "hr_recruitment", + ], + "data": [ + ], + "license": "AGPL-3", + 'installable': True, +} diff --git a/hr_applicant_duplicate/i18n/es.po b/hr_applicant_duplicate/i18n/es.po new file mode 100644 index 0000000..b528183 --- /dev/null +++ b/hr_applicant_duplicate/i18n/es.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_applicant_duplicate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-07-16 10:15+0000\n" +"PO-Revision-Date: 2021-07-16 10:15+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_applicant_duplicate +#: model:ir.model,name:hr_applicant_duplicate.model_hr_applicant +msgid "Applicant" +msgstr "Candidato" + +#. module: hr_applicant_duplicate +#: code:addons/hr_applicant_duplicate/models/hr_applicant.py:0 +#: code:addons/hr_applicant_duplicate/models/hr_applicant.py:0 +#, python-format +msgid "Applicant duplicated or discarded." +msgstr "Candidato duplicado o descartado." + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant__id +msgid "ID" +msgstr "" + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant____last_update +msgid "Last Modified on" +msgstr "Última modificación el" diff --git a/hr_applicant_duplicate/i18n/hr_applicant_duplicate.pot b/hr_applicant_duplicate/i18n/hr_applicant_duplicate.pot new file mode 100644 index 0000000..22969eb --- /dev/null +++ b/hr_applicant_duplicate/i18n/hr_applicant_duplicate.pot @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_applicant_duplicate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-07-16 10:15+0000\n" +"PO-Revision-Date: 2021-07-16 10:15+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_applicant_duplicate +#: model:ir.model,name:hr_applicant_duplicate.model_hr_applicant +msgid "Applicant" +msgstr "" + +#. module: hr_applicant_duplicate +#: code:addons/hr_applicant_duplicate/models/hr_applicant.py:0 +#: code:addons/hr_applicant_duplicate/models/hr_applicant.py:0 +#, python-format +msgid "Applicant duplicated or discarded." +msgstr "" + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant__display_name +msgid "Display Name" +msgstr "" + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant__id +msgid "ID" +msgstr "" + +#. module: hr_applicant_duplicate +#: model:ir.model.fields,field_description:hr_applicant_duplicate.field_hr_applicant____last_update +msgid "Last Modified on" +msgstr "" diff --git a/hr_applicant_duplicate/models/__init__.py b/hr_applicant_duplicate/models/__init__.py new file mode 100644 index 0000000..27b2d82 --- /dev/null +++ b/hr_applicant_duplicate/models/__init__.py @@ -0,0 +1 @@ +from . import hr_applicant diff --git a/hr_applicant_duplicate/models/hr_applicant.py b/hr_applicant_duplicate/models/hr_applicant.py new file mode 100644 index 0000000..8edccd5 --- /dev/null +++ b/hr_applicant_duplicate/models/hr_applicant.py @@ -0,0 +1,33 @@ +# Copyright 2021 Berezi - Iker - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models, api, _ +from odoo.exceptions import ValidationError + + +class HrApplicant(models.Model): + _inherit = 'hr.applicant' + + @api.onchange('partner_mobile', 'email_from') + def onchange_applicant_duplicate(self): + if self.partner_mobile: + cond1 = [ + ('partner_mobile', '=', self.partner_mobile), + ('active', '=', True)] + cond2 = [ + ('partner_mobile', '=', self.partner_mobile), + ('active', '=', False)] + employee1 = self.env['hr.applicant'].search(cond1, limit=1) + employee2 = self.env['hr.applicant'].search(cond2, limit=1) + if employee1 or employee2: + raise ValidationError( + _("Applicant duplicated or discarded.")) + if self.email_from: + cond3 = [ + ('email_from', '=', self.email_from), ('active', '=', True)] + cond4 = [ + ('email_from', '=', self.email_from), ('active', '=', False)] + employee3 = self.env['hr.applicant'].search(cond3, limit=1) + employee4 = self.env['hr.applicant'].search(cond4, limit=1) + if employee3 or employee4: + raise ValidationError( + _("Applicant duplicated or discarded.")) diff --git a/hr_applicant_duplicate/tests/__init__.py b/hr_applicant_duplicate/tests/__init__.py new file mode 100644 index 0000000..51c5652 --- /dev/null +++ b/hr_applicant_duplicate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_applicant_duplicate diff --git a/hr_applicant_duplicate/tests/test_hr_applicant_duplicate.py b/hr_applicant_duplicate/tests/test_hr_applicant_duplicate.py new file mode 100644 index 0000000..dd9976c --- /dev/null +++ b/hr_applicant_duplicate/tests/test_hr_applicant_duplicate.py @@ -0,0 +1,27 @@ +# Copyright (c) 2021 Berezi Amubieta - Avanzosc S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import common +from odoo.exceptions import ValidationError + + +class TestHrApplicantDuplicate(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestHrApplicantDuplicate, cls).setUpClass() + applicant_obj = cls.env['hr.applicant'] + cls.applicant1 = applicant_obj.create({ + 'name': 'aaaa', + 'partner_mobile': '11111', + 'active': True, + }) + cls.applicant2 = applicant_obj.create({ + 'name': 'bbbb', + 'email_from': 'bbbb@gmail.com', + 'active': False, + }) + + def test_sale_student_event(self): + self.applicant1.email_from = self.applicant2.email_from + with self.assertRaises(ValidationError): + self.applicant1.onchange_applicant_duplicate()