[FIX] (website_)sale_coupon: Display clearer promo code error on cart
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
This commit is contained in:
+3
-1
@@ -10,8 +10,10 @@ class WebsiteSale(WebsiteSale):
|
||||
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('error', False):
|
||||
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)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
@@ -10,3 +11,9 @@ class SaleOrder(models.Model):
|
||||
for order in self:
|
||||
reward_lines = order.website_order_line.filtered(lambda line: line.is_reward_line)
|
||||
order.cart_quantity -= int(sum(reward_lines.mapped('product_uom_qty')))
|
||||
|
||||
def get_promo_code_error(self, delete=True):
|
||||
error = request.session.get('error_promo_code')
|
||||
if error and delete:
|
||||
request.session.pop('error_promo_code')
|
||||
return error
|
||||
|
||||
@@ -47,6 +47,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-if="website_sale_order.get_promo_code_error(delete=False)">
|
||||
<div class="panel panel-danger mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left"><t t-esc="website_sale_order.get_promo_code_error()" /></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
<xpath expr="//t[@name='code_not_available']" position="replace"/>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user