[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.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -663,6 +663,14 @@
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="XmlReceiptWrappedProductNameLines">
|
||||
<t t-foreach="line.product_name_wrapped.slice(1)" t-as="wrapped_line">
|
||||
<line>
|
||||
<left><t t-esc="wrapped_line"/></left>
|
||||
</line>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<t t-name="XmlReceipt">
|
||||
<receipt align='center' width='40' value-thousands-separator='' >
|
||||
<t t-if='receipt.company.logo'>
|
||||
@@ -714,12 +722,14 @@
|
||||
<t t-set='simple' t-value='line.discount === 0 and line.unit_name === "Unit(s)" and line.quantity === 1' />
|
||||
<t t-if='simple'>
|
||||
<line>
|
||||
<left><t t-esc='line.product_name' /></left>
|
||||
<left><t t-esc='line.product_name_wrapped[0]' /></left>
|
||||
<right><value><t t-esc='line.price_display' /></value></right>
|
||||
</line>
|
||||
<t t-call="XmlReceiptWrappedProductNameLines"/>
|
||||
</t>
|
||||
<t t-if='!simple'>
|
||||
<line><left><t t-esc='line.product_name' /></left></line>
|
||||
<line><left><t t-esc='line.product_name_wrapped[0]' /></left></line>
|
||||
<t t-call="XmlReceiptWrappedProductNameLines"/>
|
||||
<t t-if='line.discount !== 0'>
|
||||
<line indent='1'><left>Discount: <t t-esc='line.discount' />%</left></line>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user