From 16531f6548fb9b1b03215dcfee9922ab5c23e7cf Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 13 Nov 2017 12:43:03 +0100 Subject: [PATCH] [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 --- wizard/sale_coupon_apply_code.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wizard/sale_coupon_apply_code.py b/wizard/sale_coupon_apply_code.py index fa109b7511b..c3099062e78 100644 --- a/wizard/sale_coupon_apply_code.py +++ b/wizard/sale_coupon_apply_code.py @@ -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