From 1ef89f0928dafad25a0820cf08734fdd000a4bb0 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 8 Oct 2019 08:53:03 +0000 Subject: [PATCH] [FIX] point_of_sale: use sudo instead of with_user(SUPERUSER_ID). Since https://github.com/odoo/odoo/pull/34297, sudo() allows to keep current user information when creating/modifying records. There is no need anymore to use with_user(SUPERUSER_ID) to have sudo rights. This commit ensures the user information is kept when creating pos sessions, instead of having OdooBot as create_user. closes odoo/odoo#38441 X-original-commit: aff1dc1ea68c345fb2632f9666dc298f685b8748 Signed-off-by: Victor Feyens (vfe) --- addons/point_of_sale/models/pos_session.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index d3d5775835a..2092baf0f3d 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -4,7 +4,7 @@ from collections import defaultdict from datetime import timedelta -from odoo import api, fields, models, SUPERUSER_ID, _ +from odoo import api, fields, models, _ from odoo.exceptions import UserError, ValidationError from odoo.tools import float_is_zero @@ -186,10 +186,10 @@ class PosSession(models.Model): if values.get('name'): pos_name += ' ' + values['name'] - uid = SUPERUSER_ID if self.env.user.has_group('point_of_sale.group_pos_user') else self.env.user.id - cash_payment_methods = pos_config.payment_method_ids.filtered(lambda pm: pm.is_cash_count) statement_ids = self.env['account.bank.statement'] + if self.user_has_groups('point_of_sale.group_pos_user'): + statement_ids = statement_ids.sudo() for cash_journal in cash_payment_methods.mapped('cash_journal_id'): ctx['journal_id'] = cash_journal.id if pos_config.cash_control and cash_journal.type == 'cash' else False st_values = { @@ -198,7 +198,7 @@ class PosSession(models.Model): 'name': pos_name, 'balance_start': self.env["account.bank.statement"]._get_opening_balance(cash_journal.id) if cash_journal.type == 'cash' else 0 } - statement_ids |= statement_ids.with_context(ctx).with_user(uid).create(st_values) + statement_ids |= statement_ids.with_context(ctx).create(st_values) values.update({ 'name': pos_name, @@ -206,7 +206,10 @@ class PosSession(models.Model): 'config_id': config_id, }) - res = super(PosSession, self.with_context(ctx).with_user(uid)).create(values) + if self.user_has_groups('point_of_sale.group_pos_user'): + res = super(PosSession, self.with_context(ctx).sudo()).create(values) + else: + res = super(PosSession, self.with_context(ctx)).create(values) if not pos_config.cash_control: res.action_pos_session_open()