PURPOSE Reorganize and lint mail.channel code. Purpose is to ease future modifications linked to groups and channels in mail / Discuss. SPECIFICATIONS Some tools methods do not necessarily require to be public. LINKS Prepares Task ID-2070632 (Discuss channel task) Prepares Task ID-2419762 (SM channel task) COM PR odoo/odoo#64862
33 lines
1.7 KiB
Python
33 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class Channel(models.Model):
|
|
_inherit = 'mail.channel'
|
|
|
|
def _get_channel_partner_info(self, all_partners, direct_partners):
|
|
partner_infos = super(Channel, self)._get_channel_partner_info(all_partners, direct_partners)
|
|
# only search for leave out_of_office_date_end if im_status is on leave
|
|
partners_on_leave = [partner_id for partner_id in direct_partners.ids if 'leave' in partner_infos[partner_id]['im_status']]
|
|
if partners_on_leave:
|
|
now = fields.Datetime.now()
|
|
self.env.cr.execute('''SELECT res_users.partner_id as partner_id, hr_leave.date_to as date_to
|
|
FROM res_users
|
|
JOIN hr_leave ON hr_leave.user_id = res_users.id
|
|
AND hr_leave.state not in ('cancel', 'refuse')
|
|
AND res_users.active = 't'
|
|
AND hr_leave.date_from <= %s
|
|
AND hr_leave.date_to >= %s
|
|
AND res_users.partner_id in %s''', (now, now, tuple(partners_on_leave)))
|
|
out_of_office_infos = dict(((res['partner_id'], res) for res in self.env.cr.dictfetchall()))
|
|
for partner_id, out_of_office_info in out_of_office_infos.items():
|
|
partner_infos[partner_id]['out_of_office_date_end'] = out_of_office_info['date_to']
|
|
|
|
# fill empty values for the consistency of the result
|
|
for partner_info in partner_infos.values():
|
|
partner_info.setdefault('out_of_office_date_end', False)
|
|
|
|
return partner_infos
|