Modules: - hr_maintenance; - maintenance; - l10n_ch; - l10n_generic_coa - l10n_il. The plural of "equipment" is "equipment" and not "equipments" changes in the enterprise version: odoo/enterprise#31498 Remark: Runbot test log: Two fields (equipment_count, equipment_ids) of maintenance.equipment.category() have the same label: Equipment. [Modules: maintenance and maintenance] Two fields (equipment_count, equipment_ids) of hr.employee() have the same label: Equipment. [Modules: hr_maintenance and hr_maintenance] Using "Equipment Count" to differentiate them opw-2981186 closes odoo/odoo#100558 Signed-off-by: Adrien Widart <awt@odoo.com>
25 lines
824 B
Python
25 lines
824 B
Python
from odoo import api, models, fields
|
|
|
|
|
|
class Users(models.Model):
|
|
_inherit = 'res.users'
|
|
|
|
equipment_ids = fields.One2many('maintenance.equipment', 'owner_user_id', string="Managed Equipment")
|
|
equipment_count = fields.Integer(related='employee_id.equipment_count', string="Assigned Equipment")
|
|
|
|
@property
|
|
def SELF_READABLE_FIELDS(self):
|
|
return super().SELF_READABLE_FIELDS + ['equipment_count']
|
|
|
|
|
|
class Employee(models.Model):
|
|
_inherit = 'hr.employee'
|
|
|
|
equipment_ids = fields.One2many('maintenance.equipment', 'employee_id')
|
|
equipment_count = fields.Integer('Equipment Count', compute='_compute_equipment_count')
|
|
|
|
@api.depends('equipment_ids')
|
|
def _compute_equipment_count(self):
|
|
for employee in self:
|
|
employee.equipment_count = len(employee.equipment_ids)
|