diff --git a/addons/sale/security/sale_security.xml b/addons/sale/security/sale_security.xml index 1c3c4c5fa69..2bb41b4fb5b 100644 --- a/addons/sale/security/sale_security.xml +++ b/addons/sale/security/sale_security.xml @@ -14,17 +14,15 @@ - Show subtotal + Tax display B2B - - Only included taxes in the subtotal that are already included in the unit price. - + Show line subtotals without taxes (B2B) - Show total (tax inc) + Tax display B2C - Display the total of the line with all taxes included + Show line subtotals with taxes included (B2C) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index c82a16abf80..7b51e3c3987 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -111,15 +111,16 @@ class WebsiteSale(http.Controller): """ # product attributes with at least two choices visible_attrs_ids = product.mapped('attribute_line_ids.attribute_id').filtered(lambda attr: len(attr.value_ids) > 1).ids - to_currency = request.website.get_current_pricelist().currency_id + pl = request.website.get_current_pricelist() + to_currency = pl.currency_id attribute_value_ids = [] for variant in product.product_variant_ids: if to_currency != product.currency_id: - price = variant.currency_id.compute(variant.lst_price, to_currency) + price = variant.currency_id.compute(variant.display_price(pl, public=True), to_currency) else: - price = variant.lst_price + price = variant.display_price(pl, public=True) visible_attribute_ids = [v.id for v in variant.attribute_value_ids if v.attribute_id.id in visible_attrs_ids] - attribute_value_ids.append([variant.id, visible_attribute_ids, variant.price, price]) + attribute_value_ids.append([variant.id, visible_attribute_ids, variant.display_price(pl), price]) return attribute_value_ids def _get_search_order(self, post): @@ -976,9 +977,6 @@ class WebsiteSale(http.Controller): return ret @http.route(['/shop/get_unit_price'], type='json', auth="public", methods=['POST'], website=True) - def get_unit_price(self, product_ids, add_qty, use_order_pricelist=False, **kw): + def get_unit_price(self, product_ids, add_qty, **kw): products = request.env['product.product'].browse(product_ids) - partner = request.env.user.partner_id - pricelist = request.website.get_current_pricelist() - prices = pricelist.price_rule_get_multi([(product, add_qty, partner) for product in products]) - return {product_id: prices[product_id][pricelist.id][0] for product_id in product_ids} + return {product.id: request.website.get_product_price(product, qty=add_qty) / add_qty for product in products} diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 3046d24dd8c..835b1dbfc68 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -132,6 +132,11 @@ class ProductTemplate(models.Model): res[product.id] = "/shop/product/%s" % (product.id,) return res + @api.multi + def display_price(self, pricelist, qty=1, public=False, **kw): + self.ensure_one() + return self.product_variant_ids and self.product_variant_ids[0].display_price(pricelist, qty=qty, public=public) or 0 + class Product(models.Model): _inherit = "product.product" @@ -141,6 +146,19 @@ class Product(models.Model): self.ensure_one() return self.product_tmpl_id.website_publish_button() + @api.multi + def display_price(self, pricelist, qty=1, public=False, **kw): + self.ensure_one() + partner = self.env.user.partner_id + context = { + 'pricelist': pricelist.id, + 'quantity': qty, + 'partner': partner + } + ret = self.env.user.has_group('sale.group_show_price_subtotal') and 'total_excluded' or 'total_included' + taxes = partner.property_account_position_id.map_tax(self.taxes_id) + return taxes.compute_all(public and self.lst_price or self.with_context(context).price, pricelist.currency_id, qty, product=self, partner=partner)[ret] + class ProductAttribute(models.Model): _inherit = "product.attribute" diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 80ffe0ef73f..43466aad160 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -6,10 +6,10 @@ import random from odoo import api, models, fields, tools, _ from odoo.http import request from odoo.exceptions import UserError -import odoo.addons.decimal_precision as dp _logger = logging.getLogger(__name__) + class SaleOrder(models.Model): _inherit = "sale.order" @@ -373,6 +373,11 @@ class Website(models.Model): 'website_sale_current_pl': False, }) + @api.model + def get_product_price(self, product, qty=1, public=False, **kw): + pricelist = request.website.get_current_pricelist() + return product.display_price(pricelist, qty=qty, public=public) + class WebsitePricelist(models.Model): _name = 'website_pricelist' diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 93d238222c5..24b8aebd148 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -94,22 +94,14 @@
- - + + - - + -
+ @@ -373,7 +365,7 @@
-
+
@@ -434,22 +426,14 @@

- + t-esc="format(compute_currency(request.website.get_product_price(product, public=True)), 'monetary', website.get_current_pricelist().currency_id, website.currency_id)" + /> +

+ - + + + }' groups="sale.group_show_price_subtotal"/> +