[FIX] pos_six: Prepare for the certification

- 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 <pimodoo@users.noreply.github.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
This commit is contained in:
Antoine Prieels
2020-09-23 14:28:45 +00:00
parent 3c12f91fda
commit b17d943d98
7 changed files with 83 additions and 0 deletions
+4
View File
@@ -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',
@@ -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;
});
+17
View File
@@ -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;
});
@@ -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, "<br />");
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="BalanceButton" owl="1">
<div class="header-button balance-button" t-on-click="sendBalance">
<span class="lock-button">
Send Balance
</span>
</div>
</t>
</templates>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="Chrome" t-inherit="point_of_sale.Chrome" t-inherit-mode="extension" owl="1">
<xpath expr="//SyncNotification" position="after">
<BalanceButton t-if="balanceButtonIsShown" />
</xpath>
</t>
</templates>
@@ -3,6 +3,8 @@
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_six/static/lib/six_timapi/timapi.js"></script>
<script type="text/javascript" src="/pos_six/static/src/js/BalanceButton.js"></script> -->
<script type="text/javascript" src="/pos_six/static/src/js/Chrome.js"></script>
<script type="text/javascript" src="/pos_six/static/src/js/models.js"></script>
<script type="text/javascript" src="/pos_six/static/src/js/payment_six.js"></script>
</xpath>