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.

128 lines
5.0 KiB

  1. /*
  2. Copyright (C) 2015-Today GRAP (http://www.grap.coop)
  3. @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. */
  6. odoo.define('pos_customer_display.models', function (require) {
  7. "use strict";
  8. var models = require('point_of_sale.models');
  9. var OrderSuper = models.Order;
  10. var OrderlineSuper = models.Orderline;
  11. var PosModelSuper = models.PosModel;
  12. // //////////////////////////////////
  13. // Overload models.PosModel
  14. // //////////////////////////////////
  15. models.PosModel = models.PosModel.extend({
  16. initialize: function(session, attributes) {
  17. var res = PosModelSuper.prototype.initialize.call(this, session, attributes);
  18. // send_message_customer_display is a variable that allow
  19. // to disable the send of the message to the customer display
  20. // This desing is due to the current design of Odoo PoS.
  21. // 1) during the call_of_init_from_JSON, a call to
  22. // add_product and remove_orderline is done.
  23. // 2) during the call of add_product, a call
  24. // to set_price, set_discount, set_quantity is done.
  25. // To avoid multiple useless messages sends.
  26. // it fixed this @via-alexis comment:
  27. // https://github.com/OCA/pos/blob/10.0/pos_customer_display/
  28. // static/src/js/customer_display.js#L198
  29. this.send_message_customer_display = true;
  30. return res;
  31. },
  32. after_load_server_data: function(){
  33. this.proxy.load_customer_display_format_file();
  34. return PosModelSuper.prototype.after_load_server_data.call(this);
  35. },
  36. });
  37. // //////////////////////////////////
  38. // Overload models.Order
  39. // //////////////////////////////////
  40. models.Order = models.Order.extend({
  41. init_from_JSON: function(json) {
  42. this.pos.send_message_customer_display = false;
  43. var res = OrderSuper.prototype.init_from_JSON.call(this, json);
  44. this.pos.send_message_customer_display = true;
  45. return res;
  46. },
  47. add_product: function(product, options){
  48. var send_message = this.pos.send_message_customer_display;
  49. this.pos.send_message_customer_display = false;
  50. var res = OrderSuper.prototype.add_product.call(this, product, options);
  51. if (send_message){
  52. this.pos.proxy.send_text_customer_display(
  53. this.pos.proxy.prepare_message_orderline(
  54. this.get_last_orderline(), 'add_line'));
  55. this.pos.send_message_customer_display = true;
  56. }
  57. return res;
  58. },
  59. });
  60. //////////////////////////////////
  61. // Overload models.Orderline
  62. //////////////////////////////////
  63. models.Orderline = models.Orderline.extend({
  64. set_quantity: function(quantity, keep_price){
  65. var send_message = this.pos.send_message_customer_display;
  66. var message;
  67. this.pos.send_message_customer_display = false;
  68. // In the current Odoo design, set_quantity is call to remove line
  69. // so we prepare the message before because after the call
  70. // of super, the line is delete.
  71. if (send_message){
  72. if (quantity === 'remove') {
  73. message = this.pos.proxy.prepare_message_orderline(this, 'delete_line');
  74. }
  75. }
  76. var res = OrderlineSuper.prototype.set_quantity.call(this, quantity, keep_price);
  77. if (send_message) {
  78. if (quantity !== 'remove'){
  79. message = this.pos.proxy.prepare_message_orderline(this, 'update_quantity');
  80. }
  81. this.pos.send_message_customer_display = true;
  82. this.pos.proxy.send_text_customer_display(message);
  83. }
  84. return res;
  85. },
  86. set_discount: function(discount){
  87. var send_message = this.pos.send_message_customer_display;
  88. this.pos.send_message_customer_display = false;
  89. var res = OrderlineSuper.prototype.set_discount.call(this, discount);
  90. if (send_message) {
  91. this.pos.send_message_customer_display = true;
  92. this.pos.proxy.send_text_customer_display(
  93. this.pos.proxy.prepare_message_orderline(this, 'update_discount'));
  94. }
  95. return res;
  96. },
  97. set_unit_price: function(price){
  98. var send_message = this.pos.send_message_customer_display;
  99. this.pos.send_message_customer_display = false;
  100. var res = OrderlineSuper.prototype.set_unit_price.call(this, price);
  101. if (send_message) {
  102. this.pos.send_message_customer_display = true;
  103. this.pos.proxy.send_text_customer_display(
  104. this.pos.proxy.prepare_message_orderline(this, 'update_unit_price'));
  105. }
  106. return res;
  107. },
  108. });
  109. });