From a1508eddc9152bbf2f93213173299dfda93197a2 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Wed, 1 Dec 2021 12:49:00 +0000 Subject: [PATCH] [FIX] point_of_sale, l10n_fr_pos_cert: allow to close session after 24h - Use a company located in France - Install point_of_sale and l10n_fr_pos_cert - Open a POS session - Make some orders - Quit session without closing it (Keep session open) - Come back more than 24 hours later - Try to open the session (Continue selling) An UserError is triggered with the following message: "This session has been opened another day. To comply with the French law, you should close sessions on a daily basis. Please close session POS/00007 and open a new one." However, it is not possible to close the session as the closing control is managed in the fontend inside the session. Therefore the POS is stuck as we cannot close the last session, neither open a new one. This fix allows an user with the rights to close a session to connect to the stuck session to close it. He will only have access to the closing control popup, without the possibility to continue selling. opw-2696823 closes odoo/odoo#81110 X-original-commit: 8f14fef9232609b0a6fe3d71606f3d2b016100bb Signed-off-by: Masereel Pierre --- addons/l10n_fr_pos_cert/models/pos.py | 4 --- .../l10n_fr_pos_cert/static/src/js/Chrome.js | 25 +++++++++++++++++ .../static/src/js/Popups/ClosePosPopup.js | 27 +++++++++++++++++++ .../static/src/js/Popups/ClosePosPopup.js | 8 ++++++ .../static/src/xml/Popups/ClosePosPopup.xml | 2 +- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 addons/l10n_fr_pos_cert/static/src/js/Chrome.js create mode 100644 addons/l10n_fr_pos_cert/static/src/js/Popups/ClosePosPopup.js diff --git a/addons/l10n_fr_pos_cert/models/pos.py b/addons/l10n_fr_pos_cert/models/pos.py index 1cd87ebdfc2..7a69ca08ada 100644 --- a/addons/l10n_fr_pos_cert/models/pos.py +++ b/addons/l10n_fr_pos_cert/models/pos.py @@ -28,10 +28,6 @@ class pos_session(models.Model): def _check_session_timing(self): self.ensure_one() - date_today = datetime.utcnow() - session_start = Datetime.from_string(self.start_at) - if not date_today - timedelta(hours=24) <= session_start: - raise UserError(_("This session has been opened another day. To comply with the French law, you should close sessions on a daily basis. Please close session %s and open a new one.", self.name)) return True def open_frontend_cb(self): diff --git a/addons/l10n_fr_pos_cert/static/src/js/Chrome.js b/addons/l10n_fr_pos_cert/static/src/js/Chrome.js new file mode 100644 index 00000000000..f68a7e7f912 --- /dev/null +++ b/addons/l10n_fr_pos_cert/static/src/js/Chrome.js @@ -0,0 +1,25 @@ +odoo.define('l10n_fr_pos_cert.Chrome', function (require) { + 'use strict'; + + const Chrome = require('point_of_sale.Chrome'); + const Registries = require('point_of_sale.Registries'); + + const PosFrCertChrome = (Chrome) => + class extends Chrome { + async start() { + await super.start(); + if (this.env.pos.is_french_country() && this.env.pos.pos_session.start_at) { + const now = Date.now(); + let limitDate = new Date(this.env.pos.pos_session.start_at); + limitDate.setDate(limitDate.getDate() + 1); + if (limitDate < now) { + this.showPopup('ClosePosPopup'); + } + } + } + }; + + Registries.Component.extend(Chrome, PosFrCertChrome); + + return Chrome; +}); diff --git a/addons/l10n_fr_pos_cert/static/src/js/Popups/ClosePosPopup.js b/addons/l10n_fr_pos_cert/static/src/js/Popups/ClosePosPopup.js new file mode 100644 index 00000000000..8d5d0157e32 --- /dev/null +++ b/addons/l10n_fr_pos_cert/static/src/js/Popups/ClosePosPopup.js @@ -0,0 +1,27 @@ +odoo.define('l10n_fr_pos_cert.ClosePosPopup', function (require) { + 'use strict'; + + const ClosePosPopup = require('point_of_sale.ClosePosPopup'); + const Registries = require('point_of_sale.Registries'); + + const PosFrCertClosePopup = (ClosePosPopup) => + class extends ClosePosPopup { + sessionIsOutdated() { + let isOutdated = false; + if (this.env.pos.is_french_country() && this.env.pos.pos_session.start_at) { + const now = Date.now(); + let limitDate = new Date(this.env.pos.pos_session.start_at); + limitDate.setDate(limitDate.getDate() + 1); + isOutdated = limitDate < now; + } + return isOutdated; + } + canCancel() { + return super.canCancel() && !this.sessionIsOutdated(); + } + }; + + Registries.Component.extend(ClosePosPopup, PosFrCertClosePopup); + + return ClosePosPopup; +}); diff --git a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js index fa005a0ef16..0ae622cd392 100644 --- a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js @@ -115,6 +115,14 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { canCloseSession() { return !this.cashControl || !this.hasDifference() || this.state.acceptClosing; } + canCancel() { + return true; + } + cancelPopup() { + if (this.canCancel()) { + this.cancel(); + } + } closePos() { this.trigger('close-pos'); } diff --git a/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml b/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml index 04f215cebed..2cf3a122b9f 100644 --- a/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml +++ b/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml @@ -94,7 +94,7 @@