Purpose of this commit is to improve notification recipients computation.
Code cleaning
* make it batch enabled. Currently it works only for a single record. It
should evolve towards real multi computation, allowing to prepare post
and notification in batch;
* better manage multi users. Now when several users are linked to the same
partner, we try to find an internal user or fallback on share user. This
is cleaned compared to a distinct done previously;
* support recipients without subtype (pids + records) as a new case to
include follower computation;
Improvements
* include follower status if linked to records (is_follower can be used
notably in link computation to redirect to the portal);
* fetch partner lang directly in the SQL query. While fetching partner data
let us add its lang. That way it will be easier to improve lang support
in layouts;
Task-2739294 (Mail: Batch recipients fetch and improve its usage)
Part-of: odoo/odoo#82167
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
|
|
|
|
class Followers(models.Model):
|
|
_inherit = ['mail.followers']
|
|
|
|
def _get_recipient_data(self, records, message_type, subtype_id, pids=None):
|
|
if message_type != 'sms' or not (pids or records):
|
|
return super(Followers, self)._get_recipient_data(records, message_type, subtype_id, pids=pids)
|
|
|
|
if pids is None and records:
|
|
records_pids = dict(
|
|
(record.id, record._sms_get_default_partners().ids)
|
|
for record in records
|
|
)
|
|
elif pids and records:
|
|
records_pids = dict((record.id, pids) for record in records)
|
|
else:
|
|
records_pids = {0: pids if pids else []}
|
|
recipients_data = super(Followers, self)._get_recipient_data(records, message_type, subtype_id, pids=pids)
|
|
for rid, rdata in recipients_data.items():
|
|
sms_pids = records_pids.get(rid) or []
|
|
for pid, pdata in rdata.items():
|
|
if pid in sms_pids:
|
|
pdata['notif'] = 'sms'
|
|
return recipients_data
|