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.

81 lines
2.7 KiB

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