From e88df804e72aa5e0821b47937c4c617bd311ae06 Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Wed, 13 Feb 2019 14:33:52 +0100 Subject: [PATCH] [REF] Contract: set order count to 0 if no access to orders --- product_contract/models/contract.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/product_contract/models/contract.py b/product_contract/models/contract.py index 56279cef..7149eae4 100644 --- a/product_contract/models/contract.py +++ b/product_contract/models/contract.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.exceptions import AccessError from odoo.tools.translate import _ @@ -14,11 +15,15 @@ class AccountAnalyticAccount(models.Model): @api.depends('recurring_invoice_line_ids') def _compute_sale_order_count(self): for rec in self: - rec.sale_order_count = len( - rec.recurring_invoice_line_ids.mapped( - 'sale_order_line_id.order_id' + try: + order_count = len( + rec.recurring_invoice_line_ids.mapped( + 'sale_order_line_id.order_id' + ) ) - ) + except AccessError: + order_count = 0 + rec.sale_order_count = order_count @api.multi def action_view_sales_orders(self):