From b17d943d98a2573be0392149daf3cf6de6caa1eb Mon Sep 17 00:00:00 2001 From: Antoine Prieels Date: Wed, 23 Sep 2020 11:58:12 +0000 Subject: [PATCH] [FIX] pos_six: Prepare for the certification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The balance operation is performed automatically at the end of the day but it doesn't print any receipt. We add the possibility to perform the balance manually to get a receipt showing all the transactions of the day. - By default, DCC is set to true, but it requires a different implementation. As we don't support it, Six asked us to changed the variable to False, to make it clearer in case of debugging. closes odoo/odoo#58360 X-original-commit: bc5ea7e3d3b694bbe88b14c10cd5cc80ca617e48 Signed-off-by: pimodoo Signed-off-by: Antoine Prieƫls --- addons/pos_six/__manifest__.py | 4 ++++ addons/pos_six/static/src/js/BalanceButton.js | 21 +++++++++++++++++++ addons/pos_six/static/src/js/Chrome.js | 17 +++++++++++++++ addons/pos_six/static/src/js/payment_six.js | 17 +++++++++++++++ .../pos_six/static/src/xml/BalanceButton.xml | 12 +++++++++++ addons/pos_six/static/src/xml/Chrome.xml | 10 +++++++++ addons/pos_six/views/point_of_sale_assets.xml | 2 ++ 7 files changed, 83 insertions(+) create mode 100644 addons/pos_six/static/src/js/BalanceButton.js create mode 100644 addons/pos_six/static/src/js/Chrome.js create mode 100644 addons/pos_six/static/src/xml/BalanceButton.xml create mode 100644 addons/pos_six/static/src/xml/Chrome.xml diff --git a/addons/pos_six/__manifest__.py b/addons/pos_six/__manifest__.py index d59c415b353..580f37fc1d9 100644 --- a/addons/pos_six/__manifest__.py +++ b/addons/pos_six/__manifest__.py @@ -11,6 +11,10 @@ 'views/pos_payment_method_views.xml', 'views/point_of_sale_assets.xml', ], + 'qweb': [ + 'static/src/xml/BalanceButton.xml', + 'static/src/xml/Chrome.xml', + ], 'depends': ['point_of_sale'], 'installable': True, 'license': 'OEEL-1', diff --git a/addons/pos_six/static/src/js/BalanceButton.js b/addons/pos_six/static/src/js/BalanceButton.js new file mode 100644 index 00000000000..a792aa3333d --- /dev/null +++ b/addons/pos_six/static/src/js/BalanceButton.js @@ -0,0 +1,21 @@ +odoo.define('pos_six.BalanceButton', function(require) { + 'use strict'; + + const PosComponent = require('point_of_sale.PosComponent'); + const Registries = require('point_of_sale.Registries'); + + class BalanceButton extends PosComponent { + sendBalance() { + this.env.pos.payment_methods.map(pm => { + if (pm.use_payment_terminal === 'six') { + pm.payment_terminal.send_balance(); + } + }); + } + } + BalanceButton.template = 'BalanceButton'; + + Registries.Component.add(BalanceButton); + + return BalanceButton; +}); diff --git a/addons/pos_six/static/src/js/Chrome.js b/addons/pos_six/static/src/js/Chrome.js new file mode 100644 index 00000000000..0df6c4e1dc7 --- /dev/null +++ b/addons/pos_six/static/src/js/Chrome.js @@ -0,0 +1,17 @@ +odoo.define('pos_six.chrome', function (require) { + 'use strict'; + + const Chrome = require('point_of_sale.Chrome'); + const Registries = require('point_of_sale.Registries'); + + const PosSixChrome = (Chrome) => + class extends Chrome { + get balanceButtonIsShown() { + return this.env.pos.payment_methods.some(pm => pm.use_payment_terminal === 'six'); + } + }; + + Registries.Component.extend(Chrome, PosSixChrome); + + return Chrome; +}); diff --git a/addons/pos_six/static/src/js/payment_six.js b/addons/pos_six/static/src/js/payment_six.js index bc4633d1fd1..2eeb9b7dbe5 100644 --- a/addons/pos_six/static/src/js/payment_six.js +++ b/addons/pos_six/static/src/js/payment_six.js @@ -33,6 +33,7 @@ var PaymentSix = PaymentInterface.extend({ settings.connectionIPString = this.payment_method.six_terminal_ip; settings.connectionIPPort = "80"; settings.integratorId = "175d97a0-2a88-4413-b920-e90037b582ac"; + settings.dcc = false; this.terminal = new timapi.Terminal(settings); this.terminal.setPosId(this.pos.pos_session.name); @@ -40,6 +41,7 @@ var PaymentSix = PaymentInterface.extend({ this.terminalListener = new timapi.DefaultTerminalListener(); this.terminalListener.transactionCompleted = this._onTransactionComplete.bind(this); + this.terminalListener.balanceCompleted = this._onBalanceComplete.bind(this); this.terminal.addListener(this.terminalListener); var recipients = [timapi.constants.Recipient.merchant, timapi.constants.Recipient.cardholder]; @@ -83,6 +85,10 @@ var PaymentSix = PaymentInterface.extend({ return this._sendTransaction(timapi.constants.TransactionType.reversal); }, + send_balance: function () { + this.terminal.balanceAsync(); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -113,6 +119,17 @@ var PaymentSix = PaymentInterface.extend({ } }, + _onBalanceComplete: function (event, data) { + if (event.exception) { + Gui.showPopup('ErrorPopup',{ + 'title': _t('Balance Failed'), + 'body': _t('The balance operation failed.'), + }); + } else { + this._printReceipts(data.printData.receipts); + } + }, + _printReceipts: function (receipts) { _.forEach(receipts, (receipt) => { var value = receipt.value.replace(/\n/g, "
"); diff --git a/addons/pos_six/static/src/xml/BalanceButton.xml b/addons/pos_six/static/src/xml/BalanceButton.xml new file mode 100644 index 00000000000..e68d7ae397a --- /dev/null +++ b/addons/pos_six/static/src/xml/BalanceButton.xml @@ -0,0 +1,12 @@ + + + + +
+ + Send Balance + +
+
+ +
diff --git a/addons/pos_six/static/src/xml/Chrome.xml b/addons/pos_six/static/src/xml/Chrome.xml new file mode 100644 index 00000000000..1187e4f5a44 --- /dev/null +++ b/addons/pos_six/static/src/xml/Chrome.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/addons/pos_six/views/point_of_sale_assets.xml b/addons/pos_six/views/point_of_sale_assets.xml index 7bb3693a356..dbca83d95d5 100644 --- a/addons/pos_six/views/point_of_sale_assets.xml +++ b/addons/pos_six/views/point_of_sale_assets.xml @@ -3,6 +3,8 @@