summaryrefslogtreecommitdiff
path: root/addons/website_slides/models/res_users.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_slides/models/res_users.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_slides/models/res_users.py')
-rw-r--r--addons/website_slides/models/res_users.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/addons/website_slides/models/res_users.py b/addons/website_slides/models/res_users.py
new file mode 100644
index 00000000..47f6baa9
--- /dev/null
+++ b/addons/website_slides/models/res_users.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models
+
+
+class Users(models.Model):
+ _inherit = 'res.users'
+
+ @api.model
+ def create(self, values):
+ """ Trigger automatic subscription based on user groups """
+ user = super(Users, self).create(values)
+ self.env['slide.channel'].sudo().search([('enroll_group_ids', 'in', user.groups_id.ids)])._action_add_members(user.partner_id)
+ return user
+
+ def write(self, vals):
+ """ Trigger automatic subscription based on updated user groups """
+ res = super(Users, self).write(vals)
+ if vals.get('groups_id'):
+ added_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
+ added_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
+ self.env['slide.channel'].sudo().search([('enroll_group_ids', 'in', added_group_ids)])._action_add_members(self.mapped('partner_id'))
+ return res
+
+ def get_gamification_redirection_data(self):
+ res = super(Users, self).get_gamification_redirection_data()
+ res.append({
+ 'url': '/slides',
+ 'label': 'See our eLearning'
+ })
+ return res