From 0efc1b3384bee95cdfa45bd2f511898525c85f7f Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 10 Jun 2021 12:05:43 +0000 Subject: [PATCH] [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 Signed-off-by: pimodoo --- addons/point_of_sale/models/pos_session.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 2e2efc37d43..aa83a5dab1d 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -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'})