From cded24889f896a29e11a85fab2880e9013079aa0 Mon Sep 17 00:00:00 2001 From: "Pedram (PEBR)" Date: Fri, 1 Sep 2023 07:03:31 +0000 Subject: [PATCH] [FIX] point_of_sale: cannot close POS session without accounting rights The commit f5ce6c5979e5fba1ccb7e30c8125cd7b97534925 introduced a regression that prevents closing a POS session if the user does not have accounting and inventory access rights. opw-3487462 closes odoo/odoo#134055 X-original-commit: 6f43bc1972ac60e9365b40f53ee8966270e78848 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Pedram Bi Ria (pebr) --- addons/point_of_sale/models/pos_session.py | 2 +- .../point_of_sale/tests/test_point_of_sale_flow.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 5c4d2cc73dc..ffc1b83f06d 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -330,7 +330,7 @@ class PosSession(models.Model): self.move_id.sudo().with_company(self.company_id)._post() #We need to write the price_subtotal and price_total here because if we do it earlier the compute functions will overwrite it here /account/models/account_move_line.py _compute_totals for dummy, amount_data in data['sales'].items(): - self.env['account.move.line'].browse(amount_data['move_line_id']).sudo().write({ + self.env['account.move.line'].browse(amount_data['move_line_id']).sudo().with_company(self.company_id).write({ 'price_subtotal': abs(amount_data['amount_converted']), 'price_total': abs(amount_data['amount_converted']) + abs(amount_data['tax_amount']), }) diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index 8fc9777ca6e..fdbec7dc3a5 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -1675,7 +1675,17 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): }) order_payment.with_context(**payment_context).check() session_id = self.pos_config.current_session_id - self.pos_config.current_session_id.action_pos_session_closing_control() + + # closing the session with basic pos access + pos_user = self.env['res.users'].create({ + 'name': "PoS user", + 'login': "pos_user", + 'email': "pos_user@yourcompany.com", + 'groups_id': [(6, 0, [self.ref('base.group_user'), self.ref('point_of_sale.group_pos_user')])], + }) + + self.pos_config.current_session_id.with_user(pos_user).action_pos_session_closing_control() + #get journal entries created aml = session_id.move_id.line_ids.filtered(lambda x: x.account_id == self.account1 and x.tax_ids == self.tax1) self.assertEqual(aml.price_total, 220)