changeset 1c524d600eca in modules/sale_promotion_coupon:default
details:
https://hg.tryton.org/modules/sale_promotion_coupon?cmd=changeset;node=1c524d600eca
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
exceptions.py | 7 +++++++
message.xml | 10 ++++++++++
sale.py | 13 ++++++-------
tryton.cfg | 1 +
4 files changed, 24 insertions(+), 7 deletions(-)
diffs (77 lines):
diff -r f457df0e7b1b -r 1c524d600eca exceptions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py Sat Dec 29 14:20:29 2018 +0100
@@ -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 -r f457df0e7b1b -r 1c524d600eca message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 2018 +0100
@@ -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>
diff -r f457df0e7b1b -r 1c524d600eca sale.py
--- a/sale.py Mon Oct 01 15:17:48 2018 +0200
+++ b/sale.py Sat Dec 29 14:20:29 2018 +0100
@@ -4,6 +4,7 @@
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.tools import grouped_slice, reduce_ids
from trytond.transaction import Transaction
+from .exceptions import DuplicateError
+
__all__ = ['Promotion', 'PromotionCoupon', 'PromotionCouponNumber']
@@ -70,10 +73,6 @@
@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 @@
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 -r f457df0e7b1b -r 1c524d600eca tryton.cfg
--- a/tryton.cfg Mon Oct 01 15:17:48 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -6,3 +6,4 @@
sale_promotion
xml:
sale.xml
+ message.xml