[IMP] point_of_sale: QWeb receipt extensions. If You put <!DOCTYPE QWEB> as the first line of a receipt header or footer, it will be rendered by qweb

This commit is contained in:
Frederic van der Essen
2014-11-26 11:26:58 +01:00
committed by Frédéric van der Essen
parent ecb2e08648
commit f8778e5a4f
6 changed files with 73 additions and 15 deletions
@@ -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)){
+32 -2
View File
@@ -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('<!DOCTYPE QWEB') >= 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('<templates><t t-name="subreceipt">'+subreceipt+'</t></templates>');
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;
+12 -4
View File
@@ -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);
@@ -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;
},
});
}
@@ -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));
+14 -7
View File
@@ -660,7 +660,10 @@
<t t-if='receipt.company.website'>
<div><t t-esc='receipt.company.website' /></div>
</t>
<t t-if='receipt.header'>
<t t-if='receipt.header_xml'>
<t t-raw='receipt.header_xml' />
</t>
<t t-if='!receipt.header_xml and receipt.header'>
<div><t t-esc='receipt.header' /></div>
</t>
<t t-if='receipt.cashier'>
@@ -764,9 +767,13 @@
</t>
<!-- Footer -->
<t t-if='receipt.footer'>
<t t-if='receipt.footer_xml'>
<t t-raw='receipt.footer_xml' />
</t>
<t t-if='!receipt.footer_xml and receipt.footer'>
<br/>
<pre><t t-esc='receipt.footer' /></pre>
<t t-esc='receipt.footer' />
<br/>
<br/>
</t>
@@ -1198,9 +1205,9 @@
User: <t t-esc="widget.pos.cashier ? widget.pos.cashier.name : widget.pos.user.name"/><br />
Shop: <t t-esc="widget.pos.shop.name"/><br />
<br />
<t t-if="widget.pos.config.receipt_header">
<t t-if="header">
<div style='text-align:center'>
<t t-esc="widget.pos.config.receipt_header" />
<t t-raw="header" />
</div>
<br />
</t>
@@ -1273,10 +1280,10 @@
<t t-esc="widget.format_currency(order.getChange())"/>
</td></tr>
</table>
<t t-if="widget.pos.config.receipt_footer">
<t t-if="footer">
<br />
<div style='text-align:center'>
<t t-esc="widget.pos.config.receipt_footer" />
<t t-raw="footer" />
</div>
</t>
</div>