Skip to content

Commit

Permalink
[FIX] account: only put internal users as followers of vendor bills c…
Browse files Browse the repository at this point in the history
…reated 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 a4df9f8 despite not appearing in the task description.

We filter the partners to only keep the ones that belong to internal users.

opw 1958729
  • Loading branch information
Nans Lefebvre committed Mar 26, 2019
1 parent a4f9b48 commit 3307549
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions addons/account/models/account_invoice.py
Expand Up @@ -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
Expand All @@ -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 ''))
Expand All @@ -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
Expand Down

0 comments on commit 3307549

Please sign in to comment.