Multi is the default api for methods, it is not necessary to explicitly decorate methods with it, adds clutter and most people use it because they see that the rest of the code uses it. Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class GamificationBadgeUser(models.Model):
|
|
"""User having received a badge"""
|
|
_inherit = 'gamification.badge.user'
|
|
|
|
employee_id = fields.Many2one('hr.employee', string='Employee')
|
|
|
|
@api.constrains('employee_id')
|
|
def _check_employee_related_user(self):
|
|
for badge_user in self:
|
|
if badge_user.employee_id not in badge_user.user_id.employee_ids:
|
|
raise ValidationError(_('The selected employee does not correspond to the selected user.'))
|
|
|
|
|
|
class GamificationBadge(models.Model):
|
|
_inherit = 'gamification.badge'
|
|
|
|
granted_employees_count = fields.Integer(compute="_compute_granted_employees_count")
|
|
|
|
@api.depends('owner_ids.employee_id')
|
|
def _compute_granted_employees_count(self):
|
|
for badge in self:
|
|
badge.granted_employees_count = self.env['gamification.badge.user'].search_count([
|
|
('badge_id', '=', badge.id),
|
|
('employee_id', '!=', False)
|
|
])
|
|
|
|
def get_granted_employees(self):
|
|
employee_ids = self.mapped('owner_ids.employee_id').ids
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': 'Granted Employees',
|
|
'view_mode': 'kanban,tree,form',
|
|
'res_model': 'hr.employee.public',
|
|
'domain': [('id', 'in', employee_ids)]
|
|
}
|