From 4c6b47450547acffcdd12b78891d88690f6c4f7b Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 2 Jan 2018 12:01:21 +0100 Subject: [PATCH] [FIX] sale_coupon: min quantity set to 0 will crash backend and shop Before this commit, if minimum product quantity was set to 0 on a coupon program, it would then throw: - On backend, when updating promotions - On frontend (shop), user won't access his cart (error 500) Now, we prevent quantity from being lower than 1 Step to reproduce: - Create a coupon automatically applied, set quantity to 0, set reward to 'Free Product' and set free product to iPad Mini - Go to /shop and add a iPad Mini to your cart, it will throw an error 500 instead of redirecting to your cart - Go to backend, click on 'Update Promotions' on a quotation, it will show an error popup --- models/sale_coupon_rules.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/sale_coupon_rules.py b/models/sale_coupon_rules.py index 6495b6421b2..2f08de46b15 100644 --- a/models/sale_coupon_rules.py +++ b/models/sale_coupon_rules.py @@ -36,6 +36,11 @@ class SaleCouponRule(models.Model): if self.filtered(lambda applicability: applicability.rule_minimum_amount < 0): raise ValidationError(_('Minimum purchased amount should be greater than 0')) + @api.constrains('rule_min_quantity') + def _check_rule_min_quantity(self): + if not self.rule_min_quantity > 0: + raise ValidationError(_('Minimum quantity should be greater than 0')) + # YTI TODO Remove in master def _compute_rule_partner_ids(self): pass