Skip to content
Extraits de code Groupes Projets
Valider 4d3a490e rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[ADD] Add print QR code + new template

parent 0a097746
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
{
"name": "VRACOOP - POS Balance Container QRCode",
"summary": "VRACOOP - POS Balance Container QRCode",
"version": "12.0.0.2.2",
"version": "12.0.1.0.0",
"development_status": "Beta",
"author": "Le Filament",
"maintainers": ["remi-filament"],
......
......@@ -29,6 +29,7 @@ odoo.define('vracoop_pos_container_qrcode.container_print_qr', function (require
init: function(parent, options){
this._super(parent, options);
this.barcode_base64;
},
show: function(){
......@@ -58,12 +59,6 @@ odoo.define('vracoop_pos_container_qrcode.container_print_qr', function (require
var self = this;
this.$('.next,.add-container').click(function(){
self.render_receipt();
self.handle_auto_print();
self.renderElement();
});
if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input')));
}
......@@ -72,9 +67,12 @@ odoo.define('vracoop_pos_container_qrcode.container_print_qr', function (require
$("#pos-topheader-scale-cont").removeClass('oe_hidden');
setTimeout(function(){
self.set_weight(0);
}, 5000);
if (this..weight !== 0) {
self.print();
}
}, 2000);
this.render_receipt();
},
hide: function(){
......@@ -120,13 +118,96 @@ odoo.define('vracoop_pos_container_qrcode.container_print_qr', function (require
var code_base36 = ean20_int.toString(36);
var url_qrcode = url_qr.concat(code_base36);
//var logo = this.pos.company_logo_base64;
//var url_barcode = window.location.origin + "/report/barcode/?type=EAN13&value=0492525252525&width=300&height=80"
// ****************************************
// Impression barcode
var barcode = new Image();
barcode.crossOrigin = "anonymous";
var barcode_base64 = window.location.origin + "/report/barcode/?type=EAN13&value=0492525252525&width=300&height=80"
//barcode.src = window.location.origin + "/report/barcode/?type=QR&value=" + url_qrcode + "&width=200&height=200"
// var img = barcode;
// var ratio = 1;
// var targetwidth = 200;
// var maxheight = 200;
// if( img.width !== targetwidth ){
// ratio = targetwidth / img.width;
// }
// if( img.height * ratio > maxheight ){
// ratio = maxheight / img.height;
// }
// var width = Math.floor(img.width * ratio);
// var height = Math.floor(img.height * ratio);
// var c = document.createElement('canvas');
// c.width = width;
// c.height = height;
// var ctx = c.getContext('2d');
// ctx.drawImage(barcode,0,0, width, height);
// var barcode_base64 = c.toDataURL('image/png');
// Fin impression barcode
// **************************************
return {
widget: this,
weight: this.weight,
url_qrcode: url_qrcode,
id_container: code_base36
id_container: code_base36,
url_barcode: url_qrcode,
}
},
_convert_qr_img_to_base64: function () {
var mag_name = this.pos.config.mag_id;
var url_qr = this.pos.config.url_qrcode;
var prefixe_qr = this.pos.config.prefixe_qr.toString();
var timestamp = Math.floor((new Date().getTime())/1000);
var weight_str = (this.weight * 1000).toString();
var weight_str = (0.2 * 1000).toString();
weight_str = ("0000" + weight_str).slice(-4);
var ean19 = '';
ean19 = ean19.concat(prefixe_qr,timestamp.toString(),weight_str);
var ean20 = this.pos.barcode_reader.barcode_parser.sanitize_ean19(ean19);
var ean20_int = parseInt(ean20);
var code_base36 = ean20_int.toString(36);
var url_qrcode = url_qr.concat(code_base36);
var deferred = new $.Deferred();
var img = new Image();
img.onload = function () {
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
canvas.height = 200;
canvas.width = 200;
ctx.drawImage(img,0,0);
var dataURL = canvas.toDataURL('image/jpeg');
this.barcode_base64 = dataURL;
canvas = null;
deferred.resolve();
};
img.crossOrigin = 'use-credentials';
img.src = window.location.origin + "/report/barcode/?type=QR&value=" + url_qrcode + "&width=200&height=200";
return deferred;
},
renderElement: function() {
var self = this;
this._super();
this.$('.next,.add-container').click(function(){
self.print();
});
},
print_web: function() {
......@@ -148,9 +229,11 @@ odoo.define('vracoop_pos_container_qrcode.container_print_qr', function (require
}
},
print_xml: function() {
var receipt = QWeb.render('XmlQR', this.get_receipt_render_env());
var receipt = QWeb.render('XmlQR', this.get_receipt_render_env());
this.pos.proxy.print_receipt(receipt);
},
print: function() {
var self = this;
......
......@@ -80,10 +80,25 @@
</div>
</t>
<t t-name="PosQR">
<!-- OLD CODE -->
<!-- <t t-name="PosQR">
<div class="pos-sale-ticket">
<div class="pos-center-align">
<img t-att-src="widget.pos.company_logo_base64"/><br />
<div class='receipt-total'>
<div>
<t t-esc="id_container"/>
</div>
<div class="pos-right-align">
<t t-esc="weight"/>
</div>
</div>
<div>
<p>l'image se trouve la</p>
<img t-att-src="url_barcode" style="width:100%;height:35%;" />
</div>
</div>
<div class="einv-qr">
<div t-attf-id="qrcode_container">
......@@ -102,59 +117,74 @@
});
qrcode.makeCode(qr_data);
$("#qrcode > img").css({"margin":"20px auto"});
</script>
</div>
</div>
<table class='receipt-total'>
<tr>
<td><t t-esc="id_container"/></td>
<td class="pos-right-align">
</div>
</t> -->
<!-- OLD CODE -->
<!-- NEW CODE -->
<t t-name="PosQR">
<div class="pos-sale-ticket">
<div class="pos-center-align">
<img t-att-src="widget.pos.company_logo_base64"/><br />
<div class='receipt-total'>
<div>
<t t-esc="id_container"/>
</div>
<div class="pos-right-align">
<t t-esc="weight"/>
</td>
</tr>
</table>
</div>
</div>
<div>
<p>l'image se trouve la</p>
<img t-att-src="url_barcode"/>
</div>
</div>
</div>
</t>
<!-- NEW CODE -->
<t t-name="XmlQR">
<receipt align='center' width='40' value-thousands-separator='' >
^XA
^FX Third section with bar code.
^BY3,2,10
^FO60,10^BQ,2,3,H,7^FDQA,<t t-esc='url_barcode'/>^FS
^XZ
</receipt>
<!-- <receipt align='center' width='40' value-thousands-separator='' >
<div class="pos-sale-ticket">
<div class="pos-center-align">
<img t-att-src="widget.pos.company_logo_base64"/><br />
</div>
<div class="einv-qr">
<div t-attf-id="qrcode_container">
<div id="qrcode"></div>
<script type="text/javascript">
var qr_data ="<t t-esc="url_qrcode"/>";
</div>
var qrcode = new QRCode('qrcode' , {
text: qr_data,
width: 160,
height: 160,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qrcode.makeCode(qr_data);
<div>
<p>l'image se trouve la</p>
$("#qrcode > img").css({"margin":"20px auto"});
</script>
<img t-att-src="url_barcode" />
</div>
<div class='receipt-total'>
<h1>TEST</h1>
<div>
<t t-esc="id_container"/>
</div>
<table class='receipt-total'>
<tr>
<td><t t-esc="id_container"/></td>
<td class="pos-right-align">
<div class="pos-right-align">
<t t-esc="weight"/>
</td>
</tr>
</table>
</div>
</div>
</div>
</receipt>
</receipt> -->
</t>
</templates>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter