[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.
This commit is contained in:
Yannick Tivisse
2019-07-26 08:47:03 +00:00
parent 199bf06ca1
commit 0c07495391
+2 -2
View File
@@ -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.