1 function openerp_pos_basewidget(instance, module){ //module is instance.point_of_sale
3 var round_di = instance.web.round_decimals;
4 var round_pr = instance.web.round_precision
6 // This is a base class for all Widgets in the POS. It exposes relevant data to the
8 // - widget.currency : { symbol: '$' | '€' | ..., position: 'before' | 'after }
9 // - widget.format_currency(amount) : this method returns a formatted string based on the
10 // symbol, the position, and the amount of money.
11 // if the PoS is not fully loaded when you instanciate the widget, the currency might not
12 // yet have been initialized. Use __build_currency_template() to recompute with correct values
15 module.PosBaseWidget = instance.web.Widget.extend({
16 init:function(parent,options){
18 options = options || {};
19 this.pos = options.pos || (parent ? parent.pos : undefined);
20 this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined);
22 format_currency: function(amount,precision){
23 var currency = (this.pos && this.pos.currency) ? this.pos.currency : {symbol:'$', position: 'after', rounding: 0.01, decimals: 2};
24 var decimals = currency.decimals;
26 if (precision && (typeof this.pos.dp[precision]) !== undefined) {
27 decimals = this.pos.dp[precision];
30 if (typeof amount === 'number') {
31 amount = round_di(amount,decimals).toFixed(decimals);
34 if (currency.position === 'after') {
35 return amount + ' ' + (currency.symbol || '');
37 return (currency.symbol || '') + ' ' + amount;
41 this.$el.removeClass('oe_hidden');
44 this.$el.addClass('oe_hidden');
46 format_pr: function(value,precision){
47 var decimals = precision > 0 ? Math.max(0,Math.ceil(Math.log(1.0/precision) / Math.log(10))) : 0;
48 return value.toFixed(decimals);