From 9c35ab88fcdf74c35f344915f352498e10cb1e69 Mon Sep 17 00:00:00 2001 From: "Federico (fega)" Date: Fri, 28 Jan 2022 16:25:06 +0000 Subject: [PATCH] [FIX] account: multi-company error bill created by email with alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Set up an alias to receive vendor bills to company 2 - Forward a mail to this alias from an internal user - The mail should have the email address of a partner belonging to company 1 in it Current behavior: - The partner from company 1 can be set as vendor even tho the vendor bill will be from company 2 (inconsistent) - This leads to a multi-company error, and you can't open the bill as an user who can see it but not the partner. Intended behavior: - Partner from company 1 shouldn't be set as vendor if the vendor bill has been created from email alias of company 2. As the intended behavior says, the code avoids to set the vendor if the bill is created through an alias. opw-2587047 closes odoo/odoo#91973 X-original-commit: 4d5bb1fd46546870cd10d8dcd5b229de68a2e284 Signed-off-by: William André (wan) Co-authored-by: Andrea Grazioso (agr-odoo) --- addons/account/models/account_move.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 6ad7c7dbf31..795a0a8ed0e 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3277,7 +3277,12 @@ class AccountMove(models.Model): if is_internal_partner(partners[0]): # Search for partners in the mail's body. body_mail_addresses = set(email_re.findall(msg_dict.get('body'))) - partners = [partner for partner in self._mail_find_partner_from_emails(body_mail_addresses, extra_domain) if not is_internal_partner(partner)] + company_id = custom_values.get('company_id', self.env.company.id) + partners = [ + partner + for partner in self._mail_find_partner_from_emails(body_mail_addresses, extra_domain) + if not is_internal_partner(partner) and partner.company_id.id in (False, company_id) + ] # Little hack: Inject the mail's subject in the body. if msg_dict.get('subject') and msg_dict.get('body'):