From 045a8594144d1a759dae1f5d11e7814bb8f98434 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 21 Dec 2015 21:53:04 +0100 Subject: [PATCH 01/55] [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 --- addons/website_sale/models/sale_order.py | 14 ++++++++++++++ addons/website_sale/static/src/js/website_sale.js | 4 ++-- addons/website_sale/views/templates.xml | 8 ++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index eea8f01aa32..b847cd5a9dd 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -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' diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index c844adce2fc..18b47dfe285 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -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) { diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index bdf5e019415..28af2f2ca8d 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -448,6 +448,10 @@