diff --git a/pos_payment_terminal/README.rst b/pos_payment_terminal/README.rst index 6c1c22da..b8139ea0 100644 --- a/pos_payment_terminal/README.rst +++ b/pos_payment_terminal/README.rst @@ -1,3 +1,8 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +==================== POS Payment Terminal ==================== @@ -20,10 +25,6 @@ This module is designed to be installed on the and old Sagem devices support the Telium protocol implemented in the *hw_telium_payment_terminal* module. -This module requires an up-to-date version of Odoo v8 that includes -`this pull request ` which was -merged in the *8.0* branch of Odoo on Github on July 2nd 2015. - Configuration ============= @@ -36,6 +37,18 @@ Usage 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. +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/184/10.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + Credits ======= @@ -48,12 +61,14 @@ Contributors Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. -OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/pos_payment_terminal/__init__.py b/pos_payment_terminal/__init__.py index 9e67b3d9..cde864ba 100644 --- a/pos_payment_terminal/__init__.py +++ b/pos_payment_terminal/__init__.py @@ -1 +1,3 @@ -from . import pos_payment_terminal +# -*- coding: utf-8 -*- + +from . import models diff --git a/pos_payment_terminal/__openerp__.py b/pos_payment_terminal/__openerp__.py index 6538c81d..ac6aad19 100644 --- a/pos_payment_terminal/__openerp__.py +++ b/pos_payment_terminal/__openerp__.py @@ -1,39 +1,24 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# POS Payment Terminal module for Odoo -# Copyright (C) 2014 Aurélien DUMAINE -# Copyright (C) 2015 Akretion (www.akretion.com) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# © 2014-2016 Aurélien DUMAINE +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'POS Payment Terminal', - 'version': '8.0.0.1.0', + 'version': '9.0.1.0.1', 'category': 'Point Of Sale', 'summary': 'Manage Payment Terminal device from POS front end', + 'website': 'https://github.com/OCA/pos', + 'development_status': 'Stable/Production', 'author': "Aurélien DUMAINE,Akretion,Odoo Community Association (OCA)", 'license': 'AGPL-3', 'depends': ['point_of_sale'], 'data': [ - 'pos_payment_terminal.xml', - 'pos_payment_terminal_view.xml', + 'views/pos_config.xml', + 'views/account_journal.xml', + 'views/pos_payment_terminal_template.xml', ], - 'demo': ['pos_payment_terminal_demo.xml'], + 'demo': ['demo/pos_payment_terminal_demo.xml'], 'qweb': ['static/src/xml/pos_payment_terminal.xml'], - 'installable': False, + 'installable': True, } diff --git a/pos_payment_terminal/pos_payment_terminal_demo.xml b/pos_payment_terminal/demo/pos_payment_terminal_demo.xml similarity index 50% rename from pos_payment_terminal/pos_payment_terminal_demo.xml rename to pos_payment_terminal/demo/pos_payment_terminal_demo.xml index 1788dae4..fb3dbd39 100644 --- a/pos_payment_terminal/pos_payment_terminal_demo.xml +++ b/pos_payment_terminal/demo/pos_payment_terminal_demo.xml @@ -1,14 +1,8 @@ - - - - - check - + - - + diff --git a/pos_payment_terminal/i18n/es.po b/pos_payment_terminal/i18n/es.po new file mode 100644 index 00000000..1f2a1ec7 --- /dev/null +++ b/pos_payment_terminal/i18n/es.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_terminal +# +# Translators: +# OCA Transbot , 2017 +# enjolras , 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 , 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,payment_mode:0 +msgid "Card" +msgstr "Tarjeta" + +#. module: pos_payment_terminal +#: selection:account.journal,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_payment_mode +msgid "Payment Mode" +msgstr "Forma de pago" + +#. 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 "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" diff --git a/pos_payment_terminal/i18n/fr.po b/pos_payment_terminal/i18n/fr.po index f247bbc6..1f814fc1 100644 --- a/pos_payment_terminal/i18n/fr.po +++ b/pos_payment_terminal/i18n/fr.po @@ -1,19 +1,23 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * pos_payment_terminal +# * pos_payment_terminal # +# Translators: +# OCA Transbot , 2017 +# leemannd , 2017 msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-04-30 10:04+0000\n" -"PO-Revision-Date: 2015-04-30 10:04+0000\n" -"Last-Translator: Alexis de Lattre \n" -"Language-Team: \n" +"POT-Creation-Date: 2018-03-01 02:01+0000\n" +"PO-Revision-Date: 2018-03-01 02:01+0000\n" +"Last-Translator: leemannd , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Plural-Forms: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: pos_payment_terminal #: selection:account.journal,payment_mode:0 @@ -31,19 +35,23 @@ msgid "Journal" msgstr "Journal" #. module: pos_payment_terminal -#: field:account.journal,payment_mode:0 -msgid "Payment mode" -msgstr "Mode de paiement" +#: model:ir.model.fields,field_description:pos_payment_terminal.field_account_journal_payment_mode +msgid "Payment Mode" +msgstr "Moyen de paiement" #. module: pos_payment_terminal -#: help:account.journal,payment_mode:0 +#: model:ir.model.fields,help:pos_payment_terminal.field_account_journal_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:8 +#: code:addons/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml:6 #, python-format msgid "Start transaction" msgstr "Démarrer la transaction" +#. module: pos_payment_terminal +#: model:ir.model,name:pos_payment_terminal.model_pos_config +msgid "pos.config" +msgstr "pos.config" diff --git a/pos_payment_terminal/i18n/hr_HR.po b/pos_payment_terminal/i18n/hr_HR.po new file mode 100644 index 00000000..aa8f3348 --- /dev/null +++ b/pos_payment_terminal/i18n/hr_HR.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_terminal +# +# Translators: +# Bole , 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 , 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,payment_mode:0 +msgid "Card" +msgstr "Kartica" + +#. module: pos_payment_terminal +#: selection:account.journal,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_payment_mode +msgid "Payment Mode" +msgstr "Način plaćanja" + +#. 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 "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" diff --git a/pos_payment_terminal/i18n/it.po b/pos_payment_terminal/i18n/it.po new file mode 100644 index 00000000..db1d4f75 --- /dev/null +++ b/pos_payment_terminal/i18n/it.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_terminal +# +# Translators: +# Francesco Fresta , 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 , 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,payment_mode:0 +msgid "Card" +msgstr "" + +#. module: pos_payment_terminal +#: selection:account.journal,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,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 "" + +#. module: pos_payment_terminal +#: model:ir.model,name:pos_payment_terminal.model_pos_config +msgid "pos.config" +msgstr "pos.config" diff --git a/pos_payment_terminal/i18n/nl_NL.po b/pos_payment_terminal/i18n/nl_NL.po new file mode 100644 index 00000000..9d417f99 --- /dev/null +++ b/pos_payment_terminal/i18n/nl_NL.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_terminal +# +# Translators: +# Peter Hageman , 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 , 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,payment_mode:0 +msgid "Card" +msgstr "" + +#. module: pos_payment_terminal +#: selection:account.journal,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,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 "" + +#. module: pos_payment_terminal +#: model:ir.model,name:pos_payment_terminal.model_pos_config +msgid "pos.config" +msgstr "pos.config" diff --git a/pos_payment_terminal/i18n/pos_payment_terminal.pot b/pos_payment_terminal/i18n/pos_payment_terminal.pot new file mode 100644 index 00000000..c5443309 --- /dev/null +++ b/pos_payment_terminal/i18n/pos_payment_terminal.pot @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_payment_terminal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \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 +#: selection:account.journal,payment_mode:0 +msgid "Card" +msgstr "" + +#. module: pos_payment_terminal +#: selection:account.journal,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,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 "" + +#. module: pos_payment_terminal +#: model:ir.model,name:pos_payment_terminal.model_pos_config +msgid "pos.config" +msgstr "" + diff --git a/pos_payment_terminal/models/__init__.py b/pos_payment_terminal/models/__init__.py new file mode 100644 index 00000000..819b3c20 --- /dev/null +++ b/pos_payment_terminal/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import pos_config +from . import account_journal +from . import pos_order diff --git a/pos_payment_terminal/models/account_journal.py b/pos_payment_terminal/models/account_journal.py new file mode 100644 index 00000000..66fb0e75 --- /dev/null +++ b/pos_payment_terminal/models/account_journal.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2014-2016 Aurélien DUMAINE +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from openerp import models, fields + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + payment_mode = fields.Selection( + [('card', 'Card'), ('check', 'Check')], 'Payment Mode', + help="Select the payment mode sent to the payment terminal") diff --git a/pos_payment_terminal/models/pos_config.py b/pos_payment_terminal/models/pos_config.py new file mode 100644 index 00000000..fe7d95c5 --- /dev/null +++ b/pos_payment_terminal/models/pos_config.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2014-2016 Aurélien DUMAINE +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from openerp 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") diff --git a/pos_payment_terminal/models/pos_order.py b/pos_payment_terminal/models/pos_order.py new file mode 100644 index 00000000..7313ff5e --- /dev/null +++ b/pos_payment_terminal/models/pos_order.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# © 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from collections import defaultdict +import logging + +from openerp import models, api + +_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]), + ('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]) + + @api.model + 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 diff --git a/pos_payment_terminal/pos_payment_terminal.py b/pos_payment_terminal/pos_payment_terminal.py deleted file mode 100644 index 1d2bd4ec..00000000 --- a/pos_payment_terminal/pos_payment_terminal.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# POS Payment Terminal module for Odoo -# Copyright (C) 2014 Aurélien DUMAINE -# Copyright (C) 2015 Akretion (www.akretion.com) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models, fields - - -class AccountJournal(models.Model): - _inherit = 'account.journal' - - payment_mode = fields.Selection( - (('card', 'Card'), ('check', 'Check')), 'Payment mode', - help="Select the payment mode sent to the payment terminal") - - -class PosConfig(models.Model): - _inherit = 'pos.config' - - iface_payment_terminal = fields.Boolean( - 'Payment Terminal', - help="A payment terminal is available on the Proxy") diff --git a/pos_payment_terminal/pos_payment_terminal.xml b/pos_payment_terminal/pos_payment_terminal.xml deleted file mode 100644 index 6f46ad01..00000000 --- a/pos_payment_terminal/pos_payment_terminal.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - diff --git a/pos_payment_terminal/pos_payment_terminal_view.xml b/pos_payment_terminal/pos_payment_terminal_view.xml deleted file mode 100644 index 8a72bd1a..00000000 --- a/pos_payment_terminal/pos_payment_terminal_view.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - pos.payment.terminal.config.form - pos.config - - - - - - - - - - pos.payment.terminal.journal.form - account.journal - - - - - - - - - - diff --git a/pos_payment_terminal/static/description/icon.png b/pos_payment_terminal/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/pos_payment_terminal/static/description/icon.png differ diff --git a/pos_payment_terminal/static/src/css/pos_payment_terminal.css b/pos_payment_terminal/static/src/css/pos_payment_terminal.css index bfec68ef..d3f4284c 100644 --- a/pos_payment_terminal/static/src/css/pos_payment_terminal.css +++ b/pos_payment_terminal/static/src/css/pos_payment_terminal.css @@ -1,4 +1,4 @@ -.pos .payment-terminal-transaction-start button { +.payment-terminal-transaction-start button { width: 150px; height: 60px; font-size: 18px; diff --git a/pos_payment_terminal/static/src/js/pos_payment_terminal.js b/pos_payment_terminal/static/src/js/pos_payment_terminal.js index 39ae910f..493f74f7 100755 --- a/pos_payment_terminal/static/src/js/pos_payment_terminal.js +++ b/pos_payment_terminal/static/src/js/pos_payment_terminal.js @@ -1,34 +1,119 @@ /* POS Payment Terminal module for Odoo - Copyright (C) 2014 Aurélien DUMAINE - Copyright (C) 2014-2015 Akretion (www.akretion.com) + Copyright (C) 2014-2016 Aurélien DUMAINE + Copyright (C) 2014-2016 Akretion (www.akretion.com) @author: Aurélien DUMAINE @author: Alexis de Lattre - The licence is in the file __openerp__.py + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -openerp.pos_payment_terminal = function(instance){ - module = instance.point_of_sale; +odoo.define('pos_payment_terminal.pos_payment_terminal', function (require) { + "use strict"; - module.ProxyDevice = module.ProxyDevice.extend({ - payment_terminal_transaction_start: function(line, currency_iso){ - var data = {'amount' : line.get_amount(), - 'currency_iso' : currency_iso, - 'payment_mode' : line.cashregister.journal.payment_mode}; + var screens = require('point_of_sale.screens'); + var devices = require('point_of_sale.devices'); + var models = require('point_of_sale.models'); + var core = require('web.core'); + var _t = core._t; + var QWeb = core.qweb; + + models.load_fields('account.journal', ['payment_mode']); + + 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(); + }); + }, + update_transaction_data: function(line, data){ + data.amount = line.get_amount(); + data.payment_mode = line.cashregister.journal.payment_mode; + }, + 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 = { + 'currency_iso' : currency_iso, + 'currency_decimals' : currency_decimals, + 'order_id': order.uid + } + this.update_transaction_data(line, data) this.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)}); }, }); - module.PaymentScreenWidget.include({ - render_paymentline: function(line){ - el_node = this._super(line); + + screens.PaymentScreenWidget.include({ + render_paymentlines : function(){ + this._super.apply(this, arguments); var self = this; - if (line.cashregister.journal.payment_mode && this.pos.config.iface_payment_terminal){ - el_node.querySelector('.payment-terminal-transaction-start') - .addEventListener('click', function(){self.pos.proxy.payment_terminal_transaction_start(line, self.pos.currency.name)}); - } - return el_node; + 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 ? + //console.log(event.target); + 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 self = this; + var order = this.pos.get_order(); + if (!order) { + return; + } else if (order.in_transaction) { + self.$('.next').html(''); + } else { + self.$('.next').html('Validate '); + } + } + }); + + var _orderproto = models.Order.prototype; + 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; + } }); -}; +}); diff --git a/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml b/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml index 48ff65a6..4e0d625c 100644 --- a/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml +++ b/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml @@ -1,11 +1,14 @@ - - - - - - + + + + + + + + + diff --git a/pos_payment_terminal/tests/__init__.py b/pos_payment_terminal/tests/__init__.py new file mode 100644 index 00000000..64ce8822 --- /dev/null +++ b/pos_payment_terminal/tests/__init__.py @@ -0,0 +1 @@ +from . import test_transactions diff --git a/pos_payment_terminal/tests/test_transactions.py b/pos_payment_terminal/tests/test_transactions.py new file mode 100644 index 00000000..a2241149 --- /dev/null +++ b/pos_payment_terminal/tests/test_transactions.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2018-TODAY ACSONE SA/NV (). +# 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', + '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') diff --git a/pos_payment_terminal/views/account_journal.xml b/pos_payment_terminal/views/account_journal.xml new file mode 100644 index 00000000..0e62aa9f --- /dev/null +++ b/pos_payment_terminal/views/account_journal.xml @@ -0,0 +1,15 @@ + + + + + pos.payment.terminal.journal.form + account.journal + + + + + + + + + diff --git a/pos_payment_terminal/views/pos_config.xml b/pos_payment_terminal/views/pos_config.xml new file mode 100644 index 00000000..6339b396 --- /dev/null +++ b/pos_payment_terminal/views/pos_config.xml @@ -0,0 +1,15 @@ + + + + + pos.payment.terminal.config.form + pos.config + + + + + + + + + diff --git a/pos_payment_terminal/views/pos_payment_terminal_template.xml b/pos_payment_terminal/views/pos_payment_terminal_template.xml new file mode 100644 index 00000000..0b619aff --- /dev/null +++ b/pos_payment_terminal/views/pos_payment_terminal_template.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/setup/pos_payment_terminal/odoo_addons/__init__.py b/setup/pos_payment_terminal/odoo_addons/__init__.py new file mode 100644 index 00000000..de40ea7c --- /dev/null +++ b/setup/pos_payment_terminal/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/pos_payment_terminal/odoo_addons/pos_payment_terminal b/setup/pos_payment_terminal/odoo_addons/pos_payment_terminal new file mode 120000 index 00000000..66a980f4 --- /dev/null +++ b/setup/pos_payment_terminal/odoo_addons/pos_payment_terminal @@ -0,0 +1 @@ +../../../pos_payment_terminal/ \ No newline at end of file diff --git a/setup/pos_payment_terminal/setup.py b/setup/pos_payment_terminal/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/pos_payment_terminal/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)