[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:
Romain Derie
2017-11-15 12:34:57 +01:00
parent bb5d999596
commit 16531f6548
+3 -1
View File
@@ -19,6 +19,8 @@ class SaleCouponApplyCode(models.TransientModel):
error_status = self.apply_coupon(sales_order, self.coupon_code)
if error_status.get('error', False):
raise UserError(error_status.get('error', False))
if error_status.get('not_found', False):
raise UserError(error_status.get('not_found', False))
def apply_coupon(self, order, coupon_code):
error_status = {}
@@ -46,5 +48,5 @@ class SaleCouponApplyCode(models.TransientModel):
order.applied_coupon_ids += coupon
coupon.write({'state': 'used'})
else:
error_status = {'error': _('The code %s is invalid') % (coupon_code)}
error_status = {'not_found': _('The code %s is invalid') % (coupon_code)}
return error_status