mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-25 12:32:04 +02:00
Initial commit: Hr packages
This commit is contained in:
commit
62531cd146
2820 changed files with 1432848 additions and 0 deletions
35
odoo-bringout-oca-ocb-hr/hr/models/mail_channel.py
Normal file
35
odoo-bringout-oca-ocb-hr/hr/models/mail_channel.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# -*- 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 Channel(models.Model):
|
||||
_inherit = 'mail.channel'
|
||||
|
||||
subscription_department_ids = fields.Many2many(
|
||||
'hr.department', string='HR Departments',
|
||||
help='Automatically subscribe members of those departments to the channel.')
|
||||
|
||||
@api.constrains('subscription_department_ids')
|
||||
def _constraint_subscription_department_ids_channel(self):
|
||||
failing_channels = self.sudo().filtered(lambda channel: channel.channel_type != 'channel' and channel.subscription_department_ids)
|
||||
if failing_channels:
|
||||
raise ValidationError(_("For %(channels)s, channel_type should be 'channel' to have the department auto-subscription.", channels=', '.join([ch.name for ch in failing_channels])))
|
||||
|
||||
def _subscribe_users_automatically_get_members(self):
|
||||
""" Auto-subscribe members of a department to a channel """
|
||||
new_members = super(Channel, self)._subscribe_users_automatically_get_members()
|
||||
for channel in self:
|
||||
new_members[channel.id] = list(
|
||||
set(new_members[channel.id]) |
|
||||
set((channel.subscription_department_ids.member_ids.user_id.partner_id.filtered(lambda p: p.active) - channel.channel_partner_ids).ids)
|
||||
)
|
||||
return new_members
|
||||
|
||||
def write(self, vals):
|
||||
res = super(Channel, self).write(vals)
|
||||
if vals.get('subscription_department_ids'):
|
||||
self._subscribe_users_automatically()
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue