19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:00 +01:00
parent a1137a1456
commit e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions

View file

@ -3,4 +3,5 @@
from . import gamification
from . import hr_employee
from . import hr_employee_public
from . import res_users

View file

@ -10,23 +10,52 @@ class GamificationBadgeUser(models.Model):
_inherit = 'gamification.badge.user'
employee_id = fields.Many2one('hr.employee', string='Employee', index=True)
has_edit_delete_access = fields.Boolean(compute="_compute_has_edit_delete_access")
@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.\
with_context(allowed_company_ids=self.env.user.company_ids.ids).employee_ids:
if badge_user.employee_id and badge_user.employee_id not in badge_user.user_id.\
with_context(allowed_company_ids=badge_user.user_id.company_ids.ids).employee_ids:
raise ValidationError(_('The selected employee does not correspond to the selected user.'))
def _compute_has_edit_delete_access(self):
is_hr_user = self.env.user.has_group('hr.group_hr_user')
for badge_user in self:
badge_user.has_edit_delete_access = is_hr_user or self.env.uid == self.create_uid.id
def action_open_badge(self):
self.ensure_one()
return {
'name': _('Received Badge'),
'type': 'ir.actions.act_window',
'res_model': 'gamification.badge',
'res_model': 'gamification.badge.user',
'res_id': self.id,
'target': 'new',
'view_mode': 'form',
'res_id': self.badge_id.id,
'view_id': self.env.ref("hr_gamification.view_current_badge_form").id,
'context': {"dialog_size": "medium"},
}
def _notify_get_recipients_groups(self, message, model_description, msg_vals=False):
groups = super()._notify_get_recipients_groups(message, model_description, msg_vals)
self.ensure_one()
base_url = self.get_base_url()
for group in groups:
if group[0] == 'user':
if self.employee_id:
employee_form_url = f"{base_url}/web#action=hr.hr_employee_public_action&id={self.employee_id.id}&open_badges_tab=true&user_badge_id={self.id}"
group[2]['button_access'] = {
'url': employee_form_url,
'title': _('View Your Badge'),
}
group[2]['has_button_access'] = True
else:
group[2]['has_button_access'] = False
return groups
class GamificationBadge(models.Model):
_inherit = 'gamification.badge'
@ -34,18 +63,21 @@ class GamificationBadge(models.Model):
@api.depends('owner_ids.employee_id')
def _compute_granted_employees_count(self):
user_count = dict(
self.env['gamification.badge.user']._read_group(
[('badge_id', 'in', self.ids), ('employee_id', '!=', False)],
['badge_id'], ['__count'],
),
)
for badge in self:
badge.granted_employees_count = self.env['gamification.badge.user'].search_count([
('badge_id', '=', badge.id),
('employee_id', '!=', False)
])
badge.granted_employees_count = user_count.get(badge._origin, 0)
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',
'view_mode': 'kanban,list,form',
'res_model': 'hr.employee.public',
'domain': [('id', 'in', employee_ids)]
}

View file

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class HrEmployeeBase(models.AbstractModel):
_inherit = "hr.employee.base"
class HrEmployee(models.Model):
_inherit = "hr.employee"
goal_ids = fields.One2many('gamification.goal', string='Employee HR Goals', compute='_compute_employee_goals')
goal_ids = fields.One2many('gamification.goal', string='Employee HR Goals',
compute='_compute_employee_goals', groups="hr.group_hr_user")
badge_ids = fields.One2many(
'gamification.badge.user', string='Employee Badges', compute='_compute_employee_badges',
help="All employee badges, linked to the employee either directly or through the user"
@ -16,7 +16,7 @@ class HrEmployeeBase(models.AbstractModel):
# necessary for correct dependencies of badge_ids and has_badges
direct_badge_ids = fields.One2many(
'gamification.badge.user', 'employee_id',
help="Badges directly linked to the employee")
help="Badges directly linked to the employee", groups="hr.group_hr_user")
@api.depends('user_id.goal_ids.challenge_id.challenge_category')
def _compute_employee_goals(self):
@ -30,9 +30,9 @@ class HrEmployeeBase(models.AbstractModel):
def _compute_employee_badges(self):
for employee in self:
badge_ids = self.env['gamification.badge.user'].search([
'|', ('employee_id', '=', employee.id),
'|', ('employee_id', 'in', employee.ids),
'&', ('employee_id', '=', False),
('user_id', '=', employee.user_id.id)
('user_id', 'in', employee.user_id.ids)
])
employee.has_badges = bool(badge_ids)
employee.badge_ids = badge_ids

View file

@ -0,0 +1,14 @@
from odoo import fields, models
class HrEmployeePublic(models.Model):
_inherit = "hr.employee.public"
badge_ids = fields.One2many('gamification.badge.user', readonly=True, compute='_compute_badge_ids')
has_badges = fields.Boolean(compute='_compute_has_badges')
def _compute_has_badges(self):
self._compute_from_employee('has_badges')
def _compute_badge_ids(self):
self._compute_from_employee('badge_ids')