Skip to content
Snippets Groups Projects
Commit aff1dc1e authored by Victor Feyens's avatar Victor Feyens
Browse files

[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#38062

Signed-off-by: default avatarpimodoo <pimodoo@users.noreply.github.com>
parent 02037bc2
Branches
Tags
No related merge requests found
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment