| 1 |
|
| 2 |
|
| 3 |
from odoo import api, fields, models |
| 4 |
from odoo.tools import email_normalize |
| 5 |
|
| 6 |
|
| 7 |
class HrJobPlatform(models.Model): |
| 8 |
_name = 'hr.job.platform' |
| 9 |
_description = 'Job Platforms' |
| 10 |
|
| 11 |
name = fields.Char(required=True) |
| 12 |
email = fields.Char(required=True, help="Applications received from this Email won't be linked to a contact." |
| 13 |
"There will be no email address set on the Applicant either.") |
| 14 |
regex = fields.Char(help="The regex facilitates to extract information from the subject or body " |
| 15 |
"of the received email to autopopulate the Applicant's name field") |
| 16 |
|
| 17 |
_email_uniq = models.Constraint( |
| 18 |
'unique (email)', |
| 19 |
'The Email must be unique, this one already corresponds to another Job Platform.', |
| 20 |
) |
| 21 |
|
| 22 |
@api.model_create_multi |
| 23 |
def create(self, vals_list): |
| 24 |
for vals in vals_list: |
| 25 |
if vals['email']: |
| 26 |
vals['email'] = email_normalize(vals['email']) or vals['email'] |
| 27 |
platforms = super().create(vals_list) |
| 28 |
return platforms |
| 29 |
|
| 30 |
def write(self, vals): |
| 31 |
if vals.get('email'): |
| 32 |
vals['email'] = email_normalize(vals['email']) or vals['email'] |
| 33 |
return super().write(vals) |