diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 0928206731b..02c1723cf2c 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -615,7 +615,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal } function is_number(char){ - n = char.charCodeAt(0); + var n = char.charCodeAt(0); return n >= 48 && n <= 57; } @@ -676,6 +676,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal }, scan: function(code){ + debugger; if(code.length < 3){ return; }else if(code.length === 13 && this.check_ean(code)){ diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index befa3c129f8..472ca9af93d 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1227,6 +1227,8 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // exports a JSON for receipt printing export_for_printing: function(){ var orderlines = []; + var self = this; + this.get('orderLines').each(function(orderline){ orderlines.push(orderline.export_for_printing()); }); @@ -1239,9 +1241,27 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var cashier = this.pos.cashier || this.pos.user; var company = this.pos.company; var shop = this.pos.shop; - var date = new Date(); + var date = new Date(); - return { + function is_xml(subreceipt){ + return subreceipt ? (subreceipt.split('\n')[0].indexOf('= 0) : false; + } + + function render_xml(subreceipt){ + if (!is_xml(subreceipt)) { + return subreceipt; + } else { + subreceipt = subreceipt.split('\n').slice(1).join('\n'); + var qweb = new QWeb2.Engine(); + qweb.debug = instance.session.debug; + qweb.default_dict = _.clone(QWeb.default_dict); + qweb.add_template(''+subreceipt+''); + + return qweb.render('subreceipt',{'pos':self.pos,'widget':self.pos.pos_widget,'order':self, 'receipt': receipt}) ; + } + } + + var receipt = { orderlines: orderlines, paymentlines: paymentlines, subtotal: this.getSubtotal(), @@ -1288,6 +1308,16 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }, currency: this.pos.currency, }; + + if (is_xml(this.pos.config.receipt_header)){ + receipt.header_xml = render_xml(this.pos.config.receipt_header); + } + + if (is_xml(this.pos.config.receipt_footer)){ + receipt.footer_xml = render_xml(this.pos.config.receipt_footer); + } + + return receipt; }, export_as_JSON: function() { var orderLines, paymentLines; diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index e4660743337..e8326d36774 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -1337,6 +1337,17 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa self.$('.next').removeClass('highlight'); } }, + print_escpos_receipt: function(){ + var env = { + widget: this, + pos: this.pos, + order: this.pos.get_order(), + receipt: this.pos.get_order().export_for_printing(), + }; + + this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',env)); + }, + // Check if the order is paid, then sends it to the backend, // and complete the sale process validate_order: function() { @@ -1406,10 +1417,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa } else { this.pos.push_order(order) if (this.pos.config.iface_print_via_proxy) { - var receipt = order.export_for_printing(); - this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',{ - receipt: receipt, widget: self, - })); + this.print_escpos_receipt(); order.finalize(); //finish order and go back to scan screen } else { this.pos_widget.screen_selector.set_current_screen(this.next_screen); diff --git a/addons/point_of_sale/static/src/js/widget_base.js b/addons/point_of_sale/static/src/js/widget_base.js index 5d059205496..a1faf8c9741 100644 --- a/addons/point_of_sale/static/src/js/widget_base.js +++ b/addons/point_of_sale/static/src/js/widget_base.js @@ -61,6 +61,19 @@ function openerp_pos_basewidget(instance, module){ //module is instance.point_of var decimals = precision > 0 ? Math.max(0,Math.ceil(Math.log(1.0/precision) / Math.log(10))) : 0; return value.toFixed(decimals); }, + format_fixed: function(value,integer_width,decimal_width){ + value = value.toFixed(decimal_width || 0); + var width = value.indexOf('.'); + if (width < 0 ) { + width = value.length; + } + var missing = integer_width - width; + while (missing > 0) { + value = '0' + value; + missing--; + } + return value; + }, }); } diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index 897ea5204c3..1c549bdd3c7 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -305,7 +305,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa }, renderElement: function(){ var self = this; - console.log('Re-Rendering Orders...',this.pos.get_order_list()); this._super(); this.$('.order-button.select-order').click(function(event){ self.order_click_handler(event,$(this)); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index b46eff0669d..0834b1aa7cd 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -660,7 +660,10 @@
- + + + +
@@ -764,9 +767,13 @@ - + + + + +
-
+

@@ -1198,9 +1205,9 @@ User:
Shop:

- +
- +

@@ -1273,10 +1280,10 @@ - +
- +