From d5bd5dbf667c73d217e2260f63a1f6e856eb2eb6 Mon Sep 17 00:00:00 2001 From: Baris Kocak Date: Wed, 12 Jul 2017 14:46:07 +0200 Subject: [PATCH] [IMP] hr: warn user when home address is a company * Add a warning on the employee form view when the home address has a company linked * Get email, phone number and mobile number from the application form when creating an employee from there --- addons/hr/models/hr.py | 10 +++++++ addons/hr/views/hr_views.xml | 6 ++++ .../hr_recruitment/models/hr_recruitment.py | 29 ++++++++++++++----- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/addons/hr/models/hr.py b/addons/hr/models/hr.py index ccfe751025b..dc49f6f2022 100644 --- a/addons/hr/models/hr.py +++ b/addons/hr/models/hr.py @@ -112,6 +112,10 @@ class Employee(models.Model): # private partner address_home_id = fields.Many2one( 'res.partner', 'Private Address', help='Enter here the private address of the employee, not the one linked to your company.') + is_address_home_a_company = fields.Boolean( + 'The employee adress has a company linked', + compute='_compute_is_address_home_a_company', + ) country_id = fields.Many2one( 'res.country', 'Nationality (Country)') gender = fields.Selection([ @@ -260,6 +264,12 @@ class Employee(models.Model): # Do not notify user it has been marked as follower of its employee. return + @api.depends('address_home_id.parent_id') + def _compute_is_address_home_a_company(self): + """Checks that choosen address (res.partner) is not linked to a company. + """ + for employee in self: + employee.is_address_home_a_company = employee.address_home_id.parent_id.id is not False class Department(models.Model): _name = "hr.department" diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index 74a26de680c..275048127bf 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -87,6 +87,12 @@ + +
+ Use here the home address of the employee. + This private address is used in the expense report reimbursement document. + It should be different from the work address. +
diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index adec7b15f57..bf6a1fb8242 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -397,19 +397,32 @@ class Applicant(models.Model): """ Create an hr.employee from the hr.applicants """ employee = False for applicant in self: - address_id = contact_name = False + contact_name = False if applicant.partner_id: address_id = applicant.partner_id.address_get(['contact'])['contact'] contact_name = applicant.partner_id.name_get()[0][1] + else : + new_partner_id = self.env['res.partner'].create({ + 'is_company': False, + 'name': applicant.partner_name, + 'email': applicant.email_from, + 'phone': applicant.partner_phone, + 'mobile': applicant.partner_mobile + }) + address_id = new_partner_id.address_get(['contact'])['contact'] if applicant.job_id and (applicant.partner_name or contact_name): applicant.job_id.write({'no_of_hired_employee': applicant.job_id.no_of_hired_employee + 1}) - employee = self.env['hr.employee'].create({'name': applicant.partner_name or contact_name, - 'job_id': applicant.job_id.id, - 'address_home_id': address_id, - 'department_id': applicant.department_id.id or False, - 'address_id': applicant.company_id and applicant.company_id.partner_id and applicant.company_id.partner_id.id or False, - 'work_email': applicant.department_id and applicant.department_id.company_id and applicant.department_id.company_id.email or False, - 'work_phone': applicant.department_id and applicant.department_id.company_id and applicant.department_id.company_id.phone or False}) + employee = self.env['hr.employee'].create({ + 'name': applicant.partner_name or contact_name, + 'job_id': applicant.job_id.id, + 'address_home_id': address_id, + 'department_id': applicant.department_id.id or False, + 'address_id': applicant.company_id and applicant.company_id.partner_id + and applicant.company_id.partner_id.id or False, + 'work_email': applicant.department_id and applicant.department_id.company_id + and applicant.department_id.company_id.email or False, + 'work_phone': applicant.department_id and applicant.department_id.company_id + and applicant.department_id.company_id.phone or False}) applicant.write({'emp_id': employee.id}) applicant.job_id.message_post( body=_('New Employee %s Hired') % applicant.partner_name if applicant.partner_name else applicant.name,