Commit a55cb992 by François C.

Merge branch '1996-see-meal-voucher-products-on-ticket' into 'meal-vouchers'

display symbol on pos ticket for products associated with meal vouchers, when used

See merge request !21
parents 180b2d14 8c470aae
......@@ -35,6 +35,126 @@ odoo.define("pos_meal_voucher.models", function (require) {
}
}), 0), this.pos.currency.rounding);
},
/* point_of_sale/statis/src/js/models.js */
export_for_printing: function(){
var orderlines = [];
var self = this;
var paymentlines = [];
// Add fork&knife symbol on pos ticket for products with meal voucher allowed & when meal voucher is used
var meal_voucher_used = false;
this.paymentlines.each(function(paymentline){
var line = paymentline.export_for_printing();
paymentlines.push(line);
if (paymentline.is_meal_voucher()) {
meal_voucher_used = true;
}
});
this.orderlines.each(function(orderline){
var orderline_for_printing = orderline.export_for_printing()
if (
meal_voucher_used === true &&
orderline.product.meal_voucher_ok === true &&
orderline_for_printing.product_name.includes(String.fromCharCode(0xD83C, 0xDF74)) === false
) {
orderline_for_printing.product_name = String.fromCharCode(0xD83C, 0xDF74) + " " + orderline_for_printing.product_name;
} else if (meal_voucher_used === false && orderline_for_printing.product_name.includes(String.fromCharCode(0xD83C, 0xDF74)) === true) {
orderline_for_printing.product_name = orderline_for_printing.product_name.replace(String.fromCharCode(0xD83C, 0xDF74) + " ", "");
}
orderlines.push(orderline_for_printing);
});
var client = this.get('client');
var cashier = this.pos.cashier || this.pos.user;
var company = this.pos.company;
var shop = this.pos.shop;
var date = new Date();
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 = core.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.chrome,'order':self, 'receipt': receipt}) ;
}
}
var receipt = {
orderlines: orderlines,
paymentlines: paymentlines,
subtotal: this.get_subtotal(),
total_with_tax: this.get_total_with_tax(),
total_without_tax: this.get_total_without_tax(),
total_tax: this.get_total_tax(),
total_paid: this.get_total_paid(),
total_discount: this.get_total_discount(),
tax_details: this.get_tax_details(),
change: this.get_change(),
name : this.get_name(),
client: client ? client.name : null ,
invoice_id: null, //TODO
cashier: cashier ? cashier.name : null,
precision: {
price: 2,
money: 2,
quantity: 3,
},
date: {
year: date.getFullYear(),
month: date.getMonth(),
date: date.getDate(), // day of the month
day: date.getDay(), // day of the week
hour: date.getHours(),
minute: date.getMinutes() ,
isostring: date.toISOString(),
localestring: date.toLocaleString(),
},
company:{
email: company.email,
website: company.website,
company_registry: company.company_registry,
contact_address: company.partner_id[1],
vat: company.vat,
name: company.name,
phone: company.phone,
logo: this.pos.company_logo_base64,
},
shop:{
name: shop.name,
},
currency: this.pos.currency,
};
if (is_xml(this.pos.config.receipt_header)){
receipt.header = '';
receipt.header_xml = render_xml(this.pos.config.receipt_header);
} else {
receipt.header = this.pos.config.receipt_header || '';
}
if (is_xml(this.pos.config.receipt_footer)){
receipt.footer = '';
receipt.footer_xml = render_xml(this.pos.config.receipt_footer);
} else {
receipt.footer = this.pos.config.receipt_footer || '';
}
return receipt;
},
});
models.Order = Order;
......
......@@ -8,6 +8,7 @@ odoo.define("pos_meal_voucher.screens", function (require) {
var screens = require("point_of_sale.screens");
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
screens.ScreenWidget.include({
barcode_meal_voucher_payment_action: function (code) {
......@@ -201,4 +202,41 @@ odoo.define("pos_meal_voucher.screens", function (require) {
},
});
/* point_of_sale/statis/src/js/screens.js */
screens.ReceiptScreenWidget.include({
render_receipt: function() {
var order = this.pos.get_order();
var orderlines = order.get_orderlines();
var paymentlines = order.get_paymentlines();
// Add fork&knife symbol on pos ticket for product with meal voucher allowed & when meal voucher is used
var meal_voucher_used = false;
for (var i = 0; i < paymentlines.length; i++) {
if (paymentlines[i].is_meal_voucher()) {
meal_voucher_used = true;
break;
}
};
for (var i = 0; i < orderlines.length; i++) {
if (
meal_voucher_used === true &&
orderlines[i].product.meal_voucher_ok === true &&
orderlines[i].product.display_name.includes(String.fromCharCode(0xD83C, 0xDF74)) === false
) {
orderlines[i].product.display_name = String.fromCharCode(0xD83C, 0xDF74) + " " + orderlines[i].product.display_name;
} else if (meal_voucher_used === false && orderlines[i].product.display_name.includes(String.fromCharCode(0xD83C, 0xDF74)) === true) {
orderlines[i].product.display_name = orderlines[i].product.display_name.replace(String.fromCharCode(0xD83C, 0xDF74) + " ", "");
}
}
this.$('.pos-receipt-container').html(QWeb.render('PosTicket',{
widget:this,
order: order,
receipt: order.export_for_printing(),
orderlines: orderlines,
paymentlines: paymentlines
}));
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment