[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.

A not stored computed field is added in model "sale.order.line"
to compute the discounted price because when the module
product_visible_discount is installed the price unit of a SO line
is the full price of the product and the discount related to the pricelist
is written in percent in the field discount(function "product_id_change"
in addons/product_visible_discount/product_visible_discount.py).

opw:660178
This commit is contained in:
Goffin Simon 2015-12-21 15:23:46 +01:00
parent 7c0e734785
commit a617fd29ae
3 changed files with 18 additions and 4 deletions

View File

@ -2,6 +2,7 @@
import random
from openerp import SUPERUSER_ID
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 _
@ -113,6 +114,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'

View File

@ -29,9 +29,9 @@ $('.oe_website_sale').each(function () {
$(oe_website_sale).on("change", 'input[name="add_qty"]', function (event) {
product_ids = [];
var product_dom = $(".js_add_cart_variants[data-attribute_value_ids]").first();
var product_dom = $(".js_product .js_add_cart_variants[data-attribute_value_ids]").last();
product_dom.data("attribute_value_ids").forEach(function(entry) {
product_ids.push(entry);});
product_ids.push(entry[0]);});
var qty = $(event.target).closest('form').find('input[name="add_qty"]').val();
openerp.jsonRpc("/shop/get_unit_price", 'call', {'product_ids': product_ids,'add_qty': parseInt(qty)})

View File

@ -684,13 +684,13 @@
<div class="text-muted" t-esc="'\n'.join(line.name.splitlines()[1:])"/>
</td>
<td class="text-center" name="price">
<del class="text-danger" t-att-style="'' if (compute_currency(line.product_id.lst_price) - line.price_unit) &gt; 1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
<del class="text-danger" t-att-style="'' if line.product_id.lst_price &gt; line.discounted_price else 'display: none;'" 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": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
<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",
"from_currency": "website_sale_order.pricelist_id.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"