[FIX] mail: fix current user finding in _mail_find_partner_from_emails
To reproduce ============ - login as Mitchell Admin - change the email of a portal user, ex: Joel Willis, to the same email as Mitchell Admin. Do this through the Contacts App - always connected as Mitchell Admin, create a sale order and send it by email to client, in chatter the sender will be Joel Willis Problem ======= when setting the author, `_mail_find_partner_from_emails` is called, when searching for users with the given eamil, two results are found and the first one is taken as author Solution ======== give the priority to the current user when it matches the given conditions opw-3455520 closes odoo/odoo#134609 X-original-commit: b4a9095497fb77e6963103fa2a27d20e00172ea1 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Abdelouahab Laaroussi (abla) <abla@odoo.com>
This commit is contained in:
@@ -1865,6 +1865,9 @@ class MailThread(models.AbstractModel):
|
||||
done_partners += [partner for partner in partners]
|
||||
remaining = [email for email in normalized_emails if email not in [partner.email_normalized for partner in done_partners]]
|
||||
|
||||
# prioritize current user if exists in list
|
||||
done_partners.sort(key=lambda p: self.env.user.partner_id != p)
|
||||
|
||||
# iterate and keep ordering
|
||||
partners = []
|
||||
for contact in emails:
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestMailTools(MailCommon):
|
||||
'',
|
||||
]
|
||||
|
||||
@users('employee')
|
||||
@users('admin')
|
||||
def test_find_partner_from_emails(self):
|
||||
Partner = self.env['res.partner']
|
||||
test_partner = Partner.browse(self.test_partner.ids)
|
||||
@@ -107,6 +107,12 @@ class TestMailTools(MailCommon):
|
||||
found = Partner._mail_find_partner_from_emails(['alfred_astaire@test.example.com'])
|
||||
self.assertEqual(found, [self.env['res.partner']])
|
||||
|
||||
# test users with same email, priority given to current user
|
||||
# --------------------------------------------------------------
|
||||
self.user_employee.sudo().write({'email': '"Alfred Astaire" <%s>' % self.env.user.partner_id.email_normalized})
|
||||
found = self.env['res.partner']._mail_find_partner_from_emails([self.env.user.partner_id.email_formatted])
|
||||
self.assertEqual(found, [self.env.user.partner_id])
|
||||
|
||||
@users('employee')
|
||||
def test_tools_email_re(self):
|
||||
expected = [
|
||||
|
||||
Reference in New Issue
Block a user