1 function openerp_pos_basewidget(instance, module){ //module is instance.point_of_sale
3 var round_pr = instance.web.round_precision
5 // This is a base class for all Widgets in the POS. It exposes relevant data to the
7 // - widget.currency : { symbol: '$' | '€' | ..., position: 'before' | 'after }
8 // - widget.format_currency(amount) : this method returns a formatted string based on the
9 // symbol, the position, and the amount of money.
10 // if the PoS is not fully loaded when you instanciate the widget, the currency might not
11 // yet have been initialized. Use __build_currency_template() to recompute with correct values
14 module.PosBaseWidget = instance.web.Widget.extend({
15 init:function(parent,options){
17 options = options || {};
18 this.pos = options.pos || (parent ? parent.pos : undefined);
19 this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined);
20 this.build_currency_template();
22 build_currency_template: function(){
24 if(this.pos && this.pos.currency){
25 this.currency = this.pos.currency;
27 this.currency = {symbol: '$', position: 'after', rounding: 0.01};
30 var decimals = Math.max(0,Math.ceil(Math.log(1.0 / this.currency.rounding) / Math.log(10)));
32 this.format_currency_no_symbol = function(amount){
33 amount = round_pr(amount,this.currency.rounding);
34 amount = amount.toFixed(decimals);
38 this.format_currency = function(amount){
39 if(typeof amount === 'number'){
40 amount = Math.round(amount*100)/100;
41 amount = amount.toFixed(decimals);
43 if(this.currency.position === 'after'){
44 return amount + ' ' + (this.currency.symbol || '');
46 return (this.currency.symbol || '') + ' ' + amount;
52 this.$el.removeClass('oe_hidden');
55 this.$el.addClass('oe_hidden');
57 format_pr: function(value,precision){
58 var decimals = precision > 0 ? Math.max(0,Math.ceil(Math.log(1.0/precision) / Math.log(10))) : 0;
59 return value.toFixed(decimals);