From 691c14c07089218bed52fb37807c315918bbcd1c Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 26 Oct 2020 10:10:33 +0000 Subject: [PATCH] [FIX] account, purchase, sale: portal access error - Install account / purchase / sale - Ceate an internal user without any access rights - Go to `/my` A 500 error is raised because of an AccessError. When the user has no access rights to any of the mentioned applications, the `search` call returns an AccessError. We prevent the access error and return 0 as a fallback. opw-2367559 closes odoo/odoo#60849 X-original-commit: 54ef98c613219aba3bda41817f7767261b8092d2 Signed-off-by: Nicolas Martinelli (nim) --- addons/account/controllers/portal.py | 2 +- addons/purchase/controllers/portal.py | 2 +- addons/sale/controllers/portal.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 9766b27c276..44355f227f8 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -15,7 +15,7 @@ class PortalAccount(CustomerPortal): if 'invoice_count' in counters: invoice_count = request.env['account.move'].search_count([ ('move_type', 'in', ('out_invoice', 'in_invoice', 'out_refund', 'in_refund', 'out_receipt', 'in_receipt')), - ]) + ]) if request.env['account.move'].check_access_rights('read', raise_exception=False) else 0 values['invoice_count'] = invoice_count return values diff --git a/addons/purchase/controllers/portal.py b/addons/purchase/controllers/portal.py index 45ab7d037b9..58830772074 100644 --- a/addons/purchase/controllers/portal.py +++ b/addons/purchase/controllers/portal.py @@ -22,7 +22,7 @@ class CustomerPortal(portal.CustomerPortal): if 'purchase_count' in counters: values['purchase_count'] = request.env['purchase.order'].search_count([ ('state', 'in', ['purchase', 'done', 'cancel']) - ]) + ]) if request.env['purchase.order'].check_access_rights('read', raise_exception=False) else 0 return values def _purchase_order_get_page_view_values(self, order, access_token, **kwargs): diff --git a/addons/sale/controllers/portal.py b/addons/sale/controllers/portal.py index 360fb63dd54..880200348f2 100644 --- a/addons/sale/controllers/portal.py +++ b/addons/sale/controllers/portal.py @@ -24,12 +24,12 @@ class CustomerPortal(portal.CustomerPortal): values['quotation_count'] = SaleOrder.search_count([ ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), ('state', 'in', ['sent', 'cancel']) - ]) + ]) if SaleOrder.check_access_rights('read', raise_exception=False) else 0 if 'order_count' in counters: values['order_count'] = SaleOrder.search_count([ ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), ('state', 'in', ['sale', 'done']) - ]) + ]) if SaleOrder.check_access_rights('read', raise_exception=False) else 0 return values