diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index 21b924ddf1e..1237600102b 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -3413,19 +3413,6 @@ td { cursor: pointer; } -.cashbox-input { - margin: auto; - line-height: 74px; - font-size: 16px; - border: solid 1px rgb(202, 202, 202); - border-top-width: 0px; - cursor: pointer; - padding-left: 30px; - padding-right: 30px; - flex-grow: 1; - flex-basis: 100%; -} - .currencyCashBox { font-size: 30px; } @@ -3541,3 +3528,46 @@ td { overflow: visible; } } + +.pos .cashbox-button { + height: 54px; + width: 54px; + font-weight: bold; + vertical-align: middle; + color: #555555; + border-radius: 0; + border: none; + border-right: 1px solid; + border-bottom: 1px solid; + border-color: #bfbfbf; + transition: all 150ms linear; +} + +.pos .cashbox-input { + line-height: 74px; + border: solid 1px rgb(202, 202, 202); + border-top-width: 0px; + cursor: pointer; + background: white; + display: flex; + justify-content: space-between; +} + +.cashbox-input .input-title { + margin-left: 10px; + margin-right: 10px; + font-weight: bold; + font-size: 19px; +} + +.cashbox-input .input-amount { + margin-left: 10px; + margin-right: 10px; + padding-right: 8px; +} + +.cashbox-notes { + font-style: italic; + font-weight: 350; + width: 95%; +} diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/CashBoxOpening.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/CashBoxOpening.js index be42e45dabe..9cc5cb6f6ee 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/CashBoxOpening.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/CashBoxOpening.js @@ -1,42 +1,71 @@ -odoo.define('point_of_sale.CashBoxOpening', function(require) { +odoo.define('point_of_sale.CashOpeningPopup', function(require) { 'use strict'; + const { useState, useRef} = owl.hooks; + const { useListener } = require('web.custom_hooks'); + const NumberBuffer = require('point_of_sale.NumberBuffer'); const PosComponent = require('point_of_sale.PosComponent'); + const AbstractAwaitablePopup = require('point_of_sale.AbstractAwaitablePopup'); const Registries = require('point_of_sale.Registries'); - const { Gui } = require('point_of_sale.Gui'); - class CashBoxOpening extends PosComponent { + + class CashOpeningPopup extends AbstractAwaitablePopup { constructor() { super(...arguments); - this.changes = {}; - this.defaultValue = this.env.pos.bank_statement.balance_start || 0; - this.symbol = this.env.pos.currency.symbol; - } - captureChange(event) { - this.changes[event.target.name] = event.target.value; + this.cashBoxValue = this.env.pos.bank_statement.balance_start || 0;; + this.currency = this.env.pos.currency; + this.state = useState({ + notes: "", + }); + useListener('numpad-click-input', this._updateCashAmount); + useListener('update-cash', this._updateCashAmount); + this.inputRef = useRef('input'); + NumberBuffer.use({ + nonKeyboardInputEvent: 'numpad-click-input', + triggerAtInput: 'update-cash', + useWithBarcode: false, + }); } + startSession() { - let cashOpening = this.changes.cashBoxValue? this.changes.cashBoxValue: this.defaultValue; - if(isNaN(cashOpening)) { - Gui.showPopup('ErrorPopup',{ - 'title': 'Wrong value', - 'body': 'Please insert a correct value.', - }); + if(!parseFloat(this.cashBoxValue)) return; - } - this.env.pos.bank_statement.balance_start = cashOpening; + this.env.pos.bank_statement.balance_start = parseFloat(this.cashBoxValue); this.env.pos.pos_session.state = 'opened'; - this.props.cashControl.cashControl = false; this.rpc({ - model: 'pos.session', + model: 'pos.session', method: 'set_cashbox_pos', - args: [this.env.pos.pos_session.id, cashOpening, this.changes.notes], + args: [this.env.pos.pos_session.id, parseFloat(this.cashBoxValue), this.state.notes], }); + this.trigger('close-popup'); } + + sendInput(value) { + this.trigger('numpad-click-input', { value }); + } + + async _updateCashAmount(event) { + let value = event.detail.value ? event.detail.value : event.detail.key + if(value !== "Backspace") { + if(this.cashBoxValue === 0) { + this.cashBoxValue = value !== "."? value: this.cashBoxValue + value; + } else { + this.cashBoxValue += value; + } + } else { + if(this.cashBoxValue.length > 1) { + this.cashBoxValue = this.cashBoxValue.substring(0, this.cashBoxValue.length -1) + } else { + this.cashBoxValue = 0; + } + } + this.render(); + } + } - CashBoxOpening.template = 'CashBoxOpening'; - Registries.Component.add(CashBoxOpening); + CashOpeningPopup.template = 'CashOpeningPopup'; + Registries.Component.add(CashOpeningPopup); - return CashBoxOpening; + return CashOpeningPopup; }); diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js index 1d83146d557..1bd9f73373b 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js @@ -7,6 +7,7 @@ odoo.define('point_of_sale.ProductScreen', function(require) { const { useListener } = require('web.custom_hooks'); const Registries = require('point_of_sale.Registries'); const { onChangeOrder, useBarcodeReader } = require('point_of_sale.custom_hooks'); + const { Gui } = require('point_of_sale.Gui'); const { useState } = owl.hooks; class ProductScreen extends ControlButtonsMixin(PosComponent) { @@ -32,11 +33,13 @@ odoo.define('point_of_sale.ProductScreen', function(require) { triggerAtInput: 'update-selected-orderline', useWithBarcode: true, }); - let status = this.showCashBoxOpening() - this.state = useState({ cashControl: status, numpadMode: 'quantity' }); + this.state = useState({ numpadMode: 'quantity' }); this.mobile_pane = this.props.mobile_pane || 'right'; } mounted() { + if(this.env.pos.config.cash_control && this.env.pos.pos_session.state == 'opening_control') { + Gui.showPopup('CashOpeningPopup'); + } this.env.pos.on('change:selectedClient', this.render, this); } willUnmount() { @@ -56,11 +59,6 @@ odoo.define('point_of_sale.ProductScreen', function(require) { get currentOrder() { return this.env.pos.get_order(); } - showCashBoxOpening() { - if(this.env.pos.config.cash_control && this.env.pos.pos_session.state == 'opening_control') - return true; - return false; - } async _clickProduct(event) { if (!this.currentOrder) { this.env.pos.add_new_order(); diff --git a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/CashBoxOpening.xml b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/CashBoxOpening.xml index 27193bf93b8..61b6e5bdfb0 100644 --- a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/CashBoxOpening.xml +++ b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/CashBoxOpening.xml @@ -1,27 +1,56 @@ - + - -
-
-

- - Pos closed. -
- - Set a cash opening - - -

-

Opening amount:

- - - -

Notes:

-