-
Notifications
You must be signed in to change notification settings - Fork 2
[9.0][IMP] pos_payment_terminal: better pywebdriver interface #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbidoul
wants to merge
9
commits into
9.0-add_pos_payment_terminal-dro
Choose a base branch
from
9.0-imp-pos_payment_terminal_enhanced-dro
base: 9.0-add_pos_payment_terminal-dro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
897c881
[9.0][IMP] pos_payment_terminal: Additional data to payment lines
rousseldenis a4f09df
[9.0][IMP] pos_payment_terminal: Update payment lines with response
rousseldenis f0790da
[9.0][IMP] pos_payment_terminal: Improvements to support line protect…
rousseldenis 145be15
[9.0][IMP] pos_payment_terminal: Protect Validate button
rousseldenis 0c32d13
[WIP] changes from review
rousseldenis b86459f
!fixup
rousseldenis ab7e8d4
!fixup
rousseldenis 67b7e4c
!fixup
rousseldenis 724dcac
!fixup
rousseldenis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| POS Payment Terminal module for Odoo | ||
| Copyright (C) 2014-2016 Aurélien DUMAINE | ||
| Copyright (C) 2014-2016 Akretion (www.akretion.com) | ||
| Copyright (C) 2019 ACSONE SA/NV | ||
| @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 models = require('point_of_sale.models'); | ||
| var devices = require('point_of_sale.devices'); | ||
| models.load_fields('account.journal', ['payment_mode']); | ||
|
|
||
| devices.ProxyDevice.include({ | ||
| init: function(parents, options) { | ||
| var self = this; | ||
| self._super(parents, options); | ||
| // We bind the status change | ||
| self.on('change:status', self, self.on_change_status); | ||
| }, | ||
| on_change_status: function(eh, status){ | ||
| var self = this; | ||
| if(!self.pos.chrome.screens) { | ||
| return; | ||
| } | ||
| var paymentwidget = self.pos.chrome.screens.payment; | ||
| var drivers = status.newValue.drivers; | ||
| var order = self.pos.get_order(); | ||
|
|
||
| // Check if the driver result is a terminal and then | ||
| // update payment lines with result | ||
| Object.keys(drivers).forEach(function(driver_name) { | ||
| if (drivers[driver_name].hasOwnProperty("is_terminal")) { | ||
| self.update_payment_line(drivers[driver_name]) | ||
| } | ||
| }); | ||
| if (paymentwidget){ | ||
| paymentwidget.order_changes(); | ||
| } | ||
| }, | ||
| update_payment_line: function(driver_status){ | ||
| var self = this; | ||
| var order = self.pos.get_order(); | ||
| var paymentwidget = self.pos.chrome.screens.payment; | ||
| if ('transactions' in driver_status){ | ||
| for (var transaction_id in driver_status.transactions){ | ||
| var transaction = driver_status.transactions[transaction_id]; | ||
| if ('transaction_id' in transaction){ | ||
| var transaction_id = transaction['transaction_id']; | ||
| var line = order.get_payment_line_by_transaction(transaction_id); | ||
| if (line === undefined){ | ||
| continue; | ||
| } | ||
| self.handle_terminal_response(line.cid, transaction) | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| handle_terminal_response: function(line_id, response){ | ||
| // This is intended to entrich payment line with | ||
| // useful values (status, transaction_id, ...) | ||
| // Note that transaction_id is mandatory to match response | ||
| if (response === undefined){ | ||
| return; | ||
| } | ||
| var self = this; | ||
| var order = self.pos.get_order() | ||
| var line = order.get_paymentline(line_id) | ||
| var paymentwidget = self.pos.chrome.screens.payment; | ||
|
|
||
| line.terminal_transaction_id = response.transaction_id; | ||
| line.terminal_transaction_success = response.success; | ||
| line.terminal_transaction_status = response.status; | ||
| line.terminal_transaction_reference = response.reference; | ||
|
|
||
| paymentwidget.transaction_changed(line); | ||
| }, | ||
|
|
||
| payment_terminal_transaction_start: function(line_cid){ | ||
| var self = this; | ||
| var order = this.pos.get_order(); | ||
| var line = order.get_paymentline(line_cid); | ||
| var data = line.prepare_transaction_data(); | ||
| self.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)}).then(function(result){ | ||
| self.handle_terminal_response(line.cid, result); | ||
| }); | ||
| }, | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| POS Payment Terminal module for Odoo | ||
| Copyright (C) 2014-2016 Aurélien DUMAINE | ||
| Copyright (C) 2014-2016 Akretion (www.akretion.com) | ||
| Copyright (C) 2019 ACSONE SA/NV | ||
| @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.Order = models.Order.extend({ | ||
| get_paymentline: function(id){ | ||
| var paymentlines = this.paymentlines.models; | ||
| for(var i = 0; i < paymentlines.length; i++){ | ||
| if(paymentlines[i].cid === id){ | ||
| return paymentlines[i]; | ||
| } | ||
| } | ||
| return null; | ||
| }, | ||
| get_payment_line_by_transaction: function(transaction_id){ | ||
| // This will retrieve the payment line by transaction reference | ||
| self = this; | ||
| var payment_lines = self.get_paymentlines(); | ||
| for (var id in payment_lines){ | ||
| var payment_line = payment_lines[id] | ||
| if (payment_line.terminal_transaction_id === undefined){ | ||
| continue; | ||
| } | ||
| if (transaction_id === payment_line.terminal_transaction_id){ | ||
| return payment_line; | ||
| } | ||
| } | ||
| return; | ||
| }, | ||
| show_validate_button: function(){ | ||
| var show = true; | ||
| var self = this; | ||
|
|
||
| if (self.pos.config.protect_automatic_payment){ | ||
| var payment_lines = self.get_paymentlines(); | ||
| for (var id in payment_lines){ | ||
| var payment_line = payment_lines[id] | ||
| var payment_mode = payment_line.cashregister.journal.payment_mode | ||
| if (payment_mode && (!payment_line.terminal_transaction_id || (payment_line.terminal_transaction_id && !payment_line.terminal_transaction_success))) { | ||
| show = false; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return show; | ||
| } | ||
| }); | ||
| var _paymentlineproto = models.Paymentline.prototype; | ||
| models.Paymentline = models.Paymentline.extend({ | ||
| initialize: function(attr, options){ | ||
| this.terminal_transaction_id = null; | ||
| this.terminal_transaction_success = null; | ||
| this.terminal_transaction_status = null; | ||
| this.terminal_transaction_reference = null; | ||
| _paymentlineproto.initialize.apply(this, arguments); | ||
| }, | ||
| init_from_JSON: function(json){ | ||
| _paymentlineproto.init_from_JSON.apply(this, arguments); | ||
| this.terminal_transaction_id = json.terminal_transaction_id; | ||
| this.terminal_transaction_success = json.terminal_transaction_success; | ||
| this.terminal_transaction_status = json.terminal_transaction_status; | ||
| this.terminal_transaction_reference = json.terminal_transaction_reference; | ||
| }, | ||
| export_as_JSON: function() { | ||
| var vals = _paymentlineproto.export_as_JSON.apply(this, arguments); | ||
| vals['terminal_transaction_id'] = this.terminal_transaction_id; | ||
| vals['terminal_transaction_success'] = this.terminal_transaction_success; | ||
| vals['terminal_transaction_status'] = this.terminal_transaction_status; | ||
| vals['terminal_transaction_reference'] = this.terminal_transaction_reference; | ||
| return vals; | ||
| }, | ||
| show_delete_button: function(){ | ||
| var show = true; | ||
| var self = this; | ||
| if (self.terminal_transaction_id){ | ||
| if(!self.terminal_transaction_success || self.terminal_transaction_success===true){ | ||
| show = false; | ||
| } | ||
| if(self.terminal_transaction_success === false){ | ||
| show = true; | ||
| } | ||
| } | ||
| return show; | ||
| }, | ||
| prepare_transaction_data: function(){ | ||
| var self = this; | ||
| var order = self.pos.get_order(); | ||
| var data = { | ||
| 'currency_iso' : self.pos.currency.name, | ||
| 'currency_decimals' : self.pos.currency.decimals, | ||
| 'order_id': order.uid, | ||
| 'amount': self.get_amount(), | ||
| 'payment_mode': self.cashregister.journal.payment_mode, | ||
| } | ||
| return data; | ||
| }, | ||
| is_payment_terminal_driven: function(){ | ||
| var self = this; | ||
| return self.cashregister.journal.payment_mode && self.pos.config.iface_payment_terminal; | ||
| }, | ||
| show_payment_spinner: function(){ | ||
| var show = false; | ||
| var self = this; | ||
|
|
||
| if (self.terminal_transaction_id){ | ||
| if(self.terminal_transaction_success === null){ | ||
| show = true; | ||
| } | ||
| } | ||
| return show; | ||
| }, | ||
| show_transaction_start: function(){ | ||
| var self = this; | ||
| var show = self.is_payment_terminal_driven(); | ||
| if (self.terminal_transaction_id){ | ||
| if(self.terminal_transaction_success === null || self.terminal_transaction_success === true){ | ||
| show = false; | ||
| } | ||
| } | ||
| return show; | ||
|
|
||
| }, | ||
| show_payment_status: function(){ | ||
| var show = false; | ||
| var self = this; | ||
|
|
||
| if(self.terminal_transaction_success !== undefined && self.terminal_transaction_status){ | ||
| show = true; | ||
| } | ||
| return show; | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.