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.

85 lines
2.8 KiB

  1. /*
  2. Copyright 2019 Coop IT Easy SCRLfs
  3. Robin Keunen <robin@coopiteasy.be>
  4. Vincent Van Rossem <vvrossem@gmail.com>
  5. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. */
  7. odoo.define('pos_toledo_product.devices', function (require) {
  8. "use strict";
  9. var devices = require('point_of_sale.devices');
  10. devices.ProxyDevice.include({
  11. reset_weight_product: function () {
  12. var ret = new $.Deferred();
  13. this.message('reset_weight').then(function (status) {
  14. ret.resolve(status)
  15. }, function () {
  16. ret.resolve({weight: 0.0, price: 0.0, unit: 'kg', info: 'ko'})
  17. });
  18. return ret;
  19. },
  20. reset_tare: function () {
  21. var price = '001000'; // bizerba doesn't accept '000000' as unit price
  22. var ret = new $.Deferred();
  23. this.message('scale_price', {price: price}).then(function (weight) {
  24. ret.resolve(weight);
  25. }, function () {
  26. ret.resolve({weight: 0.0, price: 0.0, unit: 'kg', info: 'ko'})
  27. });
  28. return ret;
  29. },
  30. scale_read_data_price_product: function (price) {
  31. var self = this;
  32. var ret = new $.Deferred();
  33. if (self.use_debug_weight) {
  34. return (new $.Deferred()).resolve({
  35. weight: this.debug_weight,
  36. price: this.debug_price,
  37. unit: 'kg',
  38. info: 'ok'
  39. });
  40. }
  41. this.message('scale_price', {price: price})
  42. .then(function (weight) {
  43. ret.resolve(weight);
  44. }, function () {
  45. ret.resolve({weight: 0.0, price: 0.0, unit: 'kg', info: 'ko'});
  46. });
  47. return ret;
  48. },
  49. scale_read_data_price_tare_product: function (price, tare) {
  50. var self = this;
  51. var ret = new $.Deferred();
  52. if (self.use_debug_weight) {
  53. return (new $.Deferred()).resolve({
  54. weight: this.debug_weight,
  55. price: this.debug_price,
  56. unit: 'kg',
  57. info: 'ok'
  58. });
  59. }
  60. this.message('scale_price_tare', {price: price, tare: tare})
  61. .then(function (weight) {
  62. ret.resolve(weight);
  63. }, function () {
  64. ret.resolve({weight: 0.0, price: 0.0, unit: 'kg', info: 'ko'});
  65. });
  66. return ret;
  67. },
  68. debug_set_weight: function (kg) {
  69. this._super(kg);
  70. this.debug_price = NaN;
  71. },
  72. debug_reset_weight: function () {
  73. this._super();
  74. this.debug_price = 0.0;
  75. },
  76. });
  77. });