[FIX] point_of_sale: order total round globally
Before this commit, the amount total of an order in round_globally was simply the sum of all taxes amounts, then rounded This is plain wrong, as the accepted semantics of round globally is that: - each tax for each line is computed without rounding - then each taxes is summed across all order lines - then that amount is rounded - then all those rounded tax amount are summed together After this commit, this semantics is implemented closes odoo/odoo#35211 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
@@ -2488,9 +2488,36 @@ exports.Order = Backbone.Model.extend({
|
||||
}), 0), this.pos.currency.rounding);
|
||||
},
|
||||
get_total_tax: function() {
|
||||
return round_pr(this.orderlines.reduce((function(sum, orderLine) {
|
||||
return sum + orderLine.get_tax();
|
||||
}), 0), this.pos.currency.rounding);
|
||||
if (this.pos.company.tax_calculation_rounding_method === "round_globally") {
|
||||
// As always, we need:
|
||||
// 1. For each tax, sum their amount across all order lines
|
||||
// 2. Round that result
|
||||
// 3. Sum all those rounded amounts
|
||||
var groupTaxes = {};
|
||||
this.orderlines.each(function (line) {
|
||||
var taxDetails = line.get_tax_details();
|
||||
var taxIds = Object.keys(taxDetails);
|
||||
for (var t = 0; t<taxIds.length; t++) {
|
||||
var taxId = taxIds[t];
|
||||
if (!(taxId in groupTaxes)) {
|
||||
groupTaxes[taxId] = 0;
|
||||
}
|
||||
groupTaxes[taxId] += taxDetails[taxId];
|
||||
}
|
||||
});
|
||||
|
||||
var sum = 0;
|
||||
var taxIds = Object.keys(groupTaxes);
|
||||
for (var j = 0; j<taxIds.length; j++) {
|
||||
var taxAmount = groupTaxes[taxIds[j]];
|
||||
sum += round_pr(taxAmount, this.pos.currency.rounding);
|
||||
}
|
||||
return sum;
|
||||
} else {
|
||||
return round_pr(this.orderlines.reduce((function(sum, orderLine) {
|
||||
return sum + orderLine.get_tax();
|
||||
}), 0), this.pos.currency.rounding);
|
||||
}
|
||||
},
|
||||
get_total_paid: function() {
|
||||
return round_pr(this.paymentlines.reduce((function(sum, paymentLine) {
|
||||
|
||||
Reference in New Issue
Block a user