[IMP] point_of_sale: fetch is now a method

bzr revid: fva@openerp.com-20120903144354-8563uwq7x0cvqvrp
This commit is contained in:
Frédéric van der Essen
2012-09-03 16:43:54 +02:00
parent f8212984f3
commit e0d5b6ac8b
+19 -18
View File
@@ -1,9 +1,6 @@
function openerp_pos_models(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var fetch = function(model, fields, domain, ctx){
return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all()
};
// The PosModel contains the Point Of Sale's representation of the backend.
// Since the PoS must work in standalone ( Without connection to the server )
@@ -70,15 +67,19 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
});
},
// helper function to load data from the server
fetch: function(model, fields, domain, ctx){
return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all()
};
// loads all the needed data on the sever. returns a deferred indicating when all the data has loaded.
load_server_data: function(){
var self = this;
var loaded = fetch('res.users',['name','company_id'],[['id','=',this.session.uid]])
var loaded = self.fetch('res.users',['name','company_id'],[['id','=',this.session.uid]])
.pipe(function(users){
self.set('user',users[0]);
return fetch('res.company',
return self.fetch('res.company',
[
'currency_id',
'email',
@@ -93,15 +94,15 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
}).pipe(function(companies){
self.set('company',companies[0]);
return fetch('res.partner',['contact_address'],[['id','=',companies[0].partner_id[0]]]);
return self.fetch('res.partner',['contact_address'],[['id','=',companies[0].partner_id[0]]]);
}).pipe(function(company_partners){
self.get('company').contact_address = company_partners[0].contact_address;
return fetch('res.currency',['symbol','position'],[['id','=',self.get('company').currency_id[0]]]);
return self.fetch('res.currency',['symbol','position'],[['id','=',self.get('company').currency_id[0]]]);
}).pipe(function(currencies){
self.set('currency',currencies[0]);
return fetch('product.uom', null, null);
return self.fetch('product.uom', null, null);
}).pipe(function(units){
self.set('units',units);
var units_by_id = {};
@@ -110,19 +111,19 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
}
self.set('units_by_id',units_by_id);
return fetch('product.packaging', null, null);
return self.fetch('product.packaging', null, null);
}).pipe(function(packagings){
self.set('product.packaging',packagings);
return fetch('res.users', ['name','ean13'], [['ean13', '!=', false]]);
return self.fetch('res.users', ['name','ean13'], [['ean13', '!=', false]]);
}).pipe(function(users){
self.set('user_list',users);
return fetch('account.tax', ['amount', 'price_include', 'type']);
return self.fetch('account.tax', ['amount', 'price_include', 'type']);
}).pipe(function(taxes){
self.set('taxes', taxes);
return fetch(
return self.fetch(
'pos.session',
['id', 'journal_ids','name','user_id','config_id','start_at','stop_at'],
[['state', '=', 'opened'], ['user_id', '=', self.session.uid]]
@@ -130,7 +131,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
}).pipe(function(sessions){
self.set('pos_session', sessions[0]);
return fetch(
return self.fetch(
'pos.config',
['name','journal_ids','shop_id','journal_id',
'iface_self_checkout', 'iface_led', 'iface_cashdrawer',
@@ -147,15 +148,15 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
self.iface_self_checkout = !!pos_config.iface_self_checkout;
self.iface_cashdrawer = !!pos_config.iface_cashdrawer;
return fetch('sale.shop',[],[['id','=',pos_config.shop_id[0]]]);
return self.fetch('sale.shop',[],[['id','=',pos_config.shop_id[0]]]);
}).pipe(function(shops){
self.set('shop',shops[0]);
return fetch('pos.category', ['id','name','parent_id','child_id','image'])
return self.fetch('pos.category', ['id','name','parent_id','child_id','image'])
}).pipe(function(categories){
self.db.add_categories(categories);
return fetch(
return self.fetch(
'product.product',
['name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13',
'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description'],
@@ -165,7 +166,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
}).pipe(function(products){
self.db.add_products(products);
return fetch(
return self.fetch(
'account.bank.statement',
['account_id','currency','journal_id','state','name','user_id','pos_session_id'],
[['state','=','open'],['pos_session_id', '=', self.get('pos_session').id]]
@@ -173,7 +174,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
}).pipe(function(bank_statements){
self.set('bank_statements', bank_statements);
return fetch('account.journal', undefined, [['user_id','=', self.get('pos_session').user_id[0]]]);
return self.fetch('account.journal', undefined, [['user_id','=', self.get('pos_session').user_id[0]]]);
}).pipe(function(journals){
self.set('journals',journals);