Browse Source

Merge PR #440 into 12.0

Signed-off-by legalsylvain
pull/451/head
OCA-git-bot 5 years ago
parent
commit
f34172a7f7
  1. 3
      pos_payment_terminal/README.rst
  2. 1
      pos_payment_terminal/__init__.py
  3. 22
      pos_payment_terminal/__manifest__.py
  4. 8
      pos_payment_terminal/demo/pos_config.xml
  5. 62
      pos_payment_terminal/i18n/es.po
  6. 69
      pos_payment_terminal/i18n/fr.po
  7. 63
      pos_payment_terminal/i18n/hr_HR.po
  8. 61
      pos_payment_terminal/i18n/it.po
  9. 62
      pos_payment_terminal/i18n/nl_NL.po
  10. 69
      pos_payment_terminal/i18n/pos_payment_terminal.pot
  11. 3
      pos_payment_terminal/models/__init__.py
  12. 14
      pos_payment_terminal/models/account_journal.py
  13. 14
      pos_payment_terminal/models/pos_config.py
  14. 63
      pos_payment_terminal/models/pos_order.py
  15. 11
      pos_payment_terminal/readme/CONFIGURE.rst
  16. 3
      pos_payment_terminal/readme/CONTRIBUTORS.rst
  17. 2
      pos_payment_terminal/readme/DESCRIPTION.rst
  18. 6
      pos_payment_terminal/readme/INSTALL.rst
  19. 1
      pos_payment_terminal/readme/USAGE.rst
  20. BIN
      pos_payment_terminal/static/description/account_journal_form.png
  21. BIN
      pos_payment_terminal/static/description/icon.png
  22. BIN
      pos_payment_terminal/static/description/pos_config.png
  23. 12
      pos_payment_terminal/static/src/css/pos_payment_terminal.css
  24. 69
      pos_payment_terminal/static/src/js/devices.js
  25. 30
      pos_payment_terminal/static/src/js/models.js
  26. 42
      pos_payment_terminal/static/src/js/screens.js
  27. 10
      pos_payment_terminal/static/src/xml/pos_payment_terminal.xml
  28. 1
      pos_payment_terminal/tests/__init__.py
  29. 49
      pos_payment_terminal/tests/test_transactions.py
  30. 16
      pos_payment_terminal/views/account_journal.xml
  31. 13
      pos_payment_terminal/views/assets.xml
  32. 18
      pos_payment_terminal/views/pos_config.xml

3
pos_payment_terminal/README.rst

@ -0,0 +1,3 @@
====================
POS Payment Terminal
====================

1
pos_payment_terminal/__init__.py

@ -0,0 +1 @@
from . import models

22
pos_payment_terminal/__manifest__.py

@ -0,0 +1,22 @@
# © 2014-2016 Aurélien DUMAINE
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'POS Payment Terminal',
'version': '12.0.0.1.1',
'category': 'Point Of Sale',
'summary': 'Manage Payment Terminal device from POS front end',
'author': "Aurélien DUMAINE,GRAP,Akretion,"
"Odoo Community Association (OCA)",
'license': 'AGPL-3',
'depends': ['point_of_sale'],
'data': [
'views/pos_config.xml',
'views/account_journal.xml',
'views/assets.xml',
],
'demo': ['demo/pos_config.xml'],
'qweb': ['static/src/xml/pos_payment_terminal.xml'],
'installable': True,
}

8
pos_payment_terminal/demo/pos_config.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="point_of_sale.pos_config_main" model="pos.config">
<field name="iface_payment_terminal" eval="True"/>
</record>
</odoo>

62
pos_payment_terminal/i18n/es.po

@ -0,0 +1,62 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
# enjolras <yo@miguelrevilla.com>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-01 02:01+0000\n"
"PO-Revision-Date: 2018-03-01 02:01+0000\n"
"Last-Translator: enjolras <yo@miguelrevilla.com>, 2018\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr "Tarjeta"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr "Talón"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr "Diario"
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Payment Mode"
msgstr "Forma de pago"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr "Seleccione la forma de pega enviada al terminal de pago"
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr "Iniciar transacción"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "pos.config"
msgstr "Configuración del TPV"

69
pos_payment_terminal/i18n/fr.po

@ -0,0 +1,69 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-01-18 10:52+0000\n"
"PO-Revision-Date: 2020-01-18 10:52+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_pos_config__iface_payment_terminal
msgid "A payment terminal is available on the Proxy"
msgstr "Un terminal de paiment est disponible sur le proxy"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr "Carte"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr "Chèque"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr "Journal"
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Payment Mode"
msgstr "Moyen de paiement"
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_pos_config__iface_payment_terminal
#: model_terms:ir.ui.view,arch_db:pos_payment_terminal.view_pos_config_form
msgid "Payment Terminal"
msgstr "Terminal de paiement"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "Point of Sale Configuration"
msgstr "Paramétrage du point de vente"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr "Commandes du point de vente"
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr "Sélectionner le mode de paiement envoyé au terminal de paiement"
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr "Démarrer la transaction"

63
pos_payment_terminal/i18n/hr_HR.po

@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
# Translators:
# Bole <bole@dajmi5.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-13 19:51+0000\n"
"PO-Revision-Date: 2016-12-13 19:51+0000\n"
"Last-Translator: Bole <bole@dajmi5.com>, 2017\n"
"Language-Team: Croatian (Croatia) (https://www.transifex.com/oca/teams/23907/"
"hr_HR/)\n"
"Language: hr_HR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr "Kartica"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr "Ček"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr "Dnevnik"
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Payment Mode"
msgstr "Način plaćanja"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr "Odaberite način plaćanja korišten na naplatnom terminalu"
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr "Započni transakciju"
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "pos.config"
msgstr "pos.config"

61
pos_payment_terminal/i18n/it.po

@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
# Translators:
# Francesco Fresta <franco.fresta@gmail.com>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-01 02:01+0000\n"
"PO-Revision-Date: 2018-03-01 02:01+0000\n"
"Last-Translator: Francesco Fresta <franco.fresta@gmail.com>, 2018\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr ""
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Payment Mode"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr ""
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "pos.config"
msgstr "pos.config"

62
pos_payment_terminal/i18n/nl_NL.po

@ -0,0 +1,62 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
# Translators:
# Peter Hageman <hageman.p@gmail.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-30 02:44+0000\n"
"PO-Revision-Date: 2017-05-30 02:44+0000\n"
"Last-Translator: Peter Hageman <hageman.p@gmail.com>, 2017\n"
"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/"
"teams/23907/nl_NL/)\n"
"Language: nl_NL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr ""
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Payment Mode"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__pos_terminal_payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr ""
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "pos.config"
msgstr "pos.config"

69
pos_payment_terminal/i18n/pos_payment_terminal.pot

@ -0,0 +1,69 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_payment_terminal
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-01-18 10:55+0000\n"
"PO-Revision-Date: 2020-01-18 10:55+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_pos_config__iface_payment_terminal
msgid "A payment terminal is available on the Proxy"
msgstr ""
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Card"
msgstr ""
#. module: pos_payment_terminal
#: selection:account.journal,pos_terminal_payment_mode:0
msgid "Check"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_account_journal
msgid "Journal"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal__payment_mode
msgid "Payment Mode"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,field_description:pos_payment_terminal.field_pos_config__iface_payment_terminal
#: model_terms:ir.ui.view,arch_db:pos_payment_terminal.view_pos_config_form
msgid "Payment Terminal"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_config
msgid "Point of Sale Configuration"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model,name:pos_payment_terminal.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_payment_terminal
#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal__payment_mode
msgid "Select the payment mode sent to the payment terminal"
msgstr ""
#. module: pos_payment_terminal
#. openerp-web
#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6
#, python-format
msgid "Start transaction"
msgstr ""

3
pos_payment_terminal/models/__init__.py

@ -0,0 +1,3 @@
from . import pos_config
from . import account_journal
from . import pos_order

14
pos_payment_terminal/models/account_journal.py

@ -0,0 +1,14 @@
# © 2014-2016 Aurélien DUMAINE
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class AccountJournal(models.Model):
_inherit = 'account.journal'
pos_terminal_payment_mode = fields.Selection(
selection=[('card', 'Card'), ('check', 'Check')],
string='Terminal Payment Mode',
help="Select the payment mode sent to the payment terminal")

14
pos_payment_terminal/models/pos_config.py

@ -0,0 +1,14 @@
# © 2014-2016 Aurélien DUMAINE
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
iface_payment_terminal = fields.Boolean(
'Payment Terminal',
help="A payment terminal is available on the Proxy")

63
pos_payment_terminal/models/pos_order.py

@ -0,0 +1,63 @@
# © 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from collections import defaultdict
import logging
from odoo import api, models
_logger = logging.getLogger(__name__)
class PosOrder(models.Model):
_inherit = 'pos.order'
@api.model
def _match_transactions_to_payments(self, pos_order):
payments = pos_order['statement_ids']
transactions = pos_order['transactions']
pos_session = self.env['pos.session'].browse(
pos_order['pos_session_id'])
currency_digits = pos_session.currency_id.decimal_places
card_journals = self.env['account.journal'].search([
('id', 'in', [p[2]['journal_id'] for p in payments]),
('pos_terminal_payment_mode', '!=', False),
])
card_payments = [record[2] for record in payments
if record[2]['journal_id'] in card_journals.ids]
def amount_cents(obj):
if 'amount_cents' in obj:
return obj['amount_cents']
else:
return int(round(obj['amount'] * pow(10, currency_digits)))
try:
for payment, transaction in match(card_payments, transactions,
key=amount_cents):
payment['note'] = transaction['reference']
except ValueError as e:
_logger.error("Error matching transactions to payments: %s",
e.args[0])
def _process_order(self, pos_order):
if pos_order.get('transactions'):
self._match_transactions_to_payments(pos_order)
return super(PosOrder, self)._process_order(pos_order)
def group_by(lists, key):
count = range(len(lists))
d = defaultdict(lambda: tuple([[] for _ in count]))
for i, objects in enumerate(lists):
for obj in objects:
d[key(obj)][i].append(obj)
return d
def match(al, bl, key):
for key, groups in group_by((al, bl), key).items():
if groups[0] and len(groups[0]) != len(groups[1]):
raise ValueError("Missing value for {!r}".format(key))
for val in zip(*groups):
yield val

11
pos_payment_terminal/readme/CONFIGURE.rst

@ -0,0 +1,11 @@
* Go to Point of Sale > Configuration > Point of Sale, and check
the field "Payment Terminal"
.. figure:: ../static/description/pos_config_form.png
* Then, in the same point of sale form, click on "Payment Methods" to
set correctly your account journals.
This module support two payment modes : *card* and *check*, this
option is available in te Point of sale tab.
.. figure:: ../static/description/account_journal_form.png

3
pos_payment_terminal/readme/CONTRIBUTORS.rst

@ -0,0 +1,3 @@
* Aurelien Dumaine
* Alexis de Lattre <alexis.delattre@akretion.com>
* Sylvain LE GAL (https://twitter.com/legalsylvain)

2
pos_payment_terminal/readme/DESCRIPTION.rst

@ -0,0 +1,2 @@
This module adds support for credit card reader and checks printer
in the Point of Sale.

6
pos_payment_terminal/readme/INSTALL.rst

@ -0,0 +1,6 @@
This module is designed to be installed on the
*main Odoo server*. On the *POSbox*, you should install the module
*hw_x* depending on the protocol implemented in your device.
`Ingenico <http://en.wikipedia.org/wiki/Ingenico>`
and old Sagem devices support the Telium protocol implemented in the
*hw_telium_payment_terminal* module.

1
pos_payment_terminal/readme/USAGE.rst

@ -0,0 +1 @@
In the frontend of the POS, when you select a payment method that has a payment mode *card* or *check*, you will have a *Start Transaction* button : if you click on that button, the amount, the currency and the payment mode will be sent to the POSbox.

BIN
pos_payment_terminal/static/description/account_journal_form.png

After

Width: 608  |  Height: 288  |  Size: 18 KiB

BIN
pos_payment_terminal/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

BIN
pos_payment_terminal/static/description/pos_config.png

After

Width: 524  |  Height: 262  |  Size: 18 KiB

12
pos_payment_terminal/static/src/css/pos_payment_terminal.css

@ -0,0 +1,12 @@
.payment-terminal-transaction-start button {
width: 150px;
height: 60px;
font-size: 18px;
cursor: pointer;
text-align:center;
box-sizing: border-box;
-moz-box-sizing: border-box;
left: 105%;
bottom: 10px;
position: absolute;
}

69
pos_payment_terminal/static/src/js/devices.js

@ -0,0 +1,69 @@
/*
POS Payment Terminal module for Odoo
Copyright (C) 2014-2016 Aurélien DUMAINE
Copyright (C) 2014-2016 Akretion (www.akretion.com)
@author: Aurélien DUMAINE
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
*/
odoo.define('pos_payment_terminal.devices', function (require) {
"use strict";
var devices = require('point_of_sale.devices');
devices.ProxyDevice.include({
init: function(parents, options) {
var self = this;
self._super(parents, options);
self.on('change:status', this, function(eh, status) {
if(!self.pos.chrome.screens) {
return;
}
var paymentwidget = self.pos.chrome.screens.payment;
var drivers = status.newValue.drivers;
var order = self.pos.get_order();
var in_transaction = false;
Object.keys(drivers).forEach(function(driver_name) {
if (drivers[driver_name].hasOwnProperty("in_transaction")) {
in_transaction = in_transaction || drivers[driver_name].in_transaction;
}
var transactions = drivers[driver_name].latest_transactions;
if(!!transactions && transactions.hasOwnProperty(order.uid)) {
var previous_transactions = order.transactions;
order.transactions = transactions[order.uid];
var has_new_transactions = (
!previous_transactions ||
previous_transactions.length < order.transactions.length
);
if(has_new_transactions && order.is_paid()) {
paymentwidget.validate_order();
}
}
});
order.in_transaction = in_transaction;
paymentwidget.order_changes();
});
},
payment_terminal_transaction_start: function(line_cid, currency_iso, currency_decimals){
var line;
var order = this.pos.get_order();
var lines = order.get_paymentlines();
for ( var i = 0; i < lines.length; i++ ) {
if (lines[i].cid === line_cid) {
line = lines[i];
}
}
var data = {'amount' : line.get_amount(),
'currency_iso' : currency_iso,
'currency_decimals' : currency_decimals,
'payment_mode' : line.cashregister.journal.pos_terminal_payment_mode,
'order_id': order.uid};
this.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)});
},
});
});

30
pos_payment_terminal/static/src/js/models.js

@ -0,0 +1,30 @@
/*
POS Payment Terminal module for Odoo
Copyright (C) 2014-2016 Aurélien DUMAINE
Copyright (C) 2014-2016 Akretion (www.akretion.com)
@author: Aurélien DUMAINE
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
*/
odoo.define('pos_payment_terminal.models', function (require) {
"use strict";
var models = require('point_of_sale.models');
var _orderproto = models.Order.prototype;
models.load_fields('account.journal', ['pos_terminal_payment_mode']);
models.Order = models.Order.extend({
initialize: function(){
_orderproto.initialize.apply(this, arguments);
this.in_transaction = false;
},
export_as_JSON: function() {
var vals = _orderproto.export_as_JSON.apply(this, arguments);
vals['transactions'] = this.transactions || {};
return vals;
}
});
});

42
pos_payment_terminal/static/src/js/screens.js

@ -0,0 +1,42 @@
/*
POS Payment Terminal module for Odoo
Copyright (C) 2014-2016 Aurélien DUMAINE
Copyright (C) 2014-2016 Akretion (www.akretion.com)
@author: Aurélien DUMAINE
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
*/
odoo.define('pos_payment_terminal.screens', function (require) {
"use strict";
var screens = require('point_of_sale.screens');
screens.PaymentScreenWidget.include({
render_paymentlines : function(){
this._super.apply(this, arguments);
var self = this;
this.$('.paymentlines-container').unbind('click').on('click', '.payment-terminal-transaction-start', function(event){
// Why this "on" thing links severaltime the button to the action
// if I don't use "unlink" to reset the button links before ?
self.pos.get_order().in_transaction = true;
self.order_changes();
self.pos.proxy.payment_terminal_transaction_start($(this).data('cid'), self.pos.currency.name, self.pos.currency.decimals);
});
},
order_changes: function(){
this._super.apply(this, arguments);
var order = this.pos.get_order();
if (!order) {
return;
} else if (order.in_transaction) {
self.$('.next').html('<img src="/web/static/src/img/spin.png" style="animation: fa-spin 1s infinite steps(12);width: 20px;height: auto;vertical-align: middle;">');
} else {
self.$('.next').html('Validate <i class="fa fa-angle-double-right"></i>');
}
}
});
});

10
pos_payment_terminal/static/src/xml/pos_payment_terminal.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PaymentScreen-Paymentlines" >
<t t-jquery=".col-name" t-operation="append">
<t t-if="line.cashregister.journal.pos_terminal_payment_mode and widget.pos.config.iface_payment_terminal">
<button class="payment-terminal-transaction-start" t-att-data-cid='line.cid'>Start transaction</button>
</t>
</t>
</t>
</templates>

1
pos_payment_terminal/tests/__init__.py

@ -0,0 +1 @@
from . import test_transactions

49
pos_payment_terminal/tests/test_transactions.py

@ -0,0 +1,49 @@
# Copyright (C) 2018-TODAY ACSONE SA/NV (<https://www.acsone.eu>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon
class TestTransactions(TestPointOfSaleCommon):
def test_matching(self):
card_journal_id = self.env['account.journal'].create({
'name': 'Card Journal',
'code': 'CARD',
'type': 'bank',
'pos_terminal_payment_mode': 'card',
}).id
cash_journal_id = 0
pos_order = {
'pos_session_id': self.pos_order_session0.id,
'statement_ids': [
(0, 0, {
'name': 'Payment1',
'amount': 45.2,
'journal_id': card_journal_id,
}),
(0, 0, {
'name': 'Payment2',
'amount': 10.5,
'journal_id': card_journal_id,
}),
(0, 0, {
'name': 'Payment3',
'amount': 22.0,
'journal_id': cash_journal_id,
}),
],
'transactions': [
{
'reference': 'ABCDE',
'amount_cents': 1050,
},
{
'reference': 'XPTO',
'amount_cents': 4520,
},
]
}
self.env['pos.order']._match_transactions_to_payments(pos_order)
self.assertEquals(pos_order['statement_ids'][0][2]['note'], 'XPTO')
self.assertEquals(pos_order['statement_ids'][1][2]['note'], 'ABCDE')

16
pos_payment_terminal/views/account_journal.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_journal_form" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="point_of_sale.view_account_journal_pos_user_form"/>
<field name="arch" type="xml">
<group name="amount_authorized" position="after">
<group name="payment_mode_group" attrs="{'invisible': [('type', '!=', 'bank')]}">
<field name="pos_terminal_payment_mode"/>
</group>
</group>
</field>
</record>
</odoo>

13
pos_payment_terminal/views/assets.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_payment_terminal/static/src/js/screens.js"></script>
<script type="text/javascript" src="/pos_payment_terminal/static/src/js/models.js"></script>
<script type="text/javascript" src="/pos_payment_terminal/static/src/js/devices.js"></script>
<link rel="stylesheet" href="/pos_payment_terminal/static/src/css/pos_payment_terminal.css" />
</xpath>
</template>
</odoo>

18
pos_payment_terminal/views/pos_config.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='iface_cashdrawer']/.." position="after">
<div class="row">
<label string="Payment Terminal" for="iface_payment_terminal" class="col-lg-3 o_light_label"/>
<field name="iface_payment_terminal"/>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save