[FIX] point_of_sale: the receipt would not print correctly on first try
This commit is contained in:
parent
81ce316ada
commit
986f0e9d46
|
@ -0,0 +1,59 @@
|
|||
// http://stackoverflow.com/questions/4383226/using-jquery-to-know-when-font-face-fonts-are-loaded
|
||||
(function(){
|
||||
function waitForWebfonts(fonts, callback) {
|
||||
var loadedFonts = 0;
|
||||
for(var i = 0, l = fonts.length; i < l; ++i) {
|
||||
(function(font) {
|
||||
var node = document.createElement('span');
|
||||
// Characters that vary significantly among different fonts
|
||||
node.innerHTML = 'giItT1WQy@!-/#';
|
||||
// Visible - so we can measure it - but not on the screen
|
||||
node.style.position = 'absolute';
|
||||
node.style.left = '-10000px';
|
||||
node.style.top = '-10000px';
|
||||
// Large font size makes even subtle changes obvious
|
||||
node.style.fontSize = '300px';
|
||||
// Reset any font properties
|
||||
node.style.fontFamily = 'sans-serif';
|
||||
node.style.fontVariant = 'normal';
|
||||
node.style.fontStyle = 'normal';
|
||||
node.style.fontWeight = 'normal';
|
||||
node.style.letterSpacing = '0';
|
||||
document.body.appendChild(node);
|
||||
|
||||
// Remember width with no applied web font
|
||||
var width = node.offsetWidth;
|
||||
|
||||
node.style.fontFamily = font;
|
||||
|
||||
var interval;
|
||||
function checkFont() {
|
||||
// Compare current width with original width
|
||||
if(node && node.offsetWidth != width) {
|
||||
++loadedFonts;
|
||||
node.parentNode.removeChild(node);
|
||||
node = null;
|
||||
}
|
||||
|
||||
// If all fonts have been loaded
|
||||
if(loadedFonts >= fonts.length) {
|
||||
if(interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
if(loadedFonts == fonts.length) {
|
||||
callback();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(!checkFont()) {
|
||||
interval = setInterval(checkFont, 50);
|
||||
}
|
||||
})(fonts[i]);
|
||||
}
|
||||
}
|
||||
window.waitForWebfonts = waitForWebfonts;
|
||||
})();
|
||||
|
||||
|
|
@ -277,6 +277,27 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
self.cashregisters = bankstatements;
|
||||
},
|
||||
},{
|
||||
label: 'fonts',
|
||||
loaded: function(self){
|
||||
var fonts_loaded = new $.Deferred();
|
||||
|
||||
// Waiting for fonts to be loaded to prevent receipt printing
|
||||
// from printing empty receipt while loading Inconsolata
|
||||
// ( The font used for the receipt )
|
||||
waitForWebfonts(['Lato','Inconsolata'], function(){
|
||||
fonts_loaded.resolve();
|
||||
});
|
||||
|
||||
// The JS used to detect font loading is not 100% robust, so
|
||||
// do not wait more than 5sec
|
||||
setTimeout(function(){
|
||||
fonts_loaded.resolve();
|
||||
},5000);
|
||||
|
||||
return fonts_loaded;
|
||||
},
|
||||
},{
|
||||
label: 'pictures',
|
||||
loaded: function(self){
|
||||
self.company_logo = new Image();
|
||||
self.company_logo.crossOrigin = 'anonymous';
|
||||
|
@ -327,7 +348,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
loaded.resolve();
|
||||
}else{
|
||||
var model = self.models[index];
|
||||
self.pos_widget.loading_message(_t('Loading')+' '+(model.model || ''), progress);
|
||||
self.pos_widget.loading_message(_t('Loading')+' '+(model.label || model.model || ''), progress);
|
||||
var fields = typeof model.fields === 'function' ? model.fields(self,tmp) : model.fields;
|
||||
var domain = typeof model.domain === 'function' ? model.domain(self,tmp) : model.domain;
|
||||
var context = typeof model.context === 'function' ? model.context(self,tmp) : model.context;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<template id="assets_backend" name="point_of_sale assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/point_of_sale/static/lib/fastclick.js"></script>
|
||||
<script type="text/javascript" src="/point_of_sale/static/lib/waitfont.js"></script>
|
||||
<script type="text/javascript" src="/point_of_sale/static/src/js/db.js"></script>
|
||||
<script type="text/javascript" src="/point_of_sale/static/src/js/models.js"></script>
|
||||
<script type="text/javascript" src="/point_of_sale/static/src/js/widget_base.js"></script>
|
||||
|
|
Loading…
Reference in New Issue