Skip to content
Browse files

[FIX] account: only put internal users as followers of vendor bills c…

…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...
len-odoo committed Mar 25, 2019
1 parent a4f9b48 commit d697217594c7f11dcd9306f1089000db941a8bf2
Showing with 9 additions and 5 deletions.
  1. +9 −5 addons/account/models/
@@ -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:

# 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:
# 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.has_group('base.group_user'))))
partners_to_subscribe = partners.filtered(is_internal)
if partners_to_subscribe:
invoice.message_subscribe([ for p in partners_to_subscribe])
return invoice


0 comments on commit d697217

Please sign in to comment.
You can’t perform that action at this time.