From dc8cf87fc8f92b6afb5b79a0bfa44b06a4981a7e Mon Sep 17 00:00:00 2001 From: Yolann Sabaux Date: Thu, 14 Apr 2022 09:31:51 +0000 Subject: [PATCH] [FIX] web: fetch right company_id Steps to reproduce: - Have two companies set up - In settings, check for company 2 the Files Centralization - For a Product, upload a document Issue: The document will not appear in Documents. It will only appear if the option is checked for company 1 Cause: The company_id is not fetched correctly throughout the process. There is a similar solution for the specific `documents` upload route: https://github.com/odoo/enterprise/blob/bdf712d66c3e5cee70a6b424b69a618fe655a39f/documents/controllers/main.py#L147-L149 Solution: Get the id directly from the cookies opw-2774365 closes odoo/odoo#91751 X-original-commit: 46db92d5211c215d07448676e619154390b7147f Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: yosa-odoo --- addons/web/controllers/binary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/binary.py b/addons/web/controllers/binary.py index 77afdd27c82..3931c296388 100644 --- a/addons/web/controllers/binary.py +++ b/addons/web/controllers/binary.py @@ -125,7 +125,9 @@ class Binary(http.Controller): filename = unicodedata.normalize('NFD', ufile.filename) try: - attachment = Model.create({ + cids = request.httprequest.cookies.get('cids', str(request.env.user.company_id.id)) + allowed_company_ids = [int(cid) for cid in cids.split(',')] + attachment = Model.with_context(allowed_company_ids=allowed_company_ids).create({ 'name': filename, 'datas': base64.encodebytes(ufile.read()), 'res_model': model,