1 openerp.point_of_sale.load_basewidget = function load_basewidget(instance, module){ //module is instance.point_of_sale
4 var round_di = instance.web.round_decimals;
5 var round_pr = instance.web.round_precision;
7 // This is a base class for all Widgets in the POS. It exposes relevant data to the
9 // - widget.currency : { symbol: '$' | '€' | ..., position: 'before' | 'after }
10 // - widget.format_currency(amount) : this method returns a formatted string based on the
11 // symbol, the position, and the amount of money.
12 // if the PoS is not fully loaded when you instanciate the widget, the currency might not
13 // yet have been initialized. Use __build_currency_template() to recompute with correct values
16 module.PosBaseWidget = instance.web.Widget.extend({
17 init:function(parent,options){
19 options = options || {};
20 this.pos = options.pos || (parent ? parent.pos : undefined);
21 this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined);
23 format_currency: function(amount,precision){
24 var currency = (this.pos && this.pos.currency) ? this.pos.currency : {symbol:'$', position: 'after', rounding: 0.01, decimals: 2};
26 amount = this.format_currency_no_symbol(amount,precision);
28 if (currency.position === 'after') {
29 return amount + ' ' + (currency.symbol || '');
31 return (currency.symbol || '') + ' ' + amount;
34 format_currency_no_symbol: function(amount, precision) {
35 var currency = (this.pos && this.pos.currency) ? this.pos.currency : {symbol:'$', position: 'after', rounding: 0.01, decimals: 2};
36 var decimals = currency.decimals;
38 if (precision && (typeof this.pos.dp[precision]) !== undefined) {
39 decimals = this.pos.dp[precision];
42 this.format_currency_no_symbol = function(amount){
43 amount = round_pr(amount,currency.rounding);
44 amount = amount.toFixed(decimals);
48 if (typeof amount === 'number') {
49 amount = round_di(amount,decimals).toFixed(decimals);
55 this.$el.removeClass('oe_hidden');
58 this.$el.addClass('oe_hidden');
60 format_pr: function(value,precision){
61 var decimals = precision > 0 ? Math.max(0,Math.ceil(Math.log(1.0/precision) / Math.log(10))) : 0;
62 return value.toFixed(decimals);
64 format_fixed: function(value,integer_width,decimal_width){
65 value = value.toFixed(decimal_width || 0);
66 var width = value.indexOf('.');
70 var missing = integer_width - width;