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.

111 lines
4.1 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.customer_display_2_20', function (require) {
  7. "use strict";
  8. var core = require('web.core');
  9. var _t = core._t;
  10. var CustomerDisplay_2_20 = function(proxy_device){
  11. this.pos = proxy_device.pos;
  12. this._prepare_line = proxy_device._prepare_line;
  13. this._prepare_message_welcome = function(){
  14. return new Array(
  15. this._prepare_line(this.pos.config.customer_display_msg_next_l1, ""),
  16. this._prepare_line(this.pos.config.customer_display_msg_next_l2, ""),
  17. );
  18. };
  19. this._prepare_message_close = function(){
  20. return new Array(
  21. this._prepare_line(this.pos.config.customer_display_msg_closed_l1, ""),
  22. this._prepare_line(this.pos.config.customer_display_msg_closed_l2, ""),
  23. );
  24. };
  25. this._prepare_message_orderline = function(order_line, action){
  26. var currency_rounding = this.pos.currency.decimals;
  27. var product_name = order_line.product.display_name;
  28. var unit_price_str = order_line.get_unit_price().toFixed(currency_rounding);
  29. var total_amount_str = order_line.get_display_price().toFixed(currency_rounding);
  30. var qty = order_line.get_quantity();
  31. // only display decimals when qty is not an integer
  32. if (qty.toFixed(0) == qty) {
  33. qty = qty.toFixed(0);
  34. }
  35. var discount = order_line.get_discount();
  36. var discount_str = "";
  37. if ([
  38. 'add_line',
  39. 'update_quantity',
  40. 'update_unit_price',
  41. 'update_discount',
  42. ].indexOf(action) !== -1){
  43. var second_line = String(qty) + " * " + unit_price_str;
  44. if (discount){
  45. discount_str = " -" + String(discount) + "%";
  46. }
  47. return new Array(
  48. this._prepare_line(product_name, discount_str),
  49. this._prepare_line(second_line, total_amount_str),
  50. );
  51. } else if (action === 'delete_line'){
  52. return new Array(
  53. this._prepare_line(_t("Deleting Line ..."), ""),
  54. this._prepare_line(order_line.product.display_name, ""),
  55. );
  56. }
  57. };
  58. this._prepare_message_payment = function(action){
  59. var currency_rounding = this.pos.currency.decimals;
  60. var order = this.pos.get_order()
  61. var total = order.get_total_with_tax().toFixed(currency_rounding);
  62. var total_paid = order.get_total_paid().toFixed(currency_rounding);
  63. var total_change = order.get_due().toFixed(currency_rounding);
  64. var total_to_pay = (total - total_paid).toFixed(currency_rounding);
  65. var remaining_operation_str = "";
  66. if (total_paid != 0) {
  67. if (total_to_pay > 0) {
  68. remaining_operation_str = _t("To Pay: ") + String(total_to_pay);
  69. } else if (total_change < 0) {
  70. remaining_operation_str = _t("Returned: ") + String(- total_change);
  71. }
  72. }
  73. return new Array(
  74. this._prepare_line(_t("Total"), String(total)),
  75. this._prepare_line(remaining_operation_str, ""),
  76. );
  77. };
  78. this._prepare_message_client = function(client){
  79. if ( client ) {
  80. return new Array(
  81. this._prepare_line(_t("Customer Account"), ""),
  82. this._prepare_line(client.name, ""),
  83. );
  84. } else {
  85. return new Array(
  86. this._prepare_line(_t("No Customer Account"), ""),
  87. this._prepare_line("", ""),
  88. );
  89. }
  90. };
  91. };
  92. return {
  93. CustomerDisplay_2_20: CustomerDisplay_2_20,
  94. };
  95. });