From 658f3102235869943c6722d6eefbd6bdf26d8010 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 14 Nov 2014 17:31:21 +0100 Subject: [PATCH] [IMP] barcodes: more specific ValidationError messages in pattern constraint --- addons/barcodes/barcodes.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/barcodes/barcodes.py b/addons/barcodes/barcodes.py index 53be165c84b..ff0613d355b 100644 --- a/addons/barcodes/barcodes.py +++ b/addons/barcodes/barcodes.py @@ -183,8 +183,10 @@ class barcode_rule(models.Model): def _check_pattern(self): p = self.pattern.replace("\\\\", "X").replace("\{", "X").replace("\}", "X") findall = re.findall("[{]|[}]", p) # p does not contain escaped { or } - if len(findall) == 2: - if not re.search("[{][N]*[D]*[}]", p) or re.search("[{][}]", p): - raise ValidationError(_("There is a syntax error in the barcode pattern") + " %s." % self.pattern) + if len(findall) == 2: + if not re.search("[{][N]*[D]*[}]", p): + raise ValidationError(_("There is a syntax error in the barcode pattern ") + self.pattern + _(": braces can only contain N's followed by D's.")) + elif re.search("[{][}]", p): + raise ValidationError(_("There is a syntax error in the barcode pattern ") + self.pattern + _(": empty braces.")) elif len(findall) != 0: - raise ValidationError(_("There is a syntax error in the barcode pattern") + " %s." % self.pattern) \ No newline at end of file + raise ValidationError(_("There is a syntax error in the barcode pattern ") + self.pattern + _(": a rule can only contain one pair of braces.")) \ No newline at end of file