Browse Source

[FIX] Fiscal position tax mapping

It was adding to the product all the right-handed taxes found in the fiscal position, not taking into account the product source tax.
pull/39/head
PabloCM 9 years ago
parent
commit
57a30cc8c3
  1. 15
      pos_pricelist/static/src/js/db.js
  2. 36
      pos_pricelist/static/src/js/models.js

15
pos_pricelist/static/src/js/db.js

@ -140,15 +140,24 @@ function pos_pricelist_db(instance, module) {
});
return list;
},
find_taxes_by_fiscal_position_id: function (fiscal_position_id) {
find_taxes_by_fiscal_position_id: function (fiscal_position_id, taxes_ids) {
var taxes = [];
var found_taxes = {};
for (var id in this.fiscal_position_tax_by_id) {
var tax = this.fiscal_position_tax_by_id[id];
if (tax && tax.position_id &&
tax.position_id[0] == fiscal_position_id) {
taxes.push(tax);
tax.position_id[0] == fiscal_position_id &&
taxes_ids.indexOf(tax.tax_src_id[0]) > -1) {
taxes.push(tax.tax_dest_id[0]);
found_taxes[tax.tax_src_id[0]] = true;
}
}
for (var i = 0, len = taxes_ids.length; i < len; i++) {
var tax_id = taxes_ids[i];
if (! tax_id in found_taxes) {
taxes.push(tax_id);
}
}
return taxes;
},
add_products: function (products) {

36
pos_pricelist/static/src/js/models.js

@ -264,38 +264,24 @@ function pos_pricelist_models(instance, module) {
get_applicable_taxes_for_orderline: function () {
// find applicable taxes for this product and this customer
var fiscal_position_taxes = [];
var product_taxes = [];
var product = this.get_product();
var partner = this.order ? this.order.get_client() : null;
var product_tax_ids = product.taxes_id;
var product_taxes = [];
var taxes = this.pos.taxes;
var partner = this.order ? this.order.get_client() : null;
if (partner && partner.property_account_position) {
fiscal_position_taxes =
product_tax_ids =
this.pos.db.find_taxes_by_fiscal_position_id(
partner.property_account_position[0]
partner.property_account_position[0], product_tax_ids
);
}
for (var i = 0, ilen = fiscal_position_taxes.length;
for (var i = 0, ilen = product_tax_ids.length;
i < ilen; i++) {
var fp_tax = fiscal_position_taxes[i];
for (var j = 0, jlen = taxes.length; j < jlen; j++) {
var p_tax = taxes[j];
if (fp_tax && p_tax && fp_tax.tax_src_id[0] === p_tax.id) {
var dest_tax = _.detect(taxes, function (t) {
return t.id === fp_tax.tax_dest_id[0];
});
product_taxes.push(dest_tax);
}
}
}
if (product_taxes.length === 0) {
for (var i = 0, ilen = product.taxes_id.length;
i < ilen; i++) {
var _id = product.taxes_id[i];
var p_tax = _.detect(taxes, function (t) {
return t.id === _id;
});
product_taxes.push(p_tax);
}
var tax_id = product_tax_ids[i];
var tax = _.detect(taxes, function (t) {
return t.id === tax_id;
});
product_taxes.push(tax);
}
return product_taxes;
},

Loading…
Cancel
Save