Merge branch 'master-pos-wms-fva'
[odoo/odoo.git] / addons / pos_restaurant / static / src / js / splitbill.js
index 81591cc..f58f77e 100644 (file)
@@ -11,11 +11,11 @@ function openerp_restaurant_splitbill(instance, module){
         renderElement: function(){
             var self = this;
             this._super();
-            var order = this.pos.get('selectedOrder');
+            var order = this.pos.get_order();
             if(!order){
                 return;
             }
-            var orderlines = order.get('orderLines').models;
+            var orderlines = order.get_orderlines();
             for(var i = 0; i < orderlines.length; i++){
                 var line = orderlines[i];
                 linewidget = $(QWeb.render('SplitOrderline',{ 
@@ -35,7 +35,7 @@ function openerp_restaurant_splitbill(instance, module){
 
         lineselect: function($el,order,neworder,splitlines,line_id){
             var split = splitlines[line_id] || {'quantity': 0, line: null};
-            var line  = order.getOrderline(line_id);
+            var line  = order.get_orderline(line_id);
             
             if( !line.get_unit().groupable ){
                 if( split.quantity !== line.get_quantity()){
@@ -57,11 +57,11 @@ function openerp_restaurant_splitbill(instance, module){
             if( split.quantity ){
                 if ( !split.line ){
                     split.line = line.clone();
-                    neworder.addOrderline(split.line);
+                    neworder.add_orderline(split.line);
                 }
                 split.line.set_quantity(split.quantity);
             }else if( split.line ) {
-                neworder.removeOrderline(split.line);
+                neworder.remove_orderline(split.line);
                 split.line = null;
             }
      
@@ -73,11 +73,11 @@ function openerp_restaurant_splitbill(instance, module){
                 quantity: split.quantity,
                 id: line_id,
             })));
-            this.$('.order-info .subtotal').text(this.format_currency(neworder.getSubtotal()));
+            this.$('.order-info .subtotal').text(this.format_currency(neworder.get_subtotal()));
         },
 
-        pay: function($el,order,neworder,splitlines,cashregister_id){
-            var orderlines = order.get('orderLines').models;
+        pay: function(order,neworder,splitlines){
+            var orderlines = order.get_orderlines();
             var empty = true;
             var full  = true;
 
@@ -100,27 +100,19 @@ function openerp_restaurant_splitbill(instance, module){
                 return;
             }
 
-            for(var i = 0; i < this.pos.cashregisters.length; i++){
-                if(this.pos.cashregisters[i].id === cashregister_id){
-                    var cashregister = this.pos.cashregisters[i];
-                    break;
-                }
-            }
 
             if(full){
-                order.addPaymentline(cashregister);
                 this.pos_widget.screen_selector.set_current_screen('payment');
             }else{
                 for(var id in splitlines){
                     var split = splitlines[id];
-                    var line  = order.getOrderline(parseInt(id));
+                    var line  = order.get_orderline(parseInt(id));
                     line.set_quantity(line.get_quantity() - split.quantity);
                     if(Math.abs(line.get_quantity()) < 0.00001){
-                        order.removeOrderline(line);
+                        order.remove_orderline(line);
                     }
                     delete splitlines[id];
                 }
-                neworder.addPaymentline(cashregister);
                 neworder.set_screen_data('screen','payment');
 
                 // for the kitchen printer we assume that everything
@@ -144,8 +136,8 @@ function openerp_restaurant_splitbill(instance, module){
             this._super();
             this.renderElement();
 
-            var order = this.pos.get('selectedOrder');
-            var neworder = new module.Order({
+            var order = this.pos.get_order();
+            var neworder = new module.Order({},{
                 pos: this.pos,
                 temporary: true,
             });
@@ -159,10 +151,8 @@ function openerp_restaurant_splitbill(instance, module){
                 self.lineselect($el,order,neworder,splitlines,id);
             });
 
-            this.$('.paymentmethod').click(function(){
-                var id = parseInt($(this).data('id'));
-                var $el = $(this);
-                self.pay($el,order,neworder,splitlines,id);
+            this.$('.paymentmethods .button').click(function(){
+                self.pay(order,neworder,splitlines);
             });
         },
     });
@@ -180,7 +170,7 @@ function openerp_restaurant_splitbill(instance, module){
                 var splitbill = $(QWeb.render('SplitbillButton'));
 
                 splitbill.click(function(){
-                    if(self.pos.get('selectedOrder').get('orderLines').models.length > 0){
+                    if(self.pos.get_order().get_orderlines().length > 0){
                         self.pos_widget.screen_selector.set_current_screen('splitbill');
                     }
                 });