Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:29 +01:00
parent 977ed7346a
commit bb0d53bf08
4 changed files with 24 additions and 7 deletions
+7
View File
@@ -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
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data group="1">
<record model="ir.message" id="msg_duplicate_numbers">
<field name="text">The coupons numbered "%(numbers)s" are duplicated.</field>
</record>
</data>
</tryton>
+6 -7
View File
@@ -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):
+1
View File
@@ -6,3 +6,4 @@ depends:
sale_promotion
xml:
sale.xml
message.xml