[FIX] point_of_sale: tax calculation

Inconsistencies can arise between the tax calculation performed in the
PoS and in the backend (e.g. in a SO). For example:
- Unit price: 9.479
- Tax: excluded, 5.5 %
- Buy 5 units
- Round globally

In the backend, the result is 47.40 + 2.60 = 50.00
In the PoS, the result is 47.40 + 2.61 = 50.01

We make the PoS apply the same logic than in the backend. First, at the
level of the `compute_all` method, especially to use the appropriate
rounding precision before starting the calculation (so we move the
rounding of `total_excluded` after the rounding precision adjustment).
Then, by calculating the taxes amount as the difference between
`priceWithTax` with `priceWithoutTax`. This is mandatory since they
contain the result of `compute_all` in which the rounding logic has
already been applied.

opw-680891
This commit is contained in:
Nicolas Martinelli
2016-09-07 09:13:03 +02:00
parent 8e65b57df7
commit 06754b3237
+10 -7
View File
@@ -1337,13 +1337,14 @@ exports.Orderline = Backbone.Model.extend({
},
compute_all: function(taxes, price_unit, quantity, currency_rounding) {
var self = this;
var total_excluded = round_pr(price_unit * quantity, currency_rounding);
var total_included = total_excluded;
var base = total_excluded;
var list_taxes = [];
var currency_rounding_bak = currency_rounding;
if (this.pos.company.tax_calculation_rounding_method == "round_globally"){
currency_rounding = currency_rounding * 0.00001;
}
var total_excluded = round_pr(price_unit * quantity, currency_rounding);
var total_included = total_excluded;
var base = total_excluded;
_(taxes).each(function(tax) {
tax = self._map_tax_fiscal_position(tax);
if (tax.amount_type === 'group'){
@@ -1377,11 +1378,14 @@ exports.Orderline = Backbone.Model.extend({
}
}
});
return {taxes: list_taxes, total_excluded: total_excluded, total_included: total_included};
return {
taxes: list_taxes,
total_excluded: round_pr(total_excluded, currency_rounding_bak),
total_included: round_pr(total_included, currency_rounding_bak)
};
},
get_all_prices: function(){
var price_unit = this.get_unit_price() * (1.0 - (this.get_discount() / 100.0));
var taxtotal = 0;
var product = this.get_product();
var taxes_ids = product.taxes_id;
@@ -1397,14 +1401,13 @@ exports.Orderline = Backbone.Model.extend({
var all_taxes = this.compute_all(product_taxes, price_unit, this.get_quantity(), this.pos.currency.rounding);
_(all_taxes.taxes).each(function(tax) {
taxtotal += tax.amount;
taxdetail[tax.id] = tax.amount;
});
return {
"priceWithTax": all_taxes.total_included,
"priceWithoutTax": all_taxes.total_excluded,
"tax": taxtotal,
"tax": all_taxes.total_included - all_taxes.total_excluded,
"taxDetails": taxdetail,
};
},