From 7f684fcac05262d9e1b8858b1aa7ef12e0ade9cf Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Fri, 7 Oct 2022 16:52:20 +0000 Subject: [PATCH] [FIX] website_form: prevent crash on form many2one attachment upload The current implementation of the many2one file upload in website form will lead to a traceback in case of m2o fields. It is currently only working with x2many fields. Note that it was introduced as such with [1]. Step to reproduce: - install website_sale - drag & drop form snippet and click on it - select "create customer" as action option - add new existing field - select "Main attachment" and save - try to submit the form with a file uploaded in that new field -> Traceback `ValueError: Wrong value for..` This commit makes it work for all type of relational field. [1]: https://github.com/odoo/odoo/commit/a77f5cf42faa75a2dd3931d83ad8ea86648248c0 closes odoo/odoo#104241 X-original-commit: addea33a8cb6c47bacdbfad0f3082f88763b59ef Signed-off-by: Romain Derie (rde) --- addons/website/controllers/form.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/website/controllers/form.py b/addons/website/controllers/form.py index 706bdae3471..5c87a5b68b0 100644 --- a/addons/website/controllers/form.py +++ b/addons/website/controllers/form.py @@ -261,7 +261,11 @@ class WebsiteForm(http.Controller): } attachment_id = request.env['ir.attachment'].sudo().create(attachment_value) if attachment_id and not custom_field: - record.sudo()[file.field_name] = [(4, attachment_id.id)] + record_sudo = record.sudo() + value = [(4, attachment_id.id)] + if record_sudo._fields[file.field_name].type == 'many2one': + value = attachment_id.id + record_sudo[file.field_name] = value else: orphan_attachment_ids.append(attachment_id.id)