You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.9 KiB

  1. /*
  2. POS Payment Terminal module for Odoo
  3. Copyright (C) 2014-2016 Aurélien DUMAINE
  4. Copyright (C) 2014-2016 Akretion (www.akretion.com)
  5. @author: Aurélien DUMAINE
  6. @author: Alexis de Lattre <alexis.delattre@akretion.com>
  7. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  8. */
  9. odoo.define('pos_payment_terminal.devices', function (require) {
  10. "use strict";
  11. var devices = require('point_of_sale.devices');
  12. devices.ProxyDevice.include({
  13. init: function(parents, options) {
  14. var self = this;
  15. self._super(parents, options);
  16. self.on('change:status', this, function(eh, status) {
  17. if(!self.pos.chrome.screens) {
  18. return;
  19. }
  20. var paymentwidget = self.pos.chrome.screens.payment;
  21. var drivers = status.newValue.drivers;
  22. var order = self.pos.get_order();
  23. var in_transaction = false;
  24. Object.keys(drivers).forEach(function(driver_name) {
  25. if (drivers[driver_name].hasOwnProperty("in_transaction")) {
  26. in_transaction = in_transaction || drivers[driver_name].in_transaction;
  27. }
  28. var transactions = drivers[driver_name].latest_transactions;
  29. if(!!transactions && transactions.hasOwnProperty(order.uid)) {
  30. var previous_transactions = order.transactions;
  31. order.transactions = transactions[order.uid];
  32. var has_new_transactions = (
  33. !previous_transactions ||
  34. previous_transactions.length < order.transactions.length
  35. );
  36. if(has_new_transactions && order.is_paid()) {
  37. paymentwidget.validate_order();
  38. }
  39. }
  40. });
  41. order.in_transaction = in_transaction;
  42. paymentwidget.order_changes();
  43. });
  44. },
  45. payment_terminal_transaction_start: function(line_cid, currency_iso, currency_decimals){
  46. var line;
  47. var order = this.pos.get_order();
  48. var lines = order.get_paymentlines();
  49. for ( var i = 0; i < lines.length; i++ ) {
  50. if (lines[i].cid === line_cid) {
  51. line = lines[i];
  52. }
  53. }
  54. var data = {'amount' : line.get_amount(),
  55. 'currency_iso' : currency_iso,
  56. 'currency_decimals' : currency_decimals,
  57. 'payment_mode' : line.cashregister.journal.pos_terminal_payment_mode,
  58. 'order_id': order.uid};
  59. this.message('payment_terminal_transaction_start', {'payment_info' : JSON.stringify(data)});
  60. },
  61. });
  62. });