[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
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -87,6 +87,12 @@
|
||||
<field name="address_home_id"
|
||||
context="{'show_address': 1}"
|
||||
options='{"always_reload": True, "highlight_first_line": True}'/>
|
||||
<field name="is_address_home_a_company" invisible="1" />
|
||||
<div class="text-warning" attrs="{'invisible': [('is_address_home_a_company','=', False)]}">
|
||||
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.
|
||||
</div>
|
||||
</group>
|
||||
<group string="Status">
|
||||
<field name="gender"/>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user