From e5c455f1b67bc613a9b5f1480387b1c7c85cc94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Mon, 14 Oct 2019 08:22:48 +0000 Subject: [PATCH] [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 --- addons/hr_maintenance/i18n/hr_maintenance.pot | 10 ++++++++++ addons/hr_maintenance/models/res_users.py | 17 +++++++++-------- 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 @@ -25,6 +25,11 @@ msgstr "" 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 @@ -76,6 +81,11 @@ msgstr "" 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" 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 @@ +