[MERGE] from master
[odoo/odoo.git] / addons / point_of_sale / static / src / js / models.js
index 8b9dc2e..946c7f1 100644 (file)
@@ -1,4 +1,4 @@
-function openerp_pos_models(instance, module){ //module is instance.point_of_sale
+openerp.point_of_sale.load_models = function load_models(instance, module){ //module is instance.point_of_sale
     "use strict";
 
     var QWeb = instance.web.qweb;
@@ -45,7 +45,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
             this.partners = [];
             this.cashier = null;
             this.cashregisters = [];
-            this.bankstatements = [];
             this.taxes = [];
             this.pos_session = null;
             this.config = null;
@@ -167,7 +166,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
         },{
             model:  'res.partner',
             fields: ['name','street','city','state_id','country_id','vat','phone','zip','mobile','email','barcode','write_date'],
-            domain: null,
+            domain: [['customer','=',true]], 
             loaded: function(self,partners){
                 self.partners = partners;
                 self.db.add_partners(partners);
@@ -297,7 +296,8 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
             fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code', 
                      'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description',
                      'product_tmpl_id'],
-            domain:  function(self){ return [['sale_ok','=',true],['available_in_pos','=',true]]; },
+            order:  ['sequence','name'],
+            domain: [['sale_ok','=',true],['available_in_pos','=',true]],
             context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
             loaded: function(self, products){
                 self.db.add_products(products);
@@ -306,11 +306,11 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
             model:  'account.bank.statement',
             fields: ['account_id','currency','journal_id','state','name','user_id','pos_session_id'],
             domain: function(self){ return [['state', '=', 'open'],['pos_session_id', '=', self.pos_session.id]]; },
-            loaded: function(self, bankstatements, tmp){
-                self.bankstatements = bankstatements;
+            loaded: function(self, cashregisters, tmp){
+                self.cashregisters = cashregisters;
 
                 tmp.journals = [];
-                _.each(bankstatements,function(statement){
+                _.each(cashregisters,function(statement){
                     tmp.journals.push(statement.journal_id[0]);
                 });
             },
@@ -322,19 +322,24 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
                 self.journals = journals;
 
                 // associate the bank statements with their journals. 
-                var bankstatements = self.bankstatements;
-                for(var i = 0, ilen = bankstatements.length; i < ilen; i++){
+                var cashregisters = self.cashregisters;
+                for(var i = 0, ilen = cashregisters.length; i < ilen; i++){
                     for(var j = 0, jlen = journals.length; j < jlen; j++){
-                        if(bankstatements[i].journal_id[0] === journals[j].id){
-                            bankstatements[i].journal = journals[j];
+                        if(cashregisters[i].journal_id[0] === journals[j].id){
+                            cashregisters[i].journal = journals[j];
                         }
                     }
                 }
-                self.cashregisters = bankstatements;
+
                 self.cashregisters_by_id = {};
                 for (var i = 0; i < self.cashregisters.length; i++) {
                     self.cashregisters_by_id[self.cashregisters[i].id] = self.cashregisters[i];
                 }
+
+                self.cashregisters = self.cashregisters.sort(function(a,b){ 
+                    return a.journal.sequence - b.journal.sequence; 
+                });
+
             },
         },  {
             label: 'fonts',
@@ -424,6 +429,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
                     var domain =  typeof model.domain === 'function'  ? model.domain(self,tmp)  : model.domain;
                     var context = typeof model.context === 'function' ? model.context(self,tmp) : model.context; 
                     var ids     = typeof model.ids === 'function'     ? model.ids(self,tmp) : model.ids;
+                    var order   = typeof model.order === 'function'   ? model.order(self,tmp):    model.order;
                     progress += progress_step;
                     
 
@@ -431,7 +437,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
                         if (model.ids) {
                             var records = new instance.web.Model(model.model).call('read',[ids,fields],context);
                         } else {
-                            var records = new instance.web.Model(model.model).query(fields).filter(domain).context(context).all()
+                            var records = new instance.web.Model(model.model).query(fields).filter(domain).order_by(order).context(context).all()
                         }
                         records.then(function(result){
                                 try{    // catching exceptions in model.loaded(...)
@@ -484,7 +490,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
                     } else {
                         def.reject();
                     }
-                }, function(){ def.reject(); });    
+                }, function(err,event){ event.preventDefault(); def.reject(); });    
             return def;
         },