d68eb59f8bfdc48c10349ec12815da580dddfc80
[odoo/odoo.git] / addons / pos_discount / static / src / js / discount.js
1 openerp.pos_discount = function(instance){
2     var module   = instance.point_of_sale;
3     var round_pr = instance.web.round_precision
4     var QWeb = instance.web.qweb;
5
6     QWeb.add_template('/pos_discount/static/src/xml/discount.xml');
7
8     module.PosWidget.include({
9         build_widgets: function(){
10             var self = this;
11             this._super();
12             
13             if(!this.pos.config.discount_product_id){
14                 return;
15             }
16
17             var discount = $(QWeb.render('DiscountButton'));
18
19             discount.click(function(){
20                 var order    = self.pos.get_order();
21                 var product  = self.pos.db.get_product_by_id(self.pos.config.discount_product_id[0]);
22                 var discount = - self.pos.config.discount_pc/ 100.0 * order.get_total_tax_included();
23                 if( discount < 0 ){
24                     order.add_product(product, { price: discount });
25                 }
26             });
27
28             discount.appendTo(this.$('.control-buttons'));
29             this.$('.control-buttons').removeClass('oe_hidden');
30         },
31     });
32
33 };
34