From 1bd44e1106d02812aa8866ddc2835ac0f4ee200f Mon Sep 17 00:00:00 2001 From: rde Date: Tue, 31 Oct 2017 17:57:38 +0100 Subject: [PATCH] [FIX] website_sale_coupon: update reward line total when changing product qty on cart - Add a product (imac 1.799$) and a promo code (eg: 10%) in your cart - Go to checkout (/shop/cart). You now see 1,619.10 Total and 179.90 discount - Change product qty (eg: 2) - Subtotal is now 2x 1.799 - 179.90 instead of 2x 1.799 - 2x 179.90 - Reward line total (discount) is still the same amount (10% on 1 ipad) Now, we will recompute the discount price based on the entire cart Note: This behavior was wanted and comes from this commit #87d542 But for the shop, we need to have the reward line being updated on the fly or it wont make sense for the end user. This closes #ee4be7a532dd707a0cd19c766dc8e8537dcda242 --- controllers/main.py | 6 ++++++ models/__init__.py | 3 ++- models/website.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 models/website.py diff --git a/controllers/main.py b/controllers/main.py index 3a589ac2979..c818db4640f 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -19,3 +19,9 @@ class WebsiteSale(WebsiteSale): order = request.website.sale_get_order() order.recompute_coupon_lines() return super(WebsiteSale, self).payment(**post) + + @http.route(['/shop/cart'], type='http', auth="public", website=True) + def cart(self, **post): + order = request.website.sale_get_order() + order.recompute_coupon_lines() + return super(WebsiteSale, self).cart(**post) diff --git a/models/__init__.py b/models/__init__.py index bdc919f5eec..1cc49f34af5 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -2,4 +2,5 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import sale_coupon_rule -import sale_order \ No newline at end of file +import sale_order +import website diff --git a/models/website.py b/models/website.py new file mode 100644 index 00000000000..37f93c7f64b --- /dev/null +++ b/models/website.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, api + + +class Website(models.Model): + _inherit = "website" + + @api.multi + def sale_get_order(self, force_create=False, code=None, update_pricelist=False, force_pricelist=False): + order = super(Website, self).sale_get_order(force_create, code, update_pricelist, force_pricelist) + order.recompute_coupon_lines() + return order