[IMP] crm_lead: message_new now uses the on_change_partner_id to set the address...
[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     // This is a base class for all Widgets in the POS. It exposes relevant data to the 
4     // templates : 
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
10     // before rendering.
11
12     module.PosBaseWidget = instance.web.Widget.extend({
13         init:function(parent,options){
14             this._super(parent);
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();
19         },
20         build_currency_template: function(){
21
22             if(this.pos && this.pos.get('currency')){
23                 this.currency = this.pos.get('currency');
24             }else{
25                 this.currency = {symbol: '$', position: 'after'};
26             }
27
28             this.format_currency = function(amount){
29                 if(this.currency.position === 'after'){
30                     return Math.round(amount*100)/100 + ' ' + this.currency.symbol;
31                 }else{
32                     return this.currency.symbol + ' ' + Math.round(amount*100)/100;
33                 }
34             }
35
36         },
37         show: function(){
38             this.$el.show();
39         },
40         hide: function(){
41             this.$el.hide();
42         },
43     });
44
45 }