From 0c07495391695cb5ea6019543d690e789338906c Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 23 Jul 2019 10:23:09 +0000 Subject: [PATCH] [FIX] website_form: Allow to post a message with attachments Coming from the sudo() modification. The mail.message is created in sudo, but the user is still the public user, who doesn't have a email address, leading to an raised error. --- addons/website_form/controllers/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website_form/controllers/main.py b/addons/website_form/controllers/main.py index e80dd1ffe07..81d7cf363fa 100644 --- a/addons/website_form/controllers/main.py +++ b/addons/website_form/controllers/main.py @@ -8,7 +8,7 @@ import pytz from datetime import datetime from psycopg2 import IntegrityError -from odoo import http +from odoo import http, SUPERUSER_ID from odoo.http import request from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools.translate import _ @@ -236,7 +236,7 @@ class WebsiteForm(http.Controller): 'res_id': id_record, 'attachment_ids': [(6, 0, orphan_attachment_ids)], } - mail_id = request.env['mail.message'].sudo().create(values) + mail_id = request.env['mail.message'].with_user(SUPERUSER_ID).create(values) else: # If the model is mail.mail then we have no other choice but to # attach the custom binary field files on the attachment_ids field.