[FIX] account: give "Invoice" users access to "Invoice Analysis" Report.
[odoo/odoo.git] / addons / point_of_sale / static / src / js / widget_base.js
1 function openerp_pos_basewidget(instance, module){ //module is instance.point_of_sale
2
3     var round_di = instance.web.round_decimals;
4     var round_pr = instance.web.round_precision
5
6     // This is a base class for all Widgets in the POS. It exposes relevant data to the 
7     // templates : 
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
13     // before rendering.
14
15     module.PosBaseWidget = instance.web.Widget.extend({
16         init:function(parent,options){
17             this._super(parent);
18             options = options || {};
19             this.pos = options.pos || (parent ? parent.pos : undefined);
20             this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined);
21         },
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;
25
26             if (precision && (typeof this.pos.dp[precision]) !== undefined) {
27                 decimals = this.pos.dp[precision];
28             }
29
30             if (typeof amount === 'number') {
31                 amount = round_di(amount,decimals).toFixed(decimals);
32             }
33
34             if (currency.position === 'after') {
35                 return amount + ' ' + (currency.symbol || '');
36             } else {
37                 return (currency.symbol || '') + ' ' + amount;
38             }
39         },
40         show: function(){
41             this.$el.removeClass('oe_hidden');
42         },
43         hide: function(){
44             this.$el.addClass('oe_hidden');
45         },
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);
49         },
50     });
51
52 }