From 7c95c14c06d77e5ebbd7aafd9c0c345b47d27d30 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Mon, 27 Mar 2017 16:25:13 +0200 Subject: [PATCH] [FIX] website_sale: apply _fix_tax_included_price similary to sale module If you had a price with a tax included and the user has fiscal position. The tax included in the unit price was not substract before the mapping. Eg: product $115 with tin 15% included in price. Once in the cart with a fiscal position intracom (0% tva), the unit price should be 100$ and not 115$. This commit closes #16022 --- addons/sale/models/sale.py | 1 + addons/website_sale/models/sale_order.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 4d886bed176..dda33048a23 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -813,6 +813,7 @@ class SaleOrderLine(models.Model): @api.multi def _get_display_price(self, product): + # TO DO: move me in master/saas-16 on sale.order if self.order_id.pricelist_id.discount_policy == 'without_discount': from_currency = self.order_id.company_id.currency_id return from_currency.compute(product.lst_price, self.order_id.pricelist_id.currency_id) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index a0fe0e707e7..0d277be82ff 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -68,12 +68,18 @@ class SaleOrder(models.Model): }) product = self.env['product.product'].with_context(product_context).browse(product_id) + pu = product.price + if order.pricelist_id and order.partner_id: + order_line = order._cart_find_product_line(product.id) + if order_line: + pu = self.env['account.tax']._fix_tax_included_price(order_line._get_display_price(product), product.taxes_id, order_line.tax_id) + return { 'product_id': product_id, 'product_uom_qty': qty, 'order_id': order_id, 'product_uom': product.uom_id.id, - 'price_unit': product.price, + 'price_unit': pu, } @api.multi @@ -144,10 +150,12 @@ class SaleOrder(models.Model): # update line values = self._website_product_id_change(self.id, product_id, qty=quantity) - - if self.pricelist_id.discount_policy == 'with_discount' and not self.env.context.get('fixed_price'): - values['price_unit'] = order_line._get_display_price(order_line.product_id) + values['price_unit'] = self.env['account.tax']._fix_tax_included_price( + order_line._get_display_price(order_line.product_id), + order_line.product_id.taxes_id, + order_line.tax_id + ) order_line.write(values)