From 62a8def91889bbe8f2207bb4c0067f2274ae93e6 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Fri, 22 Apr 2016 10:17:50 +0200 Subject: [PATCH] [IMP] point_of_sale: wrap long product names on ESC/POS receipt Lines have to be wrapped manually as nor the ESC/POS protocol, nor the hw_escpos module will do it for us. Before this long product names where truncated to 24 characters by hw_escpos. This wraps the product names using available spaces in the product name. A product name with > 24 continuous characters will still be truncated. --- addons/point_of_sale/static/src/js/models.js | 31 ++++++++++++++++++++ addons/point_of_sale/static/src/xml/pos.xml | 14 +++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index ad28c206732..595a2d7c25d 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1227,6 +1227,7 @@ exports.Orderline = Backbone.Model.extend({ price: this.get_unit_display_price(), discount: this.get_discount(), product_name: this.get_product().display_name, + product_name_wrapped: this.generate_wrapped_product_name(), price_display : this.get_display_price(), price_with_tax : this.get_price_with_tax(), price_without_tax: this.get_price_without_tax(), @@ -1235,6 +1236,36 @@ exports.Orderline = Backbone.Model.extend({ product_description_sale: this.get_product().description_sale, }; }, + generate_wrapped_product_name: function() { + var MAX_LENGTH = 24; // 40 * line ratio of .6 + var wrapped = []; + var name = this.get_product().display_name; + var current_line = ""; + + while (name.length > 0) { + var space_index = name.indexOf(" "); + + if (space_index === -1) { + space_index = name.length; + } + + if (current_line.length + space_index > MAX_LENGTH) { + if (current_line.length) { + wrapped.push(current_line); + } + current_line = ""; + } + + current_line += name.slice(0, space_index + 1); + name = name.slice(space_index + 1); + } + + if (current_line.length) { + wrapped.push(current_line); + } + + return wrapped; + }, // changes the base price of the product for this orderline set_unit_price: function(price){ this.order.assert_editable(); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 4e8743f4e7e..c93eee36eda 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -663,6 +663,14 @@ + + + + + + + + @@ -714,12 +722,14 @@ - + + - + + Discount: %