mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-11-02 20:30:20 -06:00
[PATCH] Upstream patch - 23042022
This commit is contained in:
1 parent
5fdf6da3e2
commit
d0fce98bb4
20 files changed
+431
-136
No files matched your search
@@ -35,23 +35,25 @@ class KarmaRank(models.Model):
|
||||
@api.model_create_multi
|
||||
def create(self, values_list):
|
||||
res = super(KarmaRank, self).create(values_list)
|
||||
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
|
||||
users._recompute_rank()
|
||||
if any(res.mapped('karma_min')) > 0:
|
||||
users = self.env['res.users'].sudo().search([('karma', '>=', max(min(res.mapped('karma_min')), 1))])
|
||||
if users:
|
||||
users._recompute_rank()
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
if 'karma_min' in vals:
|
||||
previous_ranks = self.env['gamification.karma.rank'].search([], order="karma_min DESC").ids
|
||||
low = min(vals['karma_min'], self.karma_min)
|
||||
high = max(vals['karma_min'], self.karma_min)
|
||||
low = min(vals['karma_min'], min(self.mapped('karma_min')))
|
||||
high = max(vals['karma_min'], max(self.mapped('karma_min')))
|
||||
|
||||
res = super(KarmaRank, self).write(vals)
|
||||
|
||||
if 'karma_min' in vals:
|
||||
after_ranks = self.env['gamification.karma.rank'].search([], order="karma_min DESC").ids
|
||||
if previous_ranks != after_ranks:
|
||||
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
|
||||
users = self.env['res.users'].sudo().search([('karma', '>=', max(low, 1))])
|
||||
else:
|
||||
users = self.env['res.users'].sudo().search([('karma', '>=', low), ('karma', '<=', high)])
|
||||
users = self.env['res.users'].sudo().search([('karma', '>=', max(low, 1)), ('karma', '<=', high)])
|
||||
users._recompute_rank()
|
||||
return res
|
||||
@@ -180,6 +180,10 @@ WHERE sub.user_id IN %%s""" % {
|
||||
"""
|
||||
Method that can be called on a batch of users with the same new rank
|
||||
"""
|
||||
if self.env.context.get('install_mode', False):
|
||||
# avoid sending emails in install mode (prevents spamming users when creating data ranks)
|
||||
return
|
||||
|
||||
template = self.env.ref('gamification.mail_template_data_new_rank_reached', raise_if_not_found=False)
|
||||
if template:
|
||||
for u in self:
|
||||
|
||||
Reference in new issue
Block a user