From 3307549f0761a86edc5712cc8ff02f74e5f5b16e Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Mon, 25 Mar 2019 19:45:59 +0100 Subject: [PATCH] [FIX] account: only put internal users as followers of vendor bills created by emails When the pdf of a vendor bill is sent to the alias of a journal, all the partners that match one of the email address present in the mail thread are added as followers of the newly created record. This is a problem since the vendors are actually not concerned by the internal work that is done, only internal users are. As a result they get spammed by useless emails, and complain to Christine. It was put in commit a4df9f8c938 despite not appearing in the task description. We filter the partners to only keep the ones that belong to internal users. opw 1958729 --- addons/account/models/account_invoice.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 90b1727531db5..f784f216054f0 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -658,7 +658,7 @@ def message_new(self, msg_dict, custom_values=None): """ # Split `From` and `CC` email address from received email to look for related partners to subscribe on the invoice subscribed_emails = email_split((msg_dict.get('from') or '') + ',' + (msg_dict.get('cc') or '')) - subscribed_partner_ids = [pid for pid in self._find_partner_from_emails(subscribed_emails) if pid] + seen_partner_ids = [pid for pid in self._find_partner_from_emails(subscribed_emails) if pid] # Detection of the partner_id of the invoice: # 1) check if the email_from correspond to a supplier @@ -682,7 +682,7 @@ def message_new(self, msg_dict, custom_values=None): # If the partner_id can be found, subscribe it to the bill, otherwise it's left empty to be manually filled if partner_id: - subscribed_partner_ids.append(partner_id) + seen_partner_ids.append(partner_id) # Find the right purchase journal based on the "TO" email address destination_emails = email_split((msg_dict.get('to') or '') + ',' + (msg_dict.get('cc') or '')) @@ -698,9 +698,13 @@ def message_new(self, msg_dict, custom_values=None): # Passing `type` in context so that _default_journal(...) can correctly set journal for new vendor bill invoice = super(AccountInvoice, self.with_context(type=values.get('type'))).message_new(msg_dict, values) - # Subscribe people on the newly created bill - if subscribed_partner_ids: - invoice.message_subscribe(subscribed_partner_ids) + # Subscribe internal users on the newly created bill + partners = self.env['res.partner'].browse(seen_partner_ids) + is_internal = lambda p: (p.user_ids and + all(p.user_ids.mapped(lambda u: u.user_has_groups('base.group_user')))) + partners_to_subscribe = partners.filtered(is_internal) + if partners_to_subscribe: + invoice.message_subscribe([p.id for p in partners_to_subscribe]) return invoice @api.model