[IMP] website_sale: B2B-B2C - display price with or without taxes.
Allow to display price on the website tax included or not. Price for product is computed with a new function display_price which one compute an estimated price based on taxex and fiscal position of the current partner for the current product. Once the product is in the cart, it is the behaviour of previous commit odoo/odoo@5f5f8d8 which is used to diplay price with or without taxes.
This commit is contained in:
@@ -14,17 +14,15 @@
|
||||
</record>
|
||||
|
||||
<record id="group_show_price_subtotal" model="res.groups">
|
||||
<field name="name">Show subtotal</field>
|
||||
<field name="name">Tax display B2B</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
<field name="comment">
|
||||
Only included taxes in the subtotal that are already included in the unit price.
|
||||
</field>
|
||||
<field name="comment">Show line subtotals without taxes (B2B)</field>
|
||||
</record>
|
||||
|
||||
<record id="group_show_price_total" model="res.groups">
|
||||
<field name="name">Show total (tax inc)</field>
|
||||
<field name="name">Tax display B2C</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
<field name="comment">Display the total of the line with all taxes included</field>
|
||||
<field name="comment">Show line subtotals with taxes included (B2C)</field>
|
||||
</record>
|
||||
|
||||
<record id="group_mrp_properties" model="res.groups">
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -94,22 +94,14 @@
|
||||
<h5><strong><a itemprop="name" t-att-href="keep('/shop/product/%s' % slug(product), page=(pager['page']['num'] if pager['page']['num']>1 else None))" t-field="product.name"/></strong></h5>
|
||||
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price" t-if="product.product_variant_ids">
|
||||
<b>
|
||||
<t t-if="(compute_currency(product.lst_price) - product.price) > 0.1">
|
||||
<del class="text-danger mr8" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": product.currency_id,
|
||||
"display_currency": website.currency_id
|
||||
}'/>
|
||||
<t t-if="(compute_currency(product.lst_price) - product.price ) > 0.1">
|
||||
<del class="text-danger mr8" style="white-space: nowrap;" t-esc="format(compute_currency(request.website.get_product_price(product, public=True)), 'monetary', website.get_current_pricelist().currency_id, website.currency_id)"/>
|
||||
</t>
|
||||
<span t-field="product.price" style="white-space: nowrap;" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": website.currency_id
|
||||
}'>
|
||||
</span>
|
||||
<span t-esc="format(request.website.get_product_price(product), 'monetary', website.currency_id)"/>
|
||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>
|
||||
</b>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</form>
|
||||
@@ -373,7 +365,7 @@
|
||||
|
||||
<form t-att-action="keep('/shop/cart/update')" class="js_add_cart_variants" t-att-data-attribute_value_ids="product.product_variant_ids.ids" method="POST">
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
<div class="js_product">
|
||||
<div class="js_product" t-if="product.product_variant_ids">
|
||||
<t t-placeholder="select">
|
||||
<input type="hidden" class="product_id" name="product_id" t-att-value="int(product.product_variant_ids[0]) if len(product.product_variant_ids) == 1 else '0'"/>
|
||||
<t t-call="website_sale.variants">
|
||||
@@ -434,22 +426,14 @@
|
||||
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
|
||||
<h4 class="oe_price_h4 css_editable_mode_hidden">
|
||||
<span class="text-danger oe_default_price" style="text-decoration: line-through; white-space: nowrap;"
|
||||
t-field="product.lst_price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": product.currency_id,
|
||||
"display_currency": website.currency_id
|
||||
}'/>
|
||||
<b class="oe_price" style="white-space: nowrap;"
|
||||
t-field="product.price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": website.currency_id
|
||||
}'/>
|
||||
t-esc="format(compute_currency(request.website.get_product_price(product, public=True)), 'monetary', website.get_current_pricelist().currency_id, website.currency_id)"
|
||||
/>
|
||||
<b class="oe_price" style="white-space: nowrap;" t-esc="format(request.website.get_product_price(product), 'monetary', website.currency_id)"/>
|
||||
<span itemprop="price" style="display:none;" t-esc="product.price"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>
|
||||
</h4>
|
||||
<h4 class="css_non_editable_mode_hidden">
|
||||
<!-- keep field for editor -->
|
||||
<span t-field="product.lst_price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
@@ -790,16 +774,20 @@
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center" id="td-price" name="price">
|
||||
<del t-attf-class="text-danger #{'' if line.product_id.lst_price > line.price_reduce else 'hidden'}" style="text-decoration: line-through; white-space: nowrap;"
|
||||
t-field="line.product_id.lst_price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": line.company_id.currency_id,
|
||||
"display_currency": website.currency_id
|
||||
}'/>
|
||||
<span t-field="line.price_reduce" style="white-space: nowrap;" t-field-options='{
|
||||
<t t-if="(compute_currency(line.product_id.lst_price) - line.price_reduce ) > 0.1">
|
||||
<del class="text-danger mr8" style="white-space: nowrap;"
|
||||
t-esc="format(compute_currency(website.get_product_price(line.product_id, public=True)), 'monetary', website.get_current_pricelist().currency_id, website.currency_id)"/>
|
||||
</t>
|
||||
<span t-field="line.price_reduce_taxexcl" style="white-space: nowrap;" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": line.company_id.currency_id,
|
||||
"display_currency": website.currency_id
|
||||
}'/>
|
||||
}' groups="sale.group_show_price_subtotal"/>
|
||||
<span t-field="line.price_reduce_taxinc" style="white-space: nowrap;" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": line.company_id.currency_id,
|
||||
"display_currency": website.currency_id
|
||||
}' groups="sale.group_show_price_total"/>
|
||||
</td>
|
||||
</tr>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user