From a617fd29ae318e5c8f6a728dede77b1f170b3553 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 21 Dec 2015 15:23:46 +0100 Subject: [PATCH] [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 --- addons/website_sale/models/sale_order.py | 14 ++++++++++++++ addons/website_sale/static/src/js/website_sale.js | 4 ++-- addons/website_sale/views/templates.xml | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 8cc155b43a0..e5815b886b9 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -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' diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 11f7aec7365..b72df30c67f 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -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)}) diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 8d258e3f249..e46fd2bb295 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -684,13 +684,13 @@
-   -