[IMP] point_of_sale: access taxes via id for performance reasons
[IMP] point_of_sale: do not recompute taxes_by_id every time
This commit is contained in:
parent
fd1f165f18
commit
34b539494e
|
@ -188,9 +188,15 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
},
|
||||
},{
|
||||
model: 'account.tax',
|
||||
fields: ['name','amount', 'price_include', 'type'],
|
||||
fields: ['name','amount', 'price_include', 'include_base_amount', 'type'],
|
||||
domain: null,
|
||||
loaded: function(self,taxes){ self.taxes = taxes; },
|
||||
loaded: function(self,taxes){
|
||||
self.taxes = taxes;
|
||||
self.taxes_by_id = {};
|
||||
for (var i = 0; i < taxes.length; i++) {
|
||||
self.taxes_by_id[taxes[i].id] = taxes[i];
|
||||
}
|
||||
},
|
||||
},{
|
||||
model: 'pos.session',
|
||||
fields: ['id', 'journal_ids','name','user_id','config_id','start_at','stop_at','sequence_number','login_number'],
|
||||
|
@ -812,7 +818,8 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
},
|
||||
get_base_price: function(){
|
||||
var rounding = this.pos.currency.rounding;
|
||||
return round_pr(round_pr(this.get_unit_price() * this.get_quantity(),rounding) * (1- this.get_discount()/100.0),rounding);
|
||||
var price = round_pr(round_pr(this.get_unit_price() * this.get_quantity(),rounding) * (1- this.get_discount()/100.0),rounding);
|
||||
return price;
|
||||
},
|
||||
get_display_price: function(){
|
||||
return this.get_base_price();
|
||||
|
@ -826,6 +833,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
get_tax: function(){
|
||||
return this.get_all_prices().tax;
|
||||
},
|
||||
get_tax_objects: function(){
|
||||
var taxes_ids = this.get_product().taxes_id;
|
||||
var taxes = [];
|
||||
for (var i = 0; i < taxes_ids.length; i++) {
|
||||
taxes.push(this.pos.taxes_by_id[taxes_ids[i]]);
|
||||
}
|
||||
return taxes;
|
||||
},
|
||||
get_tax_details: function(){
|
||||
return this.get_all_prices().taxDetails;
|
||||
},
|
||||
|
@ -837,12 +852,10 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
var totalNoTax = base;
|
||||
|
||||
var product = this.get_product();
|
||||
var taxes_ids = product.taxes_id;
|
||||
var taxes = self.pos.taxes;
|
||||
var taxes = this.get_tax_objects();
|
||||
var taxtotal = 0;
|
||||
var taxdetail = {};
|
||||
_.each(taxes_ids, function(el) {
|
||||
var tax = _.detect(taxes, function(t) {return t.id === el;});
|
||||
_.each(taxes, function(tax) {
|
||||
if (tax.price_include) {
|
||||
var tmp;
|
||||
if (tax.type === "percent") {
|
||||
|
@ -1074,11 +1087,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
getTaxDetails: function(){
|
||||
var details = {};
|
||||
var fulldetails = [];
|
||||
var taxes_by_id = {};
|
||||
|
||||
for(var i = 0; i < this.pos.taxes.length; i++){
|
||||
taxes_by_id[this.pos.taxes[i].id] = this.pos.taxes[i];
|
||||
}
|
||||
|
||||
this.get('orderLines').each(function(line){
|
||||
var ldetails = line.get_tax_details();
|
||||
|
@ -1091,7 +1099,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
|
||||
for(var id in details){
|
||||
if(details.hasOwnProperty(id)){
|
||||
fulldetails.push({amount: details[id], tax: taxes_by_id[id], name: taxes_by_id[id].name});
|
||||
fulldetails.push({amount: details[id], tax: this.pos.taxes_by_id[id], name: this.pos.taxes_by_id[id].name});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue