From b0670da86ba5ac693887ca6251e390d645aecf03 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 16 Nov 2020 15:47:54 +0000 Subject: [PATCH] [FIX] point_of_sale: prevent closing the same session twice - Create a POS session - Sell some items - Close the session, go to the closing page - Duplicate the browser tab - Close the session in tab 1 - Close the session in tab 2 The journal entries are created twice. There should be a server check before closing the session. opw-2379278 closes odoo/odoo#61860 X-original-commit: 0ba535c5123fecb410fa7546b5bb39a52884ca40 Signed-off-by: Nicolas Martinelli (nim) --- addons/point_of_sale/i18n/point_of_sale.pot | 7 +++++++ addons/point_of_sale/models/pos_session.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index dc8f28c8540..8431f21256f 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -4977,6 +4977,13 @@ msgid "" "customize the reference numbers of your orders." msgstr "" +#. module: point_of_sale +#: code:addons/point_of_sale/models/pos_session.py:0 +#: code:addons/point_of_sale/models/pos_session.py:0 +#, python-format +msgid "This session is already closed." +msgstr "" + #. module: point_of_sale #: model_terms:ir.ui.view,arch_db:point_of_sale.res_config_settings_view_form msgid "This tax is applied to any new product created in the catalog." diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 58cd83b1301..159f8b51788 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -259,6 +259,8 @@ class PosSession(models.Model): def action_pos_session_closing_control(self): self._check_pos_session_balance() for session in self: + if session.state == 'closed': + raise UserError(_('This session is already closed.')) session.write({'state': 'closing_control', 'stop_at': fields.Datetime.now()}) if not session.config_id.cash_control: session.action_pos_session_close() @@ -297,6 +299,8 @@ class PosSession(models.Model): self.cash_real_transaction = self.cash_register_total_entry_encoding self.cash_real_expected = self.cash_register_balance_end self.cash_real_difference = self.cash_register_difference + if self.state == 'closed': + raise UserError(_('This session is already closed.')) self._check_if_no_draft_orders() if self.update_stock_at_closing: self._create_picking_at_end_of_session()