diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-10-14 08:22:48 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-16 14:18:00 +0000 |
| commit | e5c455f1b67bc613a9b5f1480387b1c7c85cc94c (patch) | |
| tree | 3a435b6cd7cea566074493bbefd42f364994ea7f | |
| parent | 14681a346e74b22bfcef50bc7a9a0958f9335c21 (diff) | |
[FIX] hr_maintenance: Display equipment count of employee
In the employee form view and in the employee profile, the stat button
displaying the equipment count is wrong.
It counts the equipment owned by the user, not equipments assigned to the
employee.
closes odoo/odoo#38889
X-original-commit: 07bd725c97519a82cc76f3069614ac70b49495a3
Signed-off-by: lul-odoo <LucasLefevre@users.noreply.github.com>
| -rw-r--r-- | addons/hr_maintenance/i18n/hr_maintenance.pot | 10 | ||||
| -rw-r--r-- | addons/hr_maintenance/models/res_users.py | 17 | ||||
| -rw-r--r-- | addons/hr_maintenance/views/hr_views.xml | 3 |
3 files changed, 21 insertions, 9 deletions
diff --git a/addons/hr_maintenance/i18n/hr_maintenance.pot b/addons/hr_maintenance/i18n/hr_maintenance.pot index ec4d43cae5f..023f2208753 100644 --- a/addons/hr_maintenance/i18n/hr_maintenance.pot +++ b/addons/hr_maintenance/i18n/hr_maintenance.pot @@ -26,6 +26,11 @@ msgid "Assigned Employee" msgstr "" #. module: hr_maintenance +#: model:ir.model.fields,field_description:hr_maintenance.field_res_users__equipment_count +msgid "Assigned Equipments" +msgstr "" + +#. module: hr_maintenance #: model_terms:ir.ui.view,arch_db:hr_maintenance.maintenance_request_view_form_inherit_hr #: model_terms:ir.ui.view,arch_db:hr_maintenance.maintenance_request_view_search_inherit_hr msgid "Created By" @@ -77,6 +82,11 @@ msgid "Maintenance Request" msgstr "" #. module: hr_maintenance +#: model:ir.model.fields,field_description:hr_maintenance.field_res_users__equipment_ids +msgid "Managed Equipments" +msgstr "" + +#. module: hr_maintenance #: model_terms:ir.ui.view,arch_db:hr_maintenance.maintenance_request_view_search_inherit_hr msgid "My Maintenances" msgstr "" diff --git a/addons/hr_maintenance/models/res_users.py b/addons/hr_maintenance/models/res_users.py index a4b784ce31b..c97a2bb60b1 100644 --- a/addons/hr_maintenance/models/res_users.py +++ b/addons/hr_maintenance/models/res_users.py @@ -4,13 +4,8 @@ from odoo import api, models, fields class Users(models.Model): _inherit = 'res.users' - equipment_ids = fields.One2many('maintenance.equipment', 'owner_user_id') - equipment_count = fields.Integer('Equipments', compute='_compute_equipment_count') - - @api.depends('equipment_ids') - def _compute_equipment_count(self): - for user in self: - user.equipment_count = len(user.equipment_ids) + equipment_ids = fields.One2many('maintenance.equipment', 'owner_user_id', string="Managed Equipments") + equipment_count = fields.Integer(related='employee_id.equipment_count', string="Assigned Equipments") def __init__(self, pool, cr): """ Override of __init__ to add access rights. @@ -26,4 +21,10 @@ class Users(models.Model): class Employee(models.Model): _inherit = 'hr.employee' - equipment_count = fields.Integer(related='user_id.equipment_count') + equipment_ids = fields.One2many('maintenance.equipment', 'employee_id') + equipment_count = fields.Integer('Equipments', compute='_compute_equipment_count') + + @api.depends('equipment_ids') + def _compute_equipment_count(self): + for employee in self: + employee.equipment_count = len(employee.equipment_ids) diff --git a/addons/hr_maintenance/views/hr_views.xml b/addons/hr_maintenance/views/hr_views.xml index eeef59184b9..0750adc6392 100644 --- a/addons/hr_maintenance/views/hr_views.xml +++ b/addons/hr_maintenance/views/hr_views.xml @@ -25,8 +25,9 @@ <field name="inherit_id" ref="hr.res_users_view_form_profile"/> <field name="arch" type="xml"> <xpath expr="//div[@name='button_box']" position="inside"> + <field name="employee_id" invisible="1"/> <button name="%(maintenance.hr_equipment_action)d" - context="{'search_default_my':1}" + context="{'search_default_employee_id': employee_id, 'default_employee_id': employee_id}" class="o_stat_button" icon="fa-cubes" type="action"> |
