From 5b502841276dda0dbc0161fd0fa080d1790086bb Mon Sep 17 00:00:00 2001
From: Goffin Simon <sig@odoo.com>
Date: Tue, 18 Apr 2017 12:00:14 +0200
Subject: [PATCH] [FIX] point_of_sale: fiscal position with included taxes in
 POS

To substract the included tax from the unit price when it's mapped
by a fiscal position in the POS.

To keep the same behavior introduced by this commit odoo@503820a

opw:710437
---
 addons/point_of_sale/static/src/js/models.js | 32 ++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index fc9a877f3b97..b0abc797f08e 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -1345,7 +1345,7 @@ exports.Orderline = Backbone.Model.extend({
         }
         return false;
     },
-    compute_all: function(taxes, price_unit, quantity, currency_rounding) {
+    compute_all: function(taxes, price_unit, quantity, currency_rounding, no_map_tax) {
         var self = this;
         var list_taxes = [];
         var currency_rounding_bak = currency_rounding;
@@ -1356,7 +1356,9 @@ exports.Orderline = Backbone.Model.extend({
         var total_included = total_excluded;
         var base = total_excluded;
         _(taxes).each(function(tax) {
-            tax = self._map_tax_fiscal_position(tax);
+            if (!no_map_tax){
+                tax = self._map_tax_fiscal_position(tax);
+            }
             if (tax.amount_type === 'group'){
                 var ret = self.compute_all(tax.children_tax_ids, price_unit, quantity, currency_rounding);
                 total_excluded = ret.total_excluded;
@@ -1813,6 +1815,27 @@ exports.Order = Backbone.Model.extend({
         this.orderlines.remove(line);
         this.select_orderline(this.get_last_orderline());
     },
+
+    fix_tax_included_price: function(line){
+        if(this.fiscal_position){
+            var unit_price = line.price;
+            var taxes = line.get_taxes();
+            var mapped_included_taxes = [];
+            _(taxes).each(function(tax) {
+                var line_tax = line._map_tax_fiscal_position(tax);
+                if(tax.price_include && tax.id != line_tax.id){
+
+                    mapped_included_taxes.push(tax);
+                }
+            })
+
+            unit_price = line.compute_all(mapped_included_taxes, unit_price, 1, this.pos.currency.rounding, true).total_excluded;
+
+            line.set_unit_price(unit_price);
+        }
+
+    },
+
     add_product: function(product, options){
         if(this._printed){
             this.destroy();
@@ -1828,9 +1851,14 @@ exports.Order = Backbone.Model.extend({
         if(options.quantity !== undefined){
             line.set_quantity(options.quantity);
         }
+
         if(options.price !== undefined){
             line.set_unit_price(options.price);
         }
+
+        //To substract from the unit price the included taxes mapped by the fiscal position
+        this.fix_tax_included_price(line);
+
         if(options.discount !== undefined){
             line.set_discount(options.discount);
         }
-- 
GitLab