2018-04-04 10:19:13 +02:00
|
|
|
# Copyright (C) 2018 Creu Blanca
|
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
|
2020-03-04 16:27:05 +01:00
|
|
|
from odoo import models
|
2021-12-30 13:33:52 +01:00
|
|
|
from odoo.tools import config
|
2018-04-04 10:19:13 +02:00
|
|
|
from odoo.tools.safe_eval import safe_eval
|
|
|
|
|
|
|
|
|
|
|
|
class MailFollowers(models.Model):
|
2020-03-09 15:10:18 +01:00
|
|
|
_inherit = "mail.followers"
|
2018-04-04 10:19:13 +02:00
|
|
|
|
2020-03-09 15:10:18 +01:00
|
|
|
def _add_followers(
|
|
|
|
self,
|
|
|
|
res_model,
|
|
|
|
res_ids,
|
|
|
|
partner_ids,
|
2022-09-15 05:13:33 +02:00
|
|
|
subtypes,
|
2020-03-09 15:10:18 +01:00
|
|
|
check_existing=False,
|
|
|
|
existing_policy="skip",
|
|
|
|
):
|
2021-12-30 13:33:52 +01:00
|
|
|
test_condition = config["test_enable"] and not self.env.context.get(
|
|
|
|
"test_restrict_follower"
|
|
|
|
)
|
|
|
|
if test_condition or self.env.context.get("no_restrict_follower"):
|
|
|
|
return super()._add_followers(
|
|
|
|
res_model,
|
|
|
|
res_ids,
|
|
|
|
partner_ids,
|
2022-09-15 05:13:33 +02:00
|
|
|
subtypes,
|
2021-12-30 13:33:52 +01:00
|
|
|
check_existing=check_existing,
|
|
|
|
existing_policy=existing_policy,
|
|
|
|
)
|
2018-04-04 10:19:13 +02:00
|
|
|
domain = self.env[
|
2020-12-22 10:18:50 +01:00
|
|
|
"mail.wizard.invite"
|
2020-01-02 13:45:13 +01:00
|
|
|
]._mail_restrict_follower_selection_get_domain(res_model=res_model)
|
2020-12-22 10:18:50 +01:00
|
|
|
partners = self.env["res.partner"].search(
|
|
|
|
[("id", "in", partner_ids)] + safe_eval(domain)
|
2018-04-04 10:19:13 +02:00
|
|
|
)
|
2020-03-04 16:27:05 +01:00
|
|
|
_res_ids = res_ids.copy() or [0]
|
|
|
|
new, update = super()._add_followers(
|
2020-03-09 15:10:18 +01:00
|
|
|
res_model,
|
|
|
|
res_ids,
|
|
|
|
partners.ids,
|
2022-09-15 05:13:33 +02:00
|
|
|
subtypes,
|
2020-03-09 15:10:18 +01:00
|
|
|
check_existing=check_existing,
|
|
|
|
existing_policy=existing_policy,
|
2020-03-04 16:27:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
for res_id in _res_ids:
|
|
|
|
if res_id not in new:
|
|
|
|
new.setdefault(res_id, list())
|
|
|
|
return new, update
|