[FIX] website_sale: discount display in e-commerce

Each time the quantity of a product is changed, the price must
be updated according to the pricelist of the user.
When the price given by the pricelist is less then the unit price
of the product, the reduction of the price must be displayed.

opw:660178
This commit is contained in:
Goffin Simon
2015-12-23 16:57:49 +01:00
parent 24eee9d7ba
commit 045a859414
3 changed files with 22 additions and 4 deletions
+14
View File
@@ -3,6 +3,7 @@ import random
import openerp
from openerp import SUPERUSER_ID, tools
import openerp.addons.decimal_precision as dp
from openerp.osv import osv, orm, fields
from openerp.addons.web.http import request
from openerp.tools.translate import _
@@ -119,6 +120,19 @@ class sale_order(osv.Model):
product_ids = random.sample(s, min(len(s), 3))
return self.pool['product.product'].browse(cr, uid, product_ids, context=context)
class sale_order_line(osv.Model):
_inherit = "sale.order.line"
def _fnct_get_discounted_price(self, cr, uid, ids, field_name, args, context=None):
res = dict.fromkeys(ids, False)
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = (line.price_unit * (1.0 - (line.discount or 0.0) / 100.0))
return res
_columns = {
'discounted_price': fields.function(_fnct_get_discounted_price, string='Discounted price', type='float', digits_compute=dp.get_precision('Product Price')),
}
class website(orm.Model):
_inherit = 'website'
@@ -101,12 +101,12 @@ $('.oe_website_sale').each(function () {
$(oe_website_sale).on("change", 'input[name="add_qty"]', function (event) {
var product_ids = [];
var product_dom = $(".js_add_cart_variants[data-attribute_value_ids]").first();
var product_dom = $(".js_add_cart_variants[data-attribute_value_ids]").last();
if (!product_dom.length) {
return;
}
_.each(product_dom.data("attribute_value_ids"), function(entry) {
product_ids.push(entry);});
product_ids.push(entry[0]);});
var qty = $(event.target).closest('form').find('input[name="add_qty"]').val();
if ($("#product_detail").length) {
+6 -2
View File
@@ -448,6 +448,10 @@
<template id="product_variants" inherit_id="website_sale.product" active="False" customize_show="True" name="List View of Variants">
<xpath expr="//t[@t-placeholder='select']" position="replace">
<input type="hidden" t-if="len(product.product_variant_ids) == 1" name="product_id" t-att-value="product.product_variant_ids[0].id"/>
<t t-debug="pudb"/>
<t t-call="website_sale.variants">
<t t-set="ul_class" t-value="'nav-stacked'"/>
</t>
<t t-if="len(product.product_variant_ids) &gt; 1">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="variant_id">
<input type="radio" name="product_id" class="js_product_change" t-att-checked="'checked' if variant_id_index == 0 else ''" t-att-value="variant_id.id" t-att-data-lst_price="variant_id.lst_price" t-att-data-price="variant_id.price"/>
@@ -772,13 +776,13 @@
</div>
</td>
<td class="text-center" id="td-price" name="price">
<del t-attf-class="text-danger #{'' if (compute_currency(line.product_id.lst_price) - line.price_unit) &gt; 0.1 else 'hidden'}" style="text-decoration: line-through; white-space: nowrap;"
<del t-attf-class="text-danger #{'' if line.product_id.lst_price &gt; line.discounted_price 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_unit" style="white-space: nowrap;" t-field-options='{
<span t-field="line.discounted_price" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "website.currency_id"
}'/>