summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/models.js
diff options
context:
space:
mode:
authorPierre Masereel <pim@odoo.com>2020-10-14 14:15:29 +0000
committerPierre Masereel <pim@odoo.com>2020-10-19 18:45:51 +0000
commitf8737b4676ea86abc0f39e448849453f28d4b10f (patch)
tree6ce5c4a4d458dc2e499130508f8ec08cd7140f1b /addons/point_of_sale/static/src/js/models.js
parent43e6f95b8d320854a84489a7007820a49be48cd2 (diff)
[FIX] point_of_sale: fix price computation for tax included
When you hava a fiscal position that that map one tax included into the price to another, the new amount is wrong. I we have a fiscal position that map a tax of 10% included to 20% included, and a product at 110$ having 10% included. When we map the tax from 10% to 20%, the new price is 100$ but should be 120$. This is because for now, the price is fixed to get the amount without tax, which perfectly works when destination tax is tax excluded. But when you call compute_all from a price with a tax included (20%) it keep the price and compute the tax amount out of this price. So to fix this issue, whent the origin tax and destination tax are included, we are computing the base amount (like before) and then we compute the new tax amount wihtout trying to find the tax amount out of the price. This will lead to have the same behavior between accounting and POS closes odoo/odoo#60237 X-original-commit: a0baa3751e1d8825c657464097f77f1957149065 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/point_of_sale/static/src/js/models.js')
-rw-r--r--addons/point_of_sale/static/src/js/models.js69
1 files changed, 40 insertions, 29 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index aff04017b64..a7d826eacd9 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -1849,13 +1849,15 @@ exports.Orderline = Backbone.Model.extend({
// in the orderline. This returns true if it makes sense to merge the two
can_be_merged_with: function(orderline){
var price = parseFloat(round_di(this.price || 0, this.pos.dp['Product Price']).toFixed(this.pos.dp['Product Price']));
+ var order_line_price = orderline.get_product().get_price(orderline.order.pricelist, this.get_quantity());
+ order_line_price = orderline.compute_fixed_price(order_line_price);
if( this.get_product().id !== orderline.get_product().id){ //only orderline of the same product can be merged
return false;
}else if(!this.get_unit() || !this.get_unit().is_pos_groupable){
return false;
}else if(this.get_discount() > 0){ // we don't merge discounted orderlines
return false;
- }else if(!utils.float_is_zero(price - orderline.get_product().get_price(orderline.order.pricelist, this.get_quantity()) - orderline.get_price_extra(),
+ }else if(!utils.float_is_zero(price - order_line_price - orderline.get_price_extra(),
this.pos.currency.decimals)){
return false;
}else if(this.product.tracking == 'lot') {
@@ -2102,7 +2104,7 @@ exports.Orderline = Backbone.Model.extend({
*
* Read comments in the python side method for more details about each sub-methods.
*/
- compute_all: function(taxes, price_unit, quantity, currency_rounding) {
+ compute_all: function(taxes, price_unit, quantity, currency_rounding, handle_price_include=true) {
var self = this;
// 1) Flatten the taxes.
@@ -2169,34 +2171,35 @@ exports.Orderline = Backbone.Model.extend({
var incl_division_amount = 0.0;
var cached_tax_amounts = {};
-
- _(taxes.reverse()).each(function(tax){
- if(tax.include_base_amount){
- base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount);
- incl_fixed_amount = 0.0;
- incl_percent_amount = 0.0;
- incl_division_amount = 0.0;
- store_included_tax_total = true;
- }
- if(tax.price_include){
- if(tax.amount_type === 'percent')
- incl_percent_amount += tax.amount;
- else if(tax.amount_type === 'division')
- incl_division_amount += tax.amount;
- else if(tax.amount_type === 'fixed')
- incl_fixed_amount += quantity * tax.amount
- else{
- var tax_amount = self._compute_all(tax, base, quantity);
- incl_fixed_amount += tax_amount;
- cached_tax_amounts[i] = tax_amount;
+ if (handle_price_include){
+ _(taxes.reverse()).each(function(tax){
+ if(tax.include_base_amount){
+ base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount);
+ incl_fixed_amount = 0.0;
+ incl_percent_amount = 0.0;
+ incl_division_amount = 0.0;
+ store_included_tax_total = true;
}
- if(store_included_tax_total){
- total_included_checkpoints[i] = base;
- store_included_tax_total = false;
+ if(tax.price_include){
+ if(tax.amount_type === 'percent')
+ incl_percent_amount += tax.amount;
+ else if(tax.amount_type === 'division')
+ incl_division_amount += tax.amount;
+ else if(tax.amount_type === 'fixed')
+ incl_fixed_amount += quantity * tax.amount
+ else{
+ var tax_amount = self._compute_all(tax, base, quantity);
+ incl_fixed_amount += tax_amount;
+ cached_tax_amounts[i] = tax_amount;
+ }
+ if(store_included_tax_total){
+ total_included_checkpoints[i] = base;
+ store_included_tax_total = false;
+ }
}
- }
- i -= 1;
- });
+ i -= 1;
+ });
+ }
var total_excluded = round_pr(recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount), initial_currency_rounding);
var total_included = total_excluded;
@@ -2284,16 +2287,24 @@ exports.Orderline = Backbone.Model.extend({
if(order.fiscal_position) {
var taxes = this.get_taxes();
var mapped_included_taxes = [];
+ var new_included_taxes = [];
var self = this;
_(taxes).each(function(tax) {
var line_taxes = self._map_tax_fiscal_position(tax);
+ new_included_taxes = new_included_taxes.concat(line_taxes)
if(tax.price_include && !_.contains(line_taxes, tax)){
mapped_included_taxes.push(tax);
}
});
if (mapped_included_taxes.length > 0) {
- return this.compute_all(mapped_included_taxes, price, 1, order.pos.currency.rounding, true).total_excluded;
+ if (new_included_taxes.length > 0) {
+ var price_without_taxes = this.compute_all(mapped_included_taxes, price, 1, order.pos.currency.rounding, true).total_excluded
+ return this.compute_all(new_included_taxes, price_without_taxes, 1, order.pos.currency.rounding, false).total_included
+ }
+ else{
+ return this.compute_all(mapped_included_taxes, price, 1, order.pos.currency.rounding, true).total_excluded;
+ }
}
}
return price;