From 01d893be4b528b7bd9970e630503d2623b2d27f7 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 9 Jul 2021 15:28:51 +0200 Subject: [PATCH] [FIX] account_spread_cost_revenue: disable rights when checking auto spread --- .../models/account_invoice_line.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/account_spread_cost_revenue/models/account_invoice_line.py b/account_spread_cost_revenue/models/account_invoice_line.py index 88fe9a647..cf5e30b63 100644 --- a/account_spread_cost_revenue/models/account_invoice_line.py +++ b/account_spread_cost_revenue/models/account_invoice_line.py @@ -87,9 +87,13 @@ class AccountInvoiceLine(models.Model): spread_type = ( 'sale' if line.invoice_type in ['out_invoice', 'out_refund'] else 'purchase') - spread_auto = self.env['account.spread.template.auto'].search( - [('template_id.auto_spread', '=', True), - ('template_id.spread_type', '=', spread_type)]) + # Search with sudo() so that no template access is required in order + # to confirm invoices to which no template applies + spread_auto = self.env['account.spread.template.auto'].sudo().search([ + ('template_id.auto_spread', '=', True), + ('template_id.spread_type', '=', spread_type), + ('company_id', '=', line.company_id.id) + ]) matched = spread_auto.filtered(lambda a, i=line: _filter_line(a, i)) template = matched.mapped('template_id') if not template: