Skip to content
Snippets Groups Projects
Commit 45bd961c authored by Nasreddin Boulif (bon)'s avatar Nasreddin Boulif (bon) Committed by Thibault Delavallée
Browse files

[FIX] mail: clean context on attachments creation


Manual backport of odoo/odoo@4504c9d8069082c9542226fbafdbf309089cf7a9 done in 13

Steps to reproduce :

  - Install `CRM` and `Sales` modules
  - Go to Settings, activate "External Email Servers" and
    set an alias.
  - Edit 'Sales Team Europe' : add an alias
    (ensure alias end with the "External Email Servers" alias)
  - Send a mail to the europe sale team alias email with a
    base64 image in the html body
    ex: <img alt="" src="data:image/png;base64,ABCDE123....789">

Issue :

  - Traceback is raised.
  ("ValueError: Wrong value for ir.attachment.type: 'opportunity'.")

Cause :

  Both `crm.lead` and `ir.attachment` have a `type` field.

  When creating the thread, in this case of crm.lead model,
  it will add the 'default_type' and 'default_team_id' to the
  context.

  The context will be inhrited and used on the creation of the
  ir.attachment (in this case its the base64 encoded image
  inside the body).

  Since no `type` was provided while creating the ir.attachment,
  it will set the type from `default_type` in context since
  available.

Solution :

- Clean the context (in this case, it will remove `default_X` values)
  when creating the ir.attachment .

opw-2551461

closes odoo/odoo#74374

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent a7574396
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ from odoo import _, api, fields, models, modules, SUPERUSER_ID, tools
from odoo.exceptions import UserError, AccessError
from odoo.osv import expression
from odoo.tools import groupby, formataddr
from odoo.tools.misc import clean_context
_logger = logging.getLogger(__name__)
_image_dataurl = re.compile(r'(data:image/[a-z]+?);base64,([a-z0-9+/\n]{3,}=*)\n*([\'"])(?: data-filename="([^"]*)")?', re.I)
......@@ -961,7 +962,7 @@ class Message(models.Model):
# extract base64 images
if 'body' in values:
Attachments = self.env['ir.attachment']
Attachments = self.env['ir.attachment'].with_context(clean_context(self._context))
data_to_url = {}
def base64_to_boundary(match):
key = match.group(2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment