diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-06-24 07:28:44 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-07-17 09:11:18 +0000 |
| commit | f6fdde96bddfedf8764cd8a73089e44340d476ae (patch) | |
| tree | c7acd4cccf2286e7ba333f5da501e674ec643227 /addons/hr | |
| parent | 008634730adb0e834e759d5f356b8978e083395a (diff) | |
[IMP] hr_*: Improve employee presence state
Purpose
=======
There are currently multiple ways to determine if an employee is presence
or absent:
- login state (user status on chat)
- checkin/checkout from the Attendance app
- leave
- hr_presence (email, ip)
Those states are displayed in several different places and can be inconsitent.
e.g. Logged in -> green in the chat
Not checked in -> red on the employee kanban view.
The multiple ways to determine employee presence described above
should be aggregated together to have a better consistency.
Specification
=============
There are 3 presence states (previously defined in module `hr_presence`),
namely `present`, `absent`, `to_define`. They are now defined as soon as
`hr` module is installed.
The state computation can have several behaviors according to which apps
are installed:
1. `hr` is installed
Check employee presence based on login by default (only for employees with
a user).
Kanban state (private and public): should be green when logged in, red when logged out and
orange when the user is away.
Private employee form: Display a stat button "Connected" on the form view
when the user is logged in or "Last Activity xx/xx/xxx" otherwise.
2. `hr_attendance` is installed:
when the user is logged out, the state
is determined from the checked in/out state. But when the user is logged in,
consider the user as present (even if he checked out).
Kanban state: green for checked in, red for checked out
Private form view: attendance stat button.
3. `hr_holidays` is installed:
Has the highest priority if the employee is on leave.
Kanban state: red if employee is on leave.
Private form view: stat button "Absent Until xx/xx/xxxx" if employee
is on leave.
4. `hr_presence` is installed:
Two additionnal presence checking option: emails sent and IP address connected.
Once a user sent an email or the IP address was connected, he is considered
present for the entire day.
There should be at most one stat button on the employee form view, with the
relevent information.
Task id: 2024482
closes odoo/odoo#34933
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/hr')
| -rw-r--r-- | addons/hr/data/hr_data.xml | 5 | ||||
| -rw-r--r-- | addons/hr/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr/models/hr_employee_base.py | 28 | ||||
| -rw-r--r-- | addons/hr/models/res_company.py | 11 | ||||
| -rw-r--r-- | addons/hr/models/res_config_settings.py | 9 | ||||
| -rw-r--r-- | addons/hr/models/res_users.py | 4 | ||||
| -rw-r--r-- | addons/hr/views/hr_employee_public_views.xml | 10 | ||||
| -rw-r--r-- | addons/hr/views/hr_employee_views.xml | 41 | ||||
| -rw-r--r-- | addons/hr/views/res_config_settings_views.xml | 44 | ||||
| -rw-r--r-- | addons/hr/views/res_users.xml | 22 |
10 files changed, 168 insertions, 7 deletions
diff --git a/addons/hr/data/hr_data.xml b/addons/hr/data/hr_data.xml index ab7165fee25..8c70cef3e68 100644 --- a/addons/hr/data/hr_data.xml +++ b/addons/hr/data/hr_data.xml @@ -99,5 +99,10 @@ <field name="user_signature" eval="False"/> </record> + <record model="ir.config_parameter" id="hr_presence_control_login" forcecreate="False"> + <field name="key">hr.hr_presence_control_login</field> + <field name="value">True</field> + </record> + </data> </odoo> diff --git a/addons/hr/models/__init__.py b/addons/hr/models/__init__.py index efe3c1d702c..43857d3d83e 100644 --- a/addons/hr/models/__init__.py +++ b/addons/hr/models/__init__.py @@ -13,3 +13,4 @@ from . import mail_channel from . import res_config_settings from . import res_partner from . import res_users +from . import res_company diff --git a/addons/hr/models/hr_employee_base.py b/addons/hr/models/hr_employee_base.py index fec003ccfc6..191a5cb926d 100644 --- a/addons/hr/models/hr_employee_base.py +++ b/addons/hr/models/hr_employee_base.py @@ -23,3 +23,31 @@ class HrEmployeeBase(models.AbstractModel): user_id = fields.Many2one('res.users') resource_id = fields.Many2one('resource.resource') resource_calendar_id = fields.Many2one('resource.calendar') + hr_presence_state = fields.Selection([ + ('present', 'Present'), + ('absent', 'Absent'), + ('to_define', 'To Define')], compute='_compute_presence_state', default='to_define') + last_activity = fields.Date(compute="_compute_last_activity") + + def _compute_presence_state(self): + """ + This method is overritten in several other modules which add additional + presence criterions. e.g. hr_attendance, hr_holidays + """ + # Check on login + check_login = self.env['ir.config_parameter'].sudo().get_param('hr.hr_presence_control_login') + for employee in self: + state = 'to_define' + if check_login: + if employee.user_id.im_status == 'online': + state = 'present' + elif employee.user_id.im_status == 'offline': + state = 'absent' + employee.hr_presence_state = state + + def _compute_last_activity(self): + employees = self.filtered(lambda e: e.user_id) + presences = self.env['bus.presence'].search([('user_id', 'in', employees.mapped('user_id.id'))]) + + for presence in presences: + presence.user_id.employee_ids.last_activity = presence.last_presence.date() diff --git a/addons/hr/models/res_company.py b/addons/hr/models/res_company.py new file mode 100644 index 00000000000..cd1937d639e --- /dev/null +++ b/addons/hr/models/res_company.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Company(models.Model): + _inherit = 'res.company' + + hr_presence_control_email_amount = fields.Integer(string="# emails to send") + hr_presence_control_ip_list = fields.Char(string="Valid IP addresses") diff --git a/addons/hr/models/res_config_settings.py b/addons/hr/models/res_config_settings.py index 14494a6318e..a75564bc122 100644 --- a/addons/hr/models/res_config_settings.py +++ b/addons/hr/models/res_config_settings.py @@ -10,9 +10,12 @@ class ResConfigSettings(models.TransientModel): 'resource.calendar', 'Company Working Hours', related='company_id.resource_calendar_id', readonly=False) module_hr_org_chart = fields.Boolean(string="Show Organizational Chart") - module_hr_presence = fields.Boolean(string="Control presence of employees") + module_hr_presence = fields.Boolean(string="Advanced control presence of employees") module_hr_skills = fields.Boolean(string="Employee Skills and Resumé") hr_presence_control_login = fields.Boolean(string="According to the system login (User status on chat)", config_parameter='hr.hr_presence_control_login') - hr_presence_control_email = fields.Boolean(string="According to the amount of sent emails", config_parameter='hr.hr_presence_control_email') - hr_presence_control_ip = fields.Boolean(string="According to the IP address", config_parameter='hr.hr_presence_control_ip') + hr_presence_control_email = fields.Boolean(string="According to the amount of sent emails", config_parameter='hr_presence.hr_presence_control_email') + hr_presence_control_ip = fields.Boolean(string="According to the IP address", config_parameter='hr_presence.hr_presence_control_ip') + module_hr_attendance = fields.Boolean(string="According to the Attendance module.") + hr_presence_control_email_amount = fields.Integer(related="company_id.hr_presence_control_email_amount", readonly=False) + hr_presence_control_ip_list = fields.Char(related="company_id.hr_presence_control_ip_list", readonly=False) hr_employee_self_edit = fields.Boolean(string="Employee Edition", config_parameter='hr.hr_employee_self_edit') diff --git a/addons/hr/models/res_users.py b/addons/hr/models/res_users.py index 0e663a8d62b..c64f678070a 100644 --- a/addons/hr/models/res_users.py +++ b/addons/hr/models/res_users.py @@ -52,6 +52,8 @@ class User(models.Model): study_field = fields.Char(related='employee_id.study_field', readonly=False, related_sudo=False) study_school = fields.Char(related='employee_id.study_school', readonly=False, related_sudo=False) employee_count = fields.Integer(compute='_compute_employee_count') + hr_presence_state = fields.Selection(related='employee_id.hr_presence_state') + last_activity = fields.Date(related='employee_id.last_activity') @api.depends('employee_ids') def _compute_employee_count(self): @@ -69,6 +71,8 @@ class User(models.Model): 'employee_id', 'employee_ids', 'employee_parent_id', + 'hr_presence_state', + 'last_activity', ] hr_writable_fields = [ diff --git a/addons/hr/views/hr_employee_public_views.xml b/addons/hr/views/hr_employee_public_views.xml index fa8582f3015..95b277b30f0 100644 --- a/addons/hr/views/hr_employee_public_views.xml +++ b/addons/hr/views/hr_employee_public_views.xml @@ -95,6 +95,7 @@ <field name="arch" type="xml"> <kanban class="o_hr_employee_kanban"> <field name="id"/> + <field name="hr_presence_state"/> <templates> <t t-name="kanban-box"> <div class="oe_kanban_global_click o_kanban_record_has_image_fill o_hr_kanban_record"> @@ -107,6 +108,15 @@ <div class="o_kanban_record_top"> <div class="o_kanban_record_headings"> <strong class="o_kanban_record_title"> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'present'"> + <span class="fa fa-circle text-success" role="img" aria-label="Present" title="Present" name="presence_present"></span> + </div> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'absent'"> + <span class="fa fa-circle text-danger" role="img" aria-label="Absent" title="Absent" name="presence_absent"></span> + </div> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'to_define'"> + <span class="fa fa-circle text-warning" role="img" aria-label="To define" title="To define" name="presence_to_define"></span> + </div> <field name="name"/> </strong> <span t-if="record.job_id.raw_value" class="o_kanban_record_subtitle"><field name="job_id"/></span> diff --git a/addons/hr/views/hr_employee_views.xml b/addons/hr/views/hr_employee_views.xml index d7e52389246..56a96215194 100644 --- a/addons/hr/views/hr_employee_views.xml +++ b/addons/hr/views/hr_employee_views.xml @@ -40,14 +40,37 @@ <form string="Employee" js_class="hr_employee_form"> <field name="active" invisible="1"/> <field name="user_partner_id" invisible="1"/> + <field name="hr_presence_state" invisible="1"/> <header> <button string="Chat" class="btn btn-primary o_employee_chat_btn" attrs="{'invisible': [('user_id','=', False)]}"/> <button name="%(plan_wizard_action)d" string="Launch Plan" type="action" groups="hr.group_hr_manager"/> </header> <sheet> - <widget name="web_ribbon" text="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/> - <div name="button_box" class="oe_button_box"/> - <field name="image" widget='image' class="oe_avatar" options='{"zoom": true, "preview_image":"image_medium"}'/> + <widget name="web_ribbon" text="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/> + <div name="button_box" class="oe_button_box"> + <button + id="hr_presence_button" + class="oe_stat_button" + disabled="1" + attrs="{'invisible': ['|', ('last_activity', '=', False), ('user_id', '=', False)]}"> + <div role="img" class="fa fa-fw fa-circle text-success o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'present')]}" aria-label="Available" title="Available"/> + <div role="img" class="fa fa-fw fa-circle text-warning o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'to_define')]}" aria-label="Away" title="Away"/> + <div role="img" class="fa fa-fw fa-circle text-danger o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'absent')]}" aria-label="Not available" title="Not available"/> + + <div class="o_stat_info" attrs="{'invisible': [('hr_presence_state', '=', 'present')]}"> + <span class="o_stat_value"> + <field name="last_activity"/> + </span> + <span class="o_stat_text"> + Last Activity + </span> + </div> + <div class="o_stat_info" attrs="{'invisible': [('hr_presence_state', '!=', 'present')]}"> + <span class="o_stat_text">Connected</span> + </div> + </button> + </div> + <field name="image" widget='image' class="oe_avatar" options='{"zoom": true, "preview_image":"image_medium"}'/> <div class="oe_title"> <label for="name" class="oe_edit_only"/> <h1> @@ -204,6 +227,7 @@ <field name="arch" type="xml"> <kanban class="o_hr_employee_kanban"> <field name="id"/> + <field name="hr_presence_state"/> <templates> <t t-name="kanban-box"> <div class="oe_kanban_global_click o_kanban_record_has_image_fill o_hr_kanban_record"> @@ -216,7 +240,16 @@ <div class="o_kanban_record_top"> <div class="o_kanban_record_headings"> <strong class="o_kanban_record_title"> - <field name="name"/> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'present'"> + <span class="fa fa-circle text-success" role="img" aria-label="Present" title="Present" name="presence_present"></span> + </div> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'absent'"> + <span class="fa fa-circle text-danger" role="img" aria-label="Absent" title="Absent" name="presence_absent"></span> + </div> + <div class="float-right" t-if="record.hr_presence_state.raw_value == 'to_define'"> + <span class="fa fa-circle text-warning" role="img" aria-label="To define" title="To define" name="presence_to_define"></span> + </div> + <field name="name" placeholder="Employee's Name"/> </strong> <span t-if="record.job_id.raw_value" class="o_kanban_record_subtitle"><field name="job_id"/></span> </div> diff --git a/addons/hr/views/res_config_settings_views.xml b/addons/hr/views/res_config_settings_views.xml index 5cdcf6f679a..62d4f4179f6 100644 --- a/addons/hr/views/res_config_settings_views.xml +++ b/addons/hr/views/res_config_settings_views.xml @@ -20,6 +20,50 @@ </div> </div> </div> + <div class="col-12 col-lg-6 o_setting_box" title="Presence of employees"> + + <div class="o_setting_right_pane"> + <span class="o_form_label">Control presence of employees</span> + <div class="content-group" name="hr_presence_options"> + <div class="row"> + <field name="module_hr_attendance" class="col-lg-1 ml16"/> + <label for="module_hr_attendance" class="col-lg-10 o_light_label"/> + </div> + <div class="row"> + <field name="hr_presence_control_login" class="col-lg-1 ml16"/> + <label for="hr_presence_control_login" class="col-lg-10 o_light_label"/> + </div> + </div> + </div> + </div> + <div class="col-12 col-lg-6 o_setting_box" title="Advanced presence of employees"> + <div class="o_setting_left_pane"> + <field name="module_hr_presence"/> + </div> + <div class="o_setting_right_pane"> + <label for="module_hr_presence"/> + <div class="text-muted" name="hr_presence_options_advanced"> + Presence reporting screen, email and IP address control. + </div> + <div class="row mt-1" attrs="{'invisible': [('module_hr_presence', '=', False)]}"> + <field name="hr_presence_control_email" class="col-lg-1 ml16"/> + <label for="hr_presence_control_email" class="col-lg-10 o_light_label"/> + </div> + <div class="row ml-4" attrs="{'invisible': ['|', ('module_hr_presence', '=', False), ('hr_presence_control_email', '=', False)]}"> + <span class="mr-2">At least </span> + <field name="hr_presence_control_email_amount"/> + <span> sent emails</span> + </div> + <div class="row" attrs="{'invisible': [('module_hr_presence', '=', False)]}"> + <field name="hr_presence_control_ip" class="col-lg-1 ml16"/> + <label for="hr_presence_control_ip" class="col-lg-10 o_light_label"/> + </div> + <div class="row ml-4" attrs="{'invisible': ['|', ('module_hr_presence', '=', False), ('hr_presence_control_ip', '=', False)]}"> + <span class="mr-2">IP List (comma separated):</span> + <field name="hr_presence_control_ip_list"/> + </div> + </div> + </div> </div> <h2>Work Organization</h2> <div class="row mt16 o_settings_container"> diff --git a/addons/hr/views/res_users.xml b/addons/hr/views/res_users.xml index d417b93341b..1eb980c20f3 100644 --- a/addons/hr/views/res_users.xml +++ b/addons/hr/views/res_users.xml @@ -36,9 +36,31 @@ <field name="arch" type="xml"> <form position="replace"> <form> + <field name="hr_presence_state" invisible="1"/> <header></header> <!-- Used by other modules to add buttons --> <sheet> <div class="oe_button_box" name="button_box"> + <button + id="hr_presence_button" + class="oe_stat_button" + disabled="1" + attrs="{'invisible': [('hr_presence_state', '=', 'absent')]}"> + <div role="img" class="fa fa-fw fa-circle text-success o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'present')]}" aria-label="Available" title="Available"/> + <div role="img" class="fa fa-fw fa-circle text-warning o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'to_define')]}" aria-label="Away" title="Away"/> + <div role="img" class="fa fa-fw fa-circle text-danger o_button_icon" attrs="{'invisible': [('hr_presence_state', '!=', 'absent')]}" aria-label="Not available" title="Not available"/> + + <div class="o_stat_info" attrs="{'invisible': [('hr_presence_state', '=', 'present')]}"> + <span class="o_stat_value"> + <field name="last_activity"/> + </span> + <span class="o_stat_text"> + Last Activity + </span> + </div> + <div class="o_stat_info" attrs="{'invisible': [('hr_presence_state', '!=', 'present')]}"> + <span class="o_stat_text">Connected</span> + </div> + </button> </div> <field name="image" widget='image' class="oe_avatar" options='{"zoom": true, "preview_image":"image_medium"}'/> <div class="oe_title"> |
