diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..ed877fb1b8 --- /dev/null +++ b/exceptions.py @@ -0,0 +1,7 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.model.exceptions import ValidationError + + +class DuplicateError(ValidationError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..c7e4741e03 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + The coupons numbered "%(numbers)s" are duplicated. + + + diff --git a/sale.py b/sale.py index e9aacd8377..f584705320 100644 --- a/sale.py +++ b/sale.py @@ -4,6 +4,7 @@ from sql import Literal from sql.aggregate import Count from sql.conditionals import Case, Coalesce +from trytond.i18n import gettext from trytond.model import ( ModelSQL, ModelView, Workflow, fields, DeactivableMixin) from trytond.pool import PoolMeta, Pool @@ -11,6 +12,8 @@ from trytond.pyson import Eval from trytond.tools import grouped_slice, reduce_ids from trytond.transaction import Transaction +from .exceptions import DuplicateError + __all__ = ['Promotion', 'PromotionCoupon', 'PromotionCouponNumber'] @@ -70,10 +73,6 @@ class PromotionCouponNumber(DeactivableMixin, ModelSQL, ModelView): @classmethod def __setup__(cls): super(PromotionCouponNumber, cls).__setup__() - cls._error_messages.update({ - 'duplicate_numbers': ( - "The coupon numbered '%(numbers)s' are duplicated."), - }) cls.active = fields.Function( fields.Boolean("Active"), 'get_active', searcher='search_active') @@ -189,9 +188,9 @@ class PromotionCouponNumber(DeactivableMixin, ModelSQL, ModelView): numbers = ', '.join(n.number for n in duplicates[:5]) if len(duplicates) > 5: numbers += '...' - cls.raise_user_error('duplicate_numbers', { - 'numbers': numbers, - }) + raise DuplicateError( + gettext('sale_promotion_coupon.msg_duplicate_numbers', + numbers=numbers)) class Sale(metaclass=PoolMeta): diff --git a/tryton.cfg b/tryton.cfg index 010f88c194..2c6e630d35 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,3 +6,4 @@ depends: sale_promotion xml: sale.xml + message.xml