From b62263b7950770884f131f5f32c5a5dd61adebf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Au=C3=A9lien=20DUMAINE?= Date: Thu, 10 Jul 2014 17:23:30 +0200 Subject: [PATCH] Initial check-in of the module pos_payment_terminal. --- pos_payment_terminal/__init__.py | 1 + pos_payment_terminal/__openerp__.py | 45 ++++++++++ pos_payment_terminal/pos_payment_terminal.py | 36 ++++++++ pos_payment_terminal/pos_payment_terminal.xml | 10 +++ .../pos_payment_terminal_view.xml | 25 ++++++ .../static/src/js/pos_payment_terminal.js | 86 +++++++++++++++++++ .../static/src/xml/pos_payment_terminal.xml | 16 ++++ 7 files changed, 219 insertions(+) create mode 100755 pos_payment_terminal/__init__.py create mode 100755 pos_payment_terminal/__openerp__.py create mode 100644 pos_payment_terminal/pos_payment_terminal.py create mode 100755 pos_payment_terminal/pos_payment_terminal.xml create mode 100644 pos_payment_terminal/pos_payment_terminal_view.xml create mode 100755 pos_payment_terminal/static/src/js/pos_payment_terminal.js create mode 100644 pos_payment_terminal/static/src/xml/pos_payment_terminal.xml diff --git a/pos_payment_terminal/__init__.py b/pos_payment_terminal/__init__.py new file mode 100755 index 00000000..45b85bcf --- /dev/null +++ b/pos_payment_terminal/__init__.py @@ -0,0 +1 @@ +import pos_payment_terminal diff --git a/pos_payment_terminal/__openerp__.py b/pos_payment_terminal/__openerp__.py new file mode 100755 index 00000000..67cb8a08 --- /dev/null +++ b/pos_payment_terminal/__openerp__.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + + +{ + 'name': 'POS Payment Terminal', + 'version': '0.1', + 'category': 'Point Of Sale', + 'summary': 'Manage Payment Terminal device from POS front end', + 'description': """ +POS Payment Terminal +==================== + +This module adds support for Payment Terminal in the Point of Sale. 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 devices support the Telium protocol implemented in the *hw_telium_payment_terminal* module. + +This module support two payment methods : cards and checks. The payment method should be configured on the main Odoo server, in the menu Point of Sale > Configuration > Payment Methods. + +This module has been developped during a POS code sprint at Akretion France from July 7th to July 10th 2014. This module is part of the POS project of the Odoo Community Association http://odoo-community.org/. You are invited to become a member and/or get involved in the Association ! + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Aurélien DUMAINE', + 'depends': ['point_of_sale'], + 'data' : ['pos_payment_terminal.xml', + 'pos_payment_terminal_view.xml'], + 'qweb': ['static/src/xml/pos_payment_terminal.xml'], +} diff --git a/pos_payment_terminal/pos_payment_terminal.py b/pos_payment_terminal/pos_payment_terminal.py new file mode 100644 index 00000000..3b4853ad --- /dev/null +++ b/pos_payment_terminal/pos_payment_terminal.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SP (). +# +# 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 account_journal(models.Model): + _name = 'account.journal' + _inherit = 'account.journal' + + payment_mode = fields.Selection((('card', 'Card'), ('check', 'Check')), 'Payment mode', help="Select the payment mode sent to the payment terminal") + +class pos_config(models.Model): + _name = 'pos.config' + _inherit = 'pos.config' + + iface_payment_terminal = fields.Boolean('Payment Terminal', help="A payment terminal is available on the Proxy") + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/pos_payment_terminal/pos_payment_terminal.xml b/pos_payment_terminal/pos_payment_terminal.xml new file mode 100755 index 00000000..32d81264 --- /dev/null +++ b/pos_payment_terminal/pos_payment_terminal.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/pos_payment_terminal/pos_payment_terminal_view.xml b/pos_payment_terminal/pos_payment_terminal_view.xml new file mode 100644 index 00000000..e55d2a34 --- /dev/null +++ b/pos_payment_terminal/pos_payment_terminal_view.xml @@ -0,0 +1,25 @@ + + + + + pos.config.form.view.inherit + pos.config + + + + + + + + + POS journal inherit + account.journal + + + + + + + + + diff --git a/pos_payment_terminal/static/src/js/pos_payment_terminal.js b/pos_payment_terminal/static/src/js/pos_payment_terminal.js new file mode 100755 index 00000000..6f7a866f --- /dev/null +++ b/pos_payment_terminal/static/src/js/pos_payment_terminal.js @@ -0,0 +1,86 @@ +openerp.pos_payment_terminal = function(instance){ + module = instance.point_of_sale; + + module.ProxyDevice = module.ProxyDevice.extend({ + payment_terminal_transaction_start: function(line, currency_iso, currency_iso_numeric){ + var data = {'amount' : line.get_amount(), + 'currency_iso' : currency_iso, + 'currency_iso_numeric' : currency_iso_numeric, + 'payment_mode' : line.cashregister.journal.payment_mode}; + alert(JSON.stringify(data)); + this.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)}); + }, + }); + + //TODO make the button bigger and with better name + + var _super_PaymentScreenWidget_init_ = module.PaymentScreenWidget.prototype.init; + module.PaymentScreenWidget.prototype.init = function(parent, options){ + _super_PaymentScreenWidget_init_.call(this, parent, options); + self = this; + this.payment_terminal_transaction_start = function(event){ + var node = this; + while(node && !node.classList.contains('paymentline')){ + node = node.parentNode; + } + if(node){ + if (self.pos.config.iface_payment_terminal) + self.pos.proxy.payment_terminal_transaction_start(node.line, self.pos.currency.name, self.pos.currency.iso_numeric); + } + event.stopPropagation(); + }; + }; + + var _super_renderPaymentline_ = module.PaymentScreenWidget.prototype.render_paymentline; + module.PaymentScreenWidget.prototype.render_paymentline = function(line){ + var el_node = _super_renderPaymentline_.call(this, line); + if (line.cashregister.journal.payment_mode && this.pos.config.iface_payment_terminal){ + if (!this.pos.currency.name){ + var self = this; + var currencies = new instance.web.Model('res.currency').query(['name', 'iso_numeric']) + .filter([['id','=',this.pos.currency.id]]) + .all().then(function (currency) { + self.pos.currency.name = currency[0].name; + self.pos.currency.iso_numeric = currency[0].iso_numeric; + }); + } + el_node.querySelector('.payment-terminal-transaction-start') + .addEventListener('click', this.payment_terminal_transaction_start); + //.addEventListener('click', this.pos.proxy.payment_terminal_transaction_start(line, this.pos.currency.name, this.pos.currency.iso_numeric)); + } + return el_node; + }; + +/* + var _super_load_server_data_ = module.PosModel.prototype.load_server_data; + module.PosModel.prototype.load_server_data = function(){ + var loaded = _super_load_server_data_.call(this); + //FIXME : this is asynchronous, I can't assume the pos.currency loaded when we enter is this + this.pos.currency.name = new instance.web.Model('res.currency').query('name').filter([['id','=',this.pos_currency.id]]).all()[0] + return loaded; + }; +*/ + +/* + var _super_setSmartStatus_ = module.ProxyStatusWidget.prototype.set_smart_status; + module.ProxyStatusWidget.prototype.set_smart_status = function(status){ + _super_setSmartStatus_.call(this, status); + if(status.status === 'connected'){ + var warning = false; + var msg = '' + if(this.pos.config.iface_customer_display){ + var customer_display = status.drivers.customer_display ? status.drivers.customer_display.status : false; + if( customer_display != 'connected' && customer_display != 'connecting'){ + warning = true; + msg = msg ? msg + ' & ' : msg; + msg += _t('Customer display'); + } + } + msg = msg ? msg + ' ' + _t('Offline') : msg; + this.set_status(warning ? 'warning' : 'connected', msg); + }else{ + this.set_status(status.status,''); + } + }; +*/ +}; diff --git a/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml b/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml new file mode 100644 index 00000000..8467a816 --- /dev/null +++ b/pos_payment_terminal/static/src/xml/pos_payment_terminal.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + +