summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_thread.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-11-26 15:01:13 +0000
committerThibault Delavallée <tde@odoo.com>2021-01-19 16:33:20 +0000
commit01254f06e8ea37887e190758cc479a098591ab8e (patch)
tree45ea1cfed547381ebc4f2ff7d0378822ea98feec /addons/mail/models/mail_thread.py
parent1e29d48f5b10deca9ed7b991ea92ffc36f61c725 (diff)
[FW][FIX] mail: fix auto subscribe subtypes computation
This commit contains a followup / rewrite / backport of #34150 : * odoo/odoo@16dd3da * odoo/odoo@0b11ed8 Fix: propagate generic internal subtypes from parent to childs with auto subscribe. With this commit, when the user subscribes to internal subtypes like activities on a parent record (e.g. a project) then the user follows them by default on every sub record creation (e.g. all new tasks of this project). Fix: do not reset existing subtypes when changing parent of a record using auto subscribe mechanism. With this commit, when changing subtype subscription from a parent record (e.g. project) avoid resetting all subtypes subscription on existing sub records (e.g. all new tasks of this project). Only new records will use the parent chosen subtypes. This is done through propagation of followers existing policy (see Follower._insert_followers() for more details); Note that fix done here is slightly different from the one done in odoo/odoo@16dd3da as there was some mismatch with internal model-related subtypes. Thix fix will be forward ported and improve the previous one. Task ID-2205643 COM PR #47336 X-original-commit: odoo/odoo@9e7092a03f6c44287c661e2b39a943d240aa2bde X-original-PR: odoo/odoo#47336 Co-Authored-By: Thibault Delavallee <tde@odoo.com> Co-Authored-By: Alexandre Khun <aku@odoo.com> Co-Authored-By: Priyanka kakadiya <pka@odoo.com>
Diffstat (limited to 'addons/mail/models/mail_thread.py')
-rw-r--r--addons/mail/models/mail_thread.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index f9a50041dc0..2b2cb9354a1 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -2811,9 +2811,10 @@ class MailThread(models.AbstractModel):
new_partners, new_channels = dict(), dict()
- # fetch auto subscription subtypes data
+ # return data related to auto subscription based on subtype matching (aka:
+ # default task subtypes or subtypes from project triggering task subtypes)
updated_relation = dict()
- all_ids, def_ids, int_ids, parent, relation = self.env['mail.message.subtype']._get_auto_subscription_subtypes(self._name)
+ child_ids, def_ids, all_int_ids, parent, relation = self.env['mail.message.subtype']._get_auto_subscription_subtypes(self._name)
# check effectively modified relation field
for res_model, fnames in relation.items():
@@ -2822,15 +2823,21 @@ class MailThread(models.AbstractModel):
udpated_fields = [fname for fnames in updated_relation.values() for fname in fnames if updated_values.get(fname)]
if udpated_fields:
+ # fetch "parent" subscription data (aka: subtypes on project to propagate on task)
doc_data = [(model, [updated_values[fname] for fname in fnames]) for model, fnames in updated_relation.items()]
res = self.env['mail.followers']._get_subscription_data(doc_data, None, None, include_pshare=True, include_active=True)
for fid, rid, pid, cid, subtype_ids, pshare, active in res:
+ # use project.task_new -> task.new link
sids = [parent[sid] for sid in subtype_ids if parent.get(sid)]
- sids += [sid for sid in subtype_ids if sid not in parent and sid in def_ids or sid in int_ids]
+ # add checked subtypes matching model_name
+ sids += [sid for sid in subtype_ids if sid not in parent and sid in child_ids]
if pid and active: # auto subscribe only active partners
- new_partners[pid] = (set(sids) & set(all_ids)) - set(int_ids) if pshare else set(sids) & set(all_ids)
- if cid:
- new_channels[cid] = (set(sids) & set(all_ids)) - set(int_ids)
+ if pshare: # remove internal subtypes for customers
+ new_partners[pid] = set(sids) - set(all_int_ids)
+ else:
+ new_partners[pid] = set(sids)
+ if cid: # never subscribe channels to internal subtypes
+ new_channels[cid] = set(sids) - set(all_int_ids)
notify_data = dict()
res = self._message_auto_subscribe_followers(updated_values, def_ids)