Before this commit: Coupon error on cart would always show "Invalid or Expired coupon code" instead of a more accurate error (eg: already applied, can't use 2 code..). Plus it would still show the error on page refresh because of the error being stored in URL param. Now: It will show the exact error and since the error is not stored in URL, it won't be still displayed on page refresh. This closes #1601
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import http
|
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
|
from odoo.http import request
|
|
|
|
|
|
class WebsiteSale(WebsiteSale):
|
|
|
|
@http.route(['/shop/pricelist'])
|
|
def pricelist(self, promo, **post):
|
|
order = request.website.sale_get_order()
|
|
coupon_status = request.env['sale.coupon.apply.code'].sudo().apply_coupon(order, promo)
|
|
if coupon_status.get('not_found'):
|
|
return super(WebsiteSale, self).pricelist(promo, **post)
|
|
elif coupon_status.get('error'):
|
|
request.session['error_promo_code'] = coupon_status['error']
|
|
return request.redirect(post.get('r', '/shop/cart'))
|
|
|
|
@http.route(['/shop/payment'], type='http', auth="public", website=True)
|
|
def payment(self, **post):
|
|
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)
|