diff --git a/account_payment_terminal/README.rst b/account_payment_terminal/README.rst new file mode 100644 index 00000000000..67c15d5962e --- /dev/null +++ b/account_payment_terminal/README.rst @@ -0,0 +1,108 @@ +======================== +Account Payment Terminal +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/14.0/account_payment_terminal + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-14-0/account-payment-14-0-account_payment_terminal + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/96/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon allows to pay invoices using a payment terminal. It communicates with the payment terminal proxy using the same protocol as OCA `pos_payment_terminal`. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure a bank journal as allowed to use payment terminals: + +#. Go to the menu Invoicing > Configuration > Journals. +#. Select or create a new bank journal. +#. Set the field 'Use a Payment Terminal' to your terminal type. + +Now you should create the payment terminals: + +#. Go to the menu Invoicing > Configuration > Payment terminals. +#. Create a new terminal by setting: + #. The hostname or ip address of the hardware proxy. + #. The identifier of the terminal as known by the hardware proxy (Leave empty if the proxy has only one terminal connected). + +Usage +===== + +#. Go to Invoicing > Customers > Invoices and select an open invoice. +#. Register a payment. +#. Select the bank journal configured to use payment terminals. +#. Select a terminal. +#. Confirm. + +You can test the flow using the mock terminal of `pywebdriver project `_ (an alternative to the POSbox/IoTbox). + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui + +Current `maintainer `__: + +|maintainer-sbejaoui| + +This module is part of the `OCA/account-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_terminal/__init__.py b/account_payment_terminal/__init__.py new file mode 100644 index 00000000000..aee8895e7a3 --- /dev/null +++ b/account_payment_terminal/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/account_payment_terminal/__manifest__.py b/account_payment_terminal/__manifest__.py new file mode 100644 index 00000000000..aefff410bd2 --- /dev/null +++ b/account_payment_terminal/__manifest__.py @@ -0,0 +1,28 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Payment Terminal", + "summary": """This addon allows to pay invoices using payment terminal""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "maintainers": ["sbejaoui"], + "website": "https://github.com/OCA/account-payment", + "depends": ["account"], + "data": [ + "security/account_payment_terminal.xml", + "views/account_payment_terminal_views.xml", + "views/account_journal_views.xml", + "views/oca_payment_terminal_form_mixin.xml", + "wizards/account_payment_register.xml", + ], + "assets": { + "web.assets_backend": [ + "account_payment_terminal/static/src/js/views/" + "payment_terminal_form/payment_terminal_form_controller.js", + "account_payment_terminal/static/src/js/views/" + "payment_terminal_form/payment_terminal_form_view.js", + ], + }, +} diff --git a/account_payment_terminal/i18n/account_payment_terminal.pot b/account_payment_terminal/i18n/account_payment_terminal.pot new file mode 100644 index 00000000000..11916e1b66f --- /dev/null +++ b/account_payment_terminal/i18n/account_payment_terminal.pot @@ -0,0 +1,210 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_terminal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: account_payment_terminal +#: model:ir.model,name:account_payment_terminal.model_account_payment_terminal +msgid "Account Payment Terminal" +msgstr "" + +#. module: account_payment_terminal +#: model_terms:ir.ui.view,arch_db:account_payment_terminal.account_payment_register_form_view +msgid "Create Payment" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__create_uid +msgid "Created by" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__create_date +msgid "Created on" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_journal__display_name +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_register__display_name +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__display_name +#: model:ir.model.fields,field_description:account_payment_terminal.field_oca_payment_terminal_form_mixin__display_name +msgid "Display Name" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "Error querying terminal driver status" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "Error starting payment transaction" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "" +"Failed to send the amount to pay to the payment terminal. Press the red " +"button on the payment terminal and try again." +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_journal__id +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_register__id +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__id +#: model:ir.model.fields,field_description:account_payment_terminal.field_oca_payment_terminal_form_mixin__id +msgid "ID" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__proxy_ip +msgid "IP Address" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model,name:account_payment_terminal.model_account_journal +msgid "Journal" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_journal____last_update +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_register____last_update +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal____last_update +#: model:ir.model.fields,field_description:account_payment_terminal.field_oca_payment_terminal_form_mixin____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__name +msgid "Name" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_register__need_payment_terminal +msgid "Need Payment Terminal" +msgstr "" + +#. module: account_payment_terminal +#: code:addons/account_payment_terminal/models/account_journal.py:0 +#, python-format +msgid "OCA Payment Terminal" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model,name:account_payment_terminal.model_oca_payment_terminal_form_mixin +msgid "OCA Payment Terminal Form Mixin" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "Payment Successful" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "Payment Successful but couldn't confirm it in odoo" +msgstr "" + +#. module: account_payment_terminal +#: code:addons/account_payment_terminal/models/oca_payment_terminal_form_mixin.py:0 +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_register__account_payment_terminal_id +#: model:ir.model.fields,field_description:account_payment_terminal.field_oca_payment_terminal_form_mixin__account_payment_terminal_id +#, python-format +msgid "Payment Terminal" +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_view.js:0 +#, python-format +msgid "Payment Terminal Form" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.actions.act_window,name:account_payment_terminal.account_payment_terminal_act_window +#: model:ir.ui.menu,name:account_payment_terminal.account_payment_terminal_menu +msgid "Payment Terminals" +msgstr "" + +#. module: account_payment_terminal +#: code:addons/account_payment_terminal/models/oca_payment_terminal_form_mixin.py:0 +#, python-format +msgid "" +"Payment terminal is not correctly configured. Please contact your " +"administrator." +msgstr "" + +#. module: account_payment_terminal +#: model_terms:ir.ui.view,arch_db:account_payment_terminal.account_payment_register_payment_terminal_form_view +#: model_terms:ir.ui.view,arch_db:account_payment_terminal.oca_payment_terminal_form_mixin_form_view +msgid "Please check the payment terminal" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,help:account_payment_terminal.field_account_journal__use_payment_terminal +msgid "Record payments with a terminal on this journal." +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model,name:account_payment_terminal.model_account_payment_register +msgid "Register Payment" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_payment_terminal__oca_payment_terminal_id +msgid "Terminal identifier" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,help:account_payment_terminal.field_account_payment_terminal__proxy_ip +msgid "The hostname or ip address of the hardware proxy" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,help:account_payment_terminal.field_account_payment_terminal__oca_payment_terminal_id +msgid "" +"The identifier of the terminal as known by the hardware proxy. Leave empty " +"if the proxy has only one terminal connected." +msgstr "" + +#. module: account_payment_terminal +#. openerp-web +#: code:addons/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js:0 +#, python-format +msgid "Transaction cancelled" +msgstr "" + +#. module: account_payment_terminal +#: model:ir.model.fields,field_description:account_payment_terminal.field_account_journal__use_payment_terminal +msgid "Use a Payment Terminal" +msgstr "" diff --git a/account_payment_terminal/models/__init__.py b/account_payment_terminal/models/__init__.py new file mode 100644 index 00000000000..171db14cd9c --- /dev/null +++ b/account_payment_terminal/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_journal +from . import account_payment_terminal +from . import oca_payment_terminal_form_mixin diff --git a/account_payment_terminal/models/account_journal.py b/account_payment_terminal/models/account_journal.py new file mode 100644 index 00000000000..a85a008bd28 --- /dev/null +++ b/account_payment_terminal/models/account_journal.py @@ -0,0 +1,18 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class AccountJournal(models.Model): + + _inherit = "account.journal" + + use_payment_terminal = fields.Selection( + selection=lambda self: self._get_payment_terminal_selection(), + string="Use a Payment Terminal", + help="Record payments with a terminal on this journal.", + ) + + def _get_payment_terminal_selection(self): + return [("oca_payment_terminal", _("OCA Payment Terminal"))] diff --git a/account_payment_terminal/models/account_payment_terminal.py b/account_payment_terminal/models/account_payment_terminal.py new file mode 100644 index 00000000000..f61589d3303 --- /dev/null +++ b/account_payment_terminal/models/account_payment_terminal.py @@ -0,0 +1,25 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountPaymentTerminal(models.Model): + + _name = "account.payment.terminal" + _description = "Account Payment Terminal" + + name = fields.Char(required=True) + proxy_ip = fields.Char( + string="IP Address", + size=45, + help="The hostname or ip address of the hardware proxy", + required=True, + ) + oca_payment_terminal_id = fields.Char( + string="Terminal identifier", + help=( + "The identifier of the terminal as known by the hardware proxy. " + "Leave empty if the proxy has only one terminal connected." + ), + ) diff --git a/account_payment_terminal/models/oca_payment_terminal_form_mixin.py b/account_payment_terminal/models/oca_payment_terminal_form_mixin.py new file mode 100644 index 00000000000..59174847a41 --- /dev/null +++ b/account_payment_terminal/models/oca_payment_terminal_form_mixin.py @@ -0,0 +1,68 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class OcaPaymentTerminalFormMixin(models.AbstractModel): + + _name = "oca.payment.terminal.form.mixin" + _description = "OCA Payment Terminal Form Mixin" + + account_payment_terminal_id = fields.Many2one( + comodel_name="account.payment.terminal", string="Payment Terminal" + ) + + def action_payment_terminal_transaction_start(self): + self.ensure_one() + if not hasattr(self, "journal_id"): + # the object must be linked to journal in order to get the payment + # terminal type + return {} + if ( + self.journal_id.use_payment_terminal + and self.account_payment_terminal_id + and hasattr( + self, self._get_payment_terminal_transaction_start_method_name() + ) + ): + return getattr( + self, self._get_payment_terminal_transaction_start_method_name() + )() + raise UserError( + _( + "Payment terminal is not correctly configured. " + "Please contact your administrator." + ) + ) + + def _get_payment_terminal_transaction_start_method_name(self): + return "_%s_transaction_start" % self.journal_id.use_payment_terminal or "" + + def _oca_payment_terminal_transaction_start(self): + self.ensure_one() + view_id = self._get_payment_terminal_form_view_id() + return { + "name": _("Payment Terminal"), + "type": "ir.actions.act_window", + "view_mode": "oca_payment_terminal_form", + "res_model": self._name, + "res_id": self.id, + "target": "new", + "view_id": view_id, + "context": self.env.context, + } + + @api.model + def _get_payment_terminal_form_view_id(self): + return self.env.ref( + "account_payment_terminal.oca_payment_terminal_form_mixin_form_view" + ).id + + # To define in the heir model + def get_payment_info(self): + raise NotImplementedError() + + def action_confirm_payment(self, payment_reference): + raise NotImplementedError() diff --git a/account_payment_terminal/readme/CONFIGURE.rst b/account_payment_terminal/readme/CONFIGURE.rst new file mode 100644 index 00000000000..a486700f63e --- /dev/null +++ b/account_payment_terminal/readme/CONFIGURE.rst @@ -0,0 +1,12 @@ +To configure a bank journal as allowed to use payment terminals: + +#. Go to the menu Invoicing > Configuration > Journals. +#. Select or create a new bank journal. +#. Set the field 'Use a Payment Terminal' to your terminal type. + +Now you should create the payment terminals: + +#. Go to the menu Invoicing > Configuration > Payment terminals. +#. Create a new terminal by setting: + #. The hostname or ip address of the hardware proxy. + #. The identifier of the terminal as known by the hardware proxy (Leave empty if the proxy has only one terminal connected). diff --git a/account_payment_terminal/readme/CONTRIBUTORS.rst b/account_payment_terminal/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..50e6298db56 --- /dev/null +++ b/account_payment_terminal/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/account_payment_terminal/readme/DESCRIPTION.rst b/account_payment_terminal/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..fcb0a5631ae --- /dev/null +++ b/account_payment_terminal/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This addon allows to pay invoices using a payment terminal. It communicates with the payment terminal proxy using the same protocol as OCA `pos_payment_terminal`. diff --git a/account_payment_terminal/readme/USAGE.rst b/account_payment_terminal/readme/USAGE.rst new file mode 100644 index 00000000000..54346b487de --- /dev/null +++ b/account_payment_terminal/readme/USAGE.rst @@ -0,0 +1,7 @@ +#. Go to Invoicing > Customers > Invoices and select an open invoice. +#. Register a payment. +#. Select the bank journal configured to use payment terminals. +#. Select a terminal. +#. Confirm. + +You can test the flow using the mock terminal of `pywebdriver project `_ (an alternative to the POSbox/IoTbox). diff --git a/account_payment_terminal/security/account_payment_terminal.xml b/account_payment_terminal/security/account_payment_terminal.xml new file mode 100644 index 00000000000..efa33bfe969 --- /dev/null +++ b/account_payment_terminal/security/account_payment_terminal.xml @@ -0,0 +1,23 @@ + + + + + account.payment.terminal access user + + + + + + + + + account.payment.terminal access manager + + + + + + + + diff --git a/account_payment_terminal/static/description/icon.png b/account_payment_terminal/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_payment_terminal/static/description/icon.png differ diff --git a/account_payment_terminal/static/description/index.html b/account_payment_terminal/static/description/index.html new file mode 100644 index 00000000000..0266249a343 --- /dev/null +++ b/account_payment_terminal/static/description/index.html @@ -0,0 +1,456 @@ + + + + + + +Account Payment Terminal + + + +
+

Account Payment Terminal

+ + +

Beta License: AGPL-3 OCA/account-payment Translate me on Weblate Try me on Runbot

+

This addon allows to pay invoices using a payment terminal. It communicates with the payment terminal proxy using the same protocol as OCA pos_payment_terminal.

+

Table of contents

+ +
+

Configuration

+

To configure a bank journal as allowed to use payment terminals:

+
    +
  1. Go to the menu Invoicing > Configuration > Journals.
  2. +
  3. Select or create a new bank journal.
  4. +
  5. Set the field ‘Use a Payment Terminal’ to your terminal type.
  6. +
+

Now you should create the payment terminals:

+
    +
  1. Go to the menu Invoicing > Configuration > Payment terminals.
  2. +
  3. +
    Create a new terminal by setting:
    +
      +
    1. The hostname or ip address of the hardware proxy.
    2. +
    3. The identifier of the terminal as known by the hardware proxy (Leave empty if the proxy has only one terminal connected).
    4. +
    +
    +
    +
  4. +
+
+
+

Usage

+
    +
  1. Go to Invoicing > Customers > Invoices and select an open invoice.
  2. +
  3. Register a payment.
  4. +
  5. Select the bank journal configured to use payment terminals.
  6. +
  7. Select a terminal.
  8. +
  9. Confirm.
  10. +
+

You can test the flow using the mock terminal of pywebdriver project (an alternative to the POSbox/IoTbox).

+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

sbejaoui

+

This module is part of the OCA/account-payment project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js b/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js new file mode 100644 index 00000000000..a3ea3ee6f3a --- /dev/null +++ b/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_controller.js @@ -0,0 +1,172 @@ +odoo.define( + "account_payment_terminal.OCAPaymentTerminalFormController", + function (require) { + "use strict"; + + var rpc = require("web.rpc"); + var FormController = require("web.FormController"); + var core = require("web.core"); + + var _lt = core._lt; + + var OCAPaymentTerminalFormController = FormController.extend({ + init: function () { + this.transaction_id = null; + this.oca_payment_terminal_id = null; + this.proxy_url = null; + this._super.apply(this, arguments); + }, + _show_error: function (error_message) { + this.$el.find("p").css("color", "red").text(error_message); + console.error(error_message); + }, + _show_success: function (success_message) { + this.$el.find("p").css("color", "green").text(success_message); + }, + _proxy_call: function (service, data, timeout) { + return $.ajax({ + url: this.proxy_url + "/hw_proxy/" + service, + dataType: "json", + contentType: "application/json;charset=utf-8", + data: JSON.stringify(data), + method: "POST", + timeout: timeout, + }); + }, + _get_payment_info: function () { + return rpc.query({ + model: this.model.loadParams.modelName, + method: "get_payment_info", + args: [[this.model.loadParams.res_id]], + }); + }, + _confirm_payment: function (transaction) { + return rpc.query({ + model: this.model.loadParams.modelName, + method: "action_confirm_payment", + args: [[this.model.loadParams.res_id], transaction.reference], + }); + }, + _get_payment_terminal_transaction_start_data: function (payment_info) { + this.proxy_url = payment_info.proxy_ip; + var cid = Math.floor(Math.random() * 1000 * 1000 * 1000); + var params = { + payment_info: JSON.stringify(payment_info), + }; + return { + jsonrpc: "2.0", + method: "call", + params: params, + id: cid, + }; + }, + _set_transaction_status: function (transaction, timerId) { + var self = this; + if (transaction.success) { + clearInterval(timerId); + self._confirm_payment(transaction) + .then(function () { + self._show_success(_lt("Payment Successful")); + }) + .catch(() => { + self._show_error( + _lt( + "Payment Successful but couldn't confirm it in odoo" + ) + ); + }); + } else if (transaction.success === false) { + clearInterval(timerId); + self._show_error(_lt("Transaction cancelled")); + } + }, + _poll_for_transaction_status: function () { + var self = this; + var timerId = setInterval(() => { + var status_params = {}; + if (self.oca_payment_terminal_id) { + status_params.terminal_id = self.oca_payment_terminal_id; + } + this._proxy_call("status_json", {params: status_params}, 1000) + .done((drivers_status) => { + if ("result" in drivers_status) { + var d_status = drivers_status.result; + for (var driver_name in d_status) { + var driver = d_status[driver_name]; + if ( + !driver.is_terminal || + !("transactions" in driver) + ) { + continue; + } + for (var transaction_id in driver.transactions) { + var transaction = + driver.transactions[transaction_id]; + if ( + transaction.transaction_id === + self.transaction_id + ) { + self._set_transaction_status( + transaction, + timerId + ); + } + } + } + } + }) + .fail(() => { + self._show_error( + _lt("Error querying terminal driver status") + ); + clearInterval(timerId); + }); + }, 1000); + }, + start: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + return self._get_payment_info().then(function (payment_info) { + self.oca_payment_terminal_id = + payment_info.oca_payment_terminal_id; + var data = + self._get_payment_terminal_transaction_start_data( + payment_info + ); + self._proxy_call( + "payment_terminal_transaction_start", + data, + 10000 + ) + .done(function (response) { + if (response === false) { + self._show_error( + _lt( + "Failed to send the amount to pay to the payment terminal. Press the red button on the payment terminal and try again." + ) + ); + return false; + } else if ( + response instanceof Object && + "result" in response && + "transaction_id" in response.result + ) { + self.transaction_id = + response.result.transaction_id; + self._poll_for_transaction_status(); + } + }) + .fail(function () { + self._show_error( + _lt("Error starting payment transaction") + ); + return false; + }); + }); + }); + }, + }); + + return OCAPaymentTerminalFormController; + } +); diff --git a/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_view.js b/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_view.js new file mode 100644 index 00000000000..31c74f4643b --- /dev/null +++ b/account_payment_terminal/static/src/js/views/payment_terminal_form/payment_terminal_form_view.js @@ -0,0 +1,31 @@ +odoo.define("account_payment_terminal.OCAPaymentTerminalFormView", function (require) { + "use strict"; + + var core = require("web.core"); + var BasicView = require("web.BasicView"); + var FormView = require("web.FormView"); + var viewRegistry = require("web.view_registry"); + var FormRenderer = require("web.FormRenderer"); + var OCAPaymentTerminalFormController = require("account_payment_terminal.OCAPaymentTerminalFormController"); + + var _lt = core._lt; + + var OCAPaymentTerminalFormView = FormView.extend({ + config: _.extend({}, BasicView.prototype.config, { + Renderer: FormRenderer, + Controller: OCAPaymentTerminalFormController, + }), + display_name: _lt("Payment Terminal Form"), + icon: "fa-edit", + multi_record: false, + withSearchBar: false, + searchMenuTypes: [], + viewType: "oca_payment_terminal_form", + init: function () { + this._super.apply(this, arguments); + }, + }); + + viewRegistry.add("oca_payment_terminal_form", OCAPaymentTerminalFormView); + return OCAPaymentTerminalFormView; +}); diff --git a/account_payment_terminal/views/account_journal_views.xml b/account_payment_terminal/views/account_journal_views.xml new file mode 100644 index 00000000000..83f76d175c5 --- /dev/null +++ b/account_payment_terminal/views/account_journal_views.xml @@ -0,0 +1,14 @@ + + + + + account.journal + + + + + + + + diff --git a/account_payment_terminal/views/account_payment_terminal_views.xml b/account_payment_terminal/views/account_payment_terminal_views.xml new file mode 100644 index 00000000000..a8301a94503 --- /dev/null +++ b/account_payment_terminal/views/account_payment_terminal_views.xml @@ -0,0 +1,42 @@ + + + + + account.payment.terminal + +
+ + + + + + + +
+
+
+ + account.payment.terminal + + + + + + + + + + Payment Terminals + account.payment.terminal + tree,form + [] + {} + + + Payment Terminals + + + + +
diff --git a/account_payment_terminal/views/oca_payment_terminal_form_mixin.xml b/account_payment_terminal/views/oca_payment_terminal_form_mixin.xml new file mode 100644 index 00000000000..508a901b961 --- /dev/null +++ b/account_payment_terminal/views/oca_payment_terminal_form_mixin.xml @@ -0,0 +1,17 @@ + + + + + oca.payment.terminal.form.mixin + 9999 + +
+ +

Please check the payment terminal

+
+