flectra/addons/digest/models/res_users.py

20 lines
836 B
Python
Raw Normal View History

2018-08-20 11:29:49 +02:00
# -*- coding: utf-8 -*-
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
from flectra import api, models
class ResUsers(models.Model):
_inherit = "res.users"
@api.model
def create(self, vals):
""" Automatically subscribe employee users to default digest if activated """
user = super(ResUsers, self).create(vals)
config_obj = self.env['ir.config_parameter'].sudo()
default_digest_emails = config_obj.get_param('digest.default_digest_emails')
default_digest_id = config_obj.get_param('digest.default_digest_id')
2018-08-20 11:29:49 +02:00
if user.has_group('base.group_user') and default_digest_emails and default_digest_id:
digest = self.env['digest.digest'].sudo().browse(int(default_digest_id))
digest.user_ids |= user
return user