From b5902c3fa23c444565eaf0b1aa6d8f956ce14453 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 31 Jan 2020 10:12:49 +0000 Subject: [PATCH] [FIX] sale: allow invoice creation from public user - Activate automatic invoicing after successful payment - Go to the eCommerce with the public user - Purchase an item An error occurs because a `list` has no attribute `id`. The root cause is the following line: https://github.com/odoo/odoo/commit/3abe78087a0426ad2783942baa01e1d5fbdff2d9#diff-39d0613187d36f16c541734e80925e9dR556 We want to allow the following scenarios: - a saleman generates an invoice for its customer but doesn't have accounting rights => check on `sale.order` - an accountant generates an invoice from a SO he can read but not modify => check on `account.move` - an invoice is generated from a purchase on the ecommerce => use of `sudo` in calling methods opw-2185680 closes odoo/odoo#44400 X-original-commit: 9ef6282fe51bbd3f0ec56d7ac420d9ffe5c46331 Signed-off-by: Nicolas Martinelli (nim) Co-authored-by: alt-odoo Co-authored-by: Thibault Francois --- addons/sale/models/sale.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index e234ac6ea61..cd0049cc23c 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -6,7 +6,7 @@ from functools import partial from itertools import groupby from odoo import api, fields, models, SUPERUSER_ID, _ -from odoo.exceptions import UserError, ValidationError +from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.misc import formatLang from odoo.osv import expression from odoo.tools import float_is_zero, float_compare @@ -580,8 +580,12 @@ class SaleOrder(models.Model): :param final: if True, refunds will be generated if necessary :returns: list of created invoices """ - if not self.env.user.has_group('sales_team.group_sale_salesman'): - return [] + if not self.env['account.move'].check_access_rights('create', False): + try: + self.check_access_rights('write') + self.check_access_rule('write') + except AccessError: + return self.env['account.move'] precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')