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 @@