[FIX] point_of_sale: allow user to close session

If a user has no accounting permission, when he opens/closes a POS
session (without any sale), he will not be able to close the session

To reproduce the error:
(Use demo data)
1. Remove all Marc Demo's permissions for the Accounting module
2. Login with Marc Demo
3. Open a POS Session
4. Close the POS Session

Error: "Sorry, you are not allowed to delete documents of type 'Journal
Entries' (account.move) [...]"

Note: if the user processes at least one order during the POS session,
he will be able to close it thanks to sudo mode:
https://github.com/odoo/odoo/blob/369331dfdc144cf852c80c99d00ce8d5da843be1/addons/point_of_sale/models/pos_session.py#L302

OPW-2523187

closes odoo/odoo#72516

X-original-commit: 766d03c84c1e51e000494d49265c32ab096d602e
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Adrien Widart
2021-06-22 09:30:49 +00:00
parent a755ed2475
commit 0efc1b3384
+3 -2
View File
@@ -295,6 +295,7 @@ class PosSession(models.Model):
def _validate_session(self, balancing_account=False, amount_to_balance=0):
self.ensure_one()
sudo = self.user_has_groups('point_of_sale.group_pos_user')
if self.order_ids or self.statement_ids.line_ids:
self.cash_real_transaction = self.cash_register_total_entry_encoding
self.cash_real_expected = self.cash_register_balance_end
@@ -307,7 +308,7 @@ class PosSession(models.Model):
try:
data = self.with_company(self.company_id)._create_account_move(balancing_account, amount_to_balance)
except AccessError as e:
if self.user_has_groups('point_of_sale.group_pos_user'):
if sudo:
data = self.sudo().with_company(self.company_id)._create_account_move(balancing_account, amount_to_balance)
else:
raise e
@@ -334,7 +335,7 @@ class PosSession(models.Model):
else:
self.move_id.unlink()
elif not self.cash_register_id.difference:
cash_register = self.cash_register_id
cash_register = self.cash_register_id.sudo() if sudo else self.cash_register_id
cash_register.pos_session_id = False
cash_register.unlink()
self.write({'state': 'closed'})