[IMP] hr: add a model for work locations

The work location of an employee was previously a fields.Char. That was
changed to a Many2one field to a the new model called work.location.
That had some consequences in other modules that had to be slightly
adjusted.  The modules impacted were hr, hr_appraisal, hr_payroll.

Task id: 2335646

closes odoo/odoo#63192

Related: odoo/enterprise#15235
Related: odoo/upgrade#2020
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Kevin Baptiste
2021-02-05 13:00:09 +00:00
committed by Yannick Tivisse
parent 258ebe1405
commit 3d5e912da7
16 changed files with 115 additions and 32 deletions
+1
View File
@@ -33,6 +33,7 @@
'report/hr_employee_badge.xml',
'views/hr_employee_views.xml',
'views/hr_department_views.xml',
'views/hr_work_location_views.xml',
'views/hr_views.xml',
'views/hr_templates.xml',
'views/res_config_settings_views.xml',
+28 -21
View File
@@ -111,6 +111,13 @@ You are approachable, honest and a fun team player
If you have development competencies, we can propose you specific traineeships</field>
</record>
<!-- Work Locations -->
<record id="work_location_1" model="hr.work.location">
<field name="name">Building 1, Second Floor</field>
<field name="address_id" ref="base.main_partner" />
</record>
<!-- Employee categories -->
<record id="employee_category_2" model="hr.employee.category">
@@ -159,7 +166,7 @@ If you have development competencies, we can propose you specific traineeships</
<!--Employees-->
<record id="employee_admin" model="hr.employee">
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(237)-125-2389</field>
<field name="work_email">aiden.hughes71@example.com</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4'), ref('employee_category_3')])]"/>
@@ -174,7 +181,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_cto"/>
<field name="job_title">Chief Technical Officer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4'), ref('employee_category_3')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(376)-310-7863</field>
<field name="work_email">ronnie.hart87@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_al-image.jpg"/>
@@ -187,7 +194,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(538)-497-4804</field>
<field name="mobile_phone">(538)-672-3185</field>
<field name="work_email">anita.oliver32@example.com</field>
@@ -201,9 +208,9 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(450)-719-4182</field>
<field name="work_email">sharlene.rhodes49@example.comcom</field>
<field name="work_email">sharlene.rhodes49@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_niv-image.jpg"/>
</record>
@@ -214,7 +221,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(332)-775-6660</field>
<field name="work_email">randall.lewis74@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_stw-image.jpg"/>
@@ -227,7 +234,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(157)-363-8229</field>
<field name="work_email">jennie.fletcher76@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_chs-image.jpg"/>
@@ -242,7 +249,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">+3281813700</field>
<field name="work_email">gilles@odoo.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_qdp-image.png"/>
@@ -255,7 +262,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(449)-505-5146</field>
<field name="work_email">keith.byrd52@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_fme-image.jpg"/>
@@ -268,7 +275,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_consultant"/>
<field name="job_title">Consultant</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4'), ref('employee_category_5')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(203)-276-7903</field>
<field name="work_email">audrey.peterson25@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_fpi-image.jpg"/>
@@ -281,7 +288,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_consultant"/>
<field name="job_title">Consultant</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4'), ref('employee_category_5')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(663)-707-8451</field>
<field name="work_email">toni.jimenez23@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jth-image.jpg"/>
@@ -294,7 +301,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_marketing"/>
<field name="job_title">Marketing and Community Manager</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4'), ref('employee_category_2')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(916)-264-7362</field>
<field name="work_email">jeffrey.kelly72@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_ngh-image.jpg"/>
@@ -307,7 +314,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="job_id" ref="hr.job_hrm"/>
<field name="job_title">Human Resources Manager</field>
<field name="category_ids" eval="[(6, 0, [ref('employee_category_4')])]"/>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(360)-694-7266</field>
<field name="work_email">tina.williamson98@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_vad-image.jpg"/>
@@ -318,7 +325,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_rd"/>
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(350)-912-1201</field>
<field name="work_email">walter.horton80@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_han-image.jpg"/>
@@ -329,7 +336,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_management"/>
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(114)-262-1607</field>
<field name="work_email">paul.williams59@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jve-image.jpg"/>
@@ -340,7 +347,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_ps"/>
<field name="job_id" ref="hr.job_consultant"/>
<field name="job_title">Consultant</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(883)-331-5378</field>
<field name="work_email">doris.cole31@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jep-image.jpg"/>
@@ -351,7 +358,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_sales"/>
<field name="job_id" ref="hr.job_marketing"/>
<field name="job_title">Marketing and Community Manager</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(206)-267-3735</field>
<field name="work_email">jod@odoo.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jod-image.jpg"/>
@@ -362,7 +369,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_rd"/>
<field name="job_id" ref="hr.job_developer"/>
<field name="job_title">Experienced Developer</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(754)-532-3841</field>
<field name="work_email">beth.evans77@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jog-image.jpg"/>
@@ -373,7 +380,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_ps"/>
<field name="job_id" ref="hr.job_consultant"/>
<field name="job_title">Consultant</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(944)-518-8232</field>
<field name="work_email">ernest.reed47@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_jgo-image.jpg"/>
@@ -384,7 +391,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_sales"/>
<field name="job_id" ref="hr.job_marketing"/>
<field name="job_title">Marketing and Community Manager</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_phone">(644)-169-1352</field>
<field name="work_email">eli.lambert22@example.com</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_lur-image.jpg"/>
@@ -395,7 +402,7 @@ If you have development competencies, we can propose you specific traineeships</
<field name="department_id" ref="dep_ps"/>
<field name="job_id" ref="hr.job_consultant"/>
<field name="job_title">Consultant</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_location_id" ref="work_location_1"/>
<field name="work_email">abigail.peterson39@example.com</field>
<field name="work_phone">(482)-233-3393</field>
<field name="image_1920" type="base64" file="hr/static/img/employee_hne-image.jpg"/>
+1
View File
@@ -8,6 +8,7 @@ from . import hr_employee_public
from . import hr_department
from . import hr_job
from . import hr_plan
from . import hr_work_location
from . import mail_alias
from . import mail_channel
from . import models
+7 -1
View File
@@ -27,7 +27,8 @@ class HrEmployeeBase(models.AbstractModel):
work_phone = fields.Char('Work Phone', compute="_compute_phones", store=True, readonly=False)
mobile_phone = fields.Char('Work Mobile')
work_email = fields.Char('Work Email')
work_location = fields.Char('Work Location')
work_location_id = fields.Many2one('hr.work.location', 'Work Location', compute="_compute_work_location_id", store=True, readonly=False,
domain="[('address_id', '=', address_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
user_id = fields.Many2one('res.users')
resource_id = fields.Many2one('resource.resource')
resource_calendar_id = fields.Many2one('resource.calendar', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
@@ -162,6 +163,11 @@ class HrEmployeeBase(models.AbstractModel):
icon = 'presence_undetermined'
employee.hr_icon_display = icon
@api.depends('address_id')
def _compute_work_location_id(self):
to_reset = self.filtered(lambda e: e.address_id != e.work_location_id.address_id)
to_reset.work_location_id = False
@api.model
def _get_employee_working_now(self):
working_now = []
+1 -1
View File
@@ -24,7 +24,7 @@ class HrEmployeePublic(models.Model):
mobile_phone = fields.Char(readonly=True)
work_phone = fields.Char(readonly=True)
work_email = fields.Char(readonly=True)
work_location = fields.Char(readonly=True)
work_location_id = fields.Many2one(readonly=True)
user_id = fields.Many2one(readonly=True)
resource_id = fields.Many2one(readonly=True)
resource_calendar_id = fields.Many2one(readonly=True)
+15
View File
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class WorkLocation(models.Model):
_name = "hr.work.location"
_description = "Work Location"
_order = 'name'
active = fields.Boolean(default=True)
name = fields.Char(string="Work Location", required=True)
company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company)
address_id = fields.Many2one('res.partner', required=True, string="Work Address", domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
+2 -2
View File
@@ -21,7 +21,7 @@ class User(models.Model):
category_ids = fields.Many2many(related='employee_id.category_ids', string="Employee Tags", readonly=False, related_sudo=False)
department_id = fields.Many2one(related='employee_id.department_id', readonly=False, related_sudo=False)
address_id = fields.Many2one(related='employee_id.address_id', readonly=False, related_sudo=False)
work_location = fields.Char(related='employee_id.work_location', readonly=False, related_sudo=False)
work_location_id = fields.Many2one(related='employee_id.work_location_id', readonly=False, related_sudo=False)
employee_parent_id = fields.Many2one(related='employee_id.parent_id', readonly=False, related_sudo=False)
coach_id = fields.Many2one(related='employee_id.coach_id', readonly=False, related_sudo=False)
address_home_id = fields.Many2one(related='employee_id.address_home_id', readonly=False, related_sudo=False)
@@ -138,7 +138,7 @@ class User(models.Model):
'visa_expire',
'visa_no',
'work_email',
'work_location',
'work_location_id',
'work_phone',
'certificate',
'study_field',
+2
View File
@@ -14,3 +14,5 @@ access_hr_plan_activity_type_hr_user,access_hr_plan_activity_type,model_hr_plan_
access_hr_plan_hr_user,access_hr_plan_hr_user,model_hr_plan,group_hr_user,1,1,1,1
access_hr_plan_wizard,access.hr.plan.wizard,model_hr_plan_wizard,hr.group_hr_manager,1,1,1,0
access_hr_departure_wizard,access.hr.departure.wizard,model_hr_departure_wizard,hr.group_hr_user,1,1,1,0
access_hr_work_location_user,access_hr_work_location_user,model_hr_work_location,base.group_user,1,0,0,0
access_hr_work_location_manager,access_hr_work_location_manager,model_hr_work_location,group_hr_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
14 access_hr_plan_hr_user access_hr_plan_hr_user model_hr_plan group_hr_user 1 1 1 1
15 access_hr_plan_wizard access.hr.plan.wizard model_hr_plan_wizard hr.group_hr_manager 1 1 1 0
16 access_hr_departure_wizard access.hr.departure.wizard model_hr_departure_wizard hr.group_hr_user 1 1 1 0
17 access_hr_work_location_user access_hr_work_location_user model_hr_work_location base.group_user 1 0 0 0
18 access_hr_work_location_manager access_hr_work_location_manager model_hr_work_location group_hr_manager 1 1 1 1
+1 -1
View File
@@ -56,7 +56,6 @@
<field name="mobile_phone" widget="phone" options="{'enable_sms': false}"/>
<field name="work_phone" widget="phone" options="{'enable_sms': false}"/>
<field name="work_email" widget="email"/>
<field name="work_location"/>
</group>
<group>
<field name="department_id"/>
@@ -74,6 +73,7 @@
<field name="address_id"
context="{'show_address': 1}"
options='{"always_reload": True, "highlight_first_line": True}'/>
<field name="work_location_id"/>
</group>
<group name="managers" string="Approvers" invisible="1">
<!-- overridden in other modules -->
+2 -2
View File
@@ -105,7 +105,7 @@
<field name="address_id"
context="{'show_address': 1}"
options='{"always_reload": True, "highlight_first_line": True}'/>
<field name="work_location"/>
<field name="work_location_id" context="{'default_address_id': address_id}" />
</group>
<group name="managers" string="Approvers" class="hide-group-if-empty">
<!-- is overridden in other hr related modules -->
@@ -220,7 +220,7 @@
<field name="department_id"/>
<field name="job_id"/>
<field name="parent_id"/>
<field name="work_location" optional="hide"/>
<field name="work_location_id" optional="hide"/>
<field name="coach_id" invisible="1"/>
</tree>
</field>
+7
View File
@@ -90,6 +90,13 @@
parent="menu_hr_root"
groups="group_hr_user"/>
<menuitem
id="menu_hr_work_location_tree"
action="hr_work_location_action"
parent="menu_human_resources_configuration"
sequence="5"
groups="group_hr_user"/>
<menuitem
id="menu_config_plan"
name="Activity Planning"
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="hr_work_location_tree_view" model="ir.ui.view">
<field name="name">hr.work.location.view.tree</field>
<field name="model">hr.work.location</field>
<field name="arch" type="xml">
<tree string="Work Location">
<field name="active" invisible="1" />
<field name="name" />
<field name="address_id" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
</field>
</record>
<record id="hr_work_location_form_view" model="ir.ui.view">
<field name="name">hr.work.location.view.form</field>
<field name="model">hr.work.location</field>
<field name="arch" type="xml">
<form string="Work Location">
<sheet>
<group>
<group>
<field name="active" invisible="1" />
<field name="name" />
<field name="address_id" />
</group>
<group>
<field name="company_id" groups="base.group_multi_company" />
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="hr_work_location_action" model="ir.actions.act_window">
<field name="name">Work Locations</field>
<field name="res_model">hr.work.location</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</odoo>
+1 -1
View File
@@ -94,7 +94,7 @@
</group>
<group>
<field name="work_email" widget="email" attrs="{'readonly': [('can_edit', '=', False)]}"/>
<field name="work_location" attrs="{'readonly': [('can_edit', '=', False)]}"/>
<field name="work_location_id" attrs="{'readonly': [('can_edit', '=', False)]}"/>
<field name="company_id" invisible="1"/>
</group>
<group>
@@ -143,7 +143,7 @@
</div>
<ul>
<li t-if="record.job_id.raw_value"><field name="job_id"/></li>
<li t-if="record.work_location.raw_value"><field name="work_location"/></li>
<li t-if="record.work_location_id.raw_value"><field name="work_location_id"/></li>
</ul>
</div>
</div>
+1 -1
View File
@@ -20,7 +20,7 @@
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='work_location']" position="after">
<xpath expr="//field[@name='work_location_id']" position="after">
<field name="expense_manager_id" optional="hide" string="Expense Approver"/>
</xpath>
</field>
+1 -1
View File
@@ -214,7 +214,7 @@
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='work_location']" position="after">
<xpath expr="//field[@name='work_location_id']" position="after">
<field name="leave_manager_id" optional="hide" string="Time Off Approver"/>
</xpath>
</field>