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