From 3ebc6c7d80ade140a2f3dce82987cebc875d2f9d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 9 Jun 2015 00:26:50 +0200 Subject: [PATCH] pos_payment_terminal: smiplify JS code Move description from __openerp__.py to README.rst Update demo data --- pos_payment_terminal/README.rst | 55 +++++++++++++++++++ pos_payment_terminal/__openerp__.py | 24 +------- pos_payment_terminal/pos_payment_terminal.py | 5 +- .../pos_payment_terminal_demo.xml | 4 ++ .../static/src/js/pos_payment_terminal.js | 54 +++++++----------- 5 files changed, 84 insertions(+), 58 deletions(-) create mode 100644 pos_payment_terminal/README.rst diff --git a/pos_payment_terminal/README.rst b/pos_payment_terminal/README.rst new file mode 100644 index 00000000..7dc931f6 --- /dev/null +++ b/pos_payment_terminal/README.rst @@ -0,0 +1,55 @@ +POS Payment Terminal +==================== + +This module adds support for credit card reader and checks printer +in the Point of Sale. + +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 ! + +Installation +============ + +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 ` +and old Sagem devices support the Telium protocol implemented in the +*hw_telium_payment_terminal* module. + +Configuration +============= + +This module support two payment modes : *card* and *check*. The payment +mode should be configured on the main Odoo server, in the menu *Point +of Sale > Configuration > Payment Methods*, under the *Point of Sale* tab. + +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. + +Credits +======= + +Contributors +------------ + +* Aurelien Dumaine +* Alexis de Lattre + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/pos_payment_terminal/__openerp__.py b/pos_payment_terminal/__openerp__.py index cc29b533..79327d62 100644 --- a/pos_payment_terminal/__openerp__.py +++ b/pos_payment_terminal/__openerp__.py @@ -3,6 +3,7 @@ # # 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 @@ -25,28 +26,7 @@ '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 credit card reader and checks printer -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 -and Sagem 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 ! - """, - 'author': "Aurélien DUMAINE,Odoo Community Association (OCA)", + 'author': "Aurélien DUMAINE,Akretion,Odoo Community Association (OCA)", 'license': 'AGPL-3', 'depends': ['point_of_sale'], 'data': [ diff --git a/pos_payment_terminal/pos_payment_terminal.py b/pos_payment_terminal/pos_payment_terminal.py index a54252ad..1d2bd4ec 100644 --- a/pos_payment_terminal/pos_payment_terminal.py +++ b/pos_payment_terminal/pos_payment_terminal.py @@ -3,6 +3,7 @@ # # 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 @@ -22,7 +23,7 @@ from openerp import models, fields -class account_journal(models.Model): +class AccountJournal(models.Model): _inherit = 'account.journal' payment_mode = fields.Selection( @@ -30,7 +31,7 @@ class account_journal(models.Model): help="Select the payment mode sent to the payment terminal") -class pos_config(models.Model): +class PosConfig(models.Model): _inherit = 'pos.config' iface_payment_terminal = fields.Boolean( diff --git a/pos_payment_terminal/pos_payment_terminal_demo.xml b/pos_payment_terminal/pos_payment_terminal_demo.xml index e51595b8..1788dae4 100644 --- a/pos_payment_terminal/pos_payment_terminal_demo.xml +++ b/pos_payment_terminal/pos_payment_terminal_demo.xml @@ -6,5 +6,9 @@ check + + + + 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 250e3d99..39ae910f 100755 --- a/pos_payment_terminal/static/src/js/pos_payment_terminal.js +++ b/pos_payment_terminal/static/src/js/pos_payment_terminal.js @@ -1,3 +1,12 @@ +/* + POS Payment Terminal module for Odoo + Copyright (C) 2014 Aurélien DUMAINE + Copyright (C) 2014-2015 Akretion (www.akretion.com) + @author: Aurélien DUMAINE + @author: Alexis de Lattre + The licence is in the file __openerp__.py +*/ + openerp.pos_payment_terminal = function(instance){ module = instance.point_of_sale; @@ -6,43 +15,20 @@ openerp.pos_payment_terminal = function(instance){ var data = {'amount' : line.get_amount(), 'currency_iso' : currency_iso, 'payment_mode' : line.cashregister.journal.payment_mode}; -// alert(JSON.stringify(data)); this.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)}); }, }); - var _super_PaymentScreenWidget_init_ = module.PaymentScreenWidget.prototype.init; - module.PaymentScreenWidget.prototype.init = function(parent, options){ - _super_PaymentScreenWidget_init_.call(this, parent, options); - var self = this; - this.payment_terminal_transaction_start = function(event){ - var node = this; - while (node && !node.classList.contains('paymentline')){ - node = node.parentNode; - } - if (node && !_.isEmpty(node.line) && self.pos.config.iface_payment_terminal){ - self.pos.proxy.payment_terminal_transaction_start(node.line, self.pos.currency.name); - } - 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']) - .filter([['id','=',this.pos.currency.id]]) - .all().then(function (currency) { - self.pos.currency.name = currency[0].name; - }); - } - el_node.querySelector('.payment-terminal-transaction-start') - .addEventListener('click', this.payment_terminal_transaction_start); - } - return el_node; - }; + module.PaymentScreenWidget.include({ + render_paymentline: function(line){ + el_node = this._super(line); + 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; + }, + }); };