changeset 2178c2a96863 in modules/product_price_list:default
details: 
https://hg.tryton.org/modules/product_price_list?cmd=changeset;node=2178c2a96863
description:
        Add ir.message and use custom exceptions

        issue3672
diffstat:

 exceptions.py |   8 ++++++++
 message.xml   |  10 ++++++++++
 price_list.py |  21 ++++++++-------------
 tryton.cfg    |   1 +
 4 files changed, 27 insertions(+), 13 deletions(-)

diffs (86 lines):

diff -r bdbaa4c6b177 -r 2178c2a96863 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,8 @@
+# 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 FormulaError(ValidationError):
+    pass
diff -r bdbaa4c6b177 -r 2178c2a96863 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_invalid_formula">
+            <field name="text">Invalid formula "%(formula)s" in price list 
line "%(line)s" with exception "%(exception)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r bdbaa4c6b177 -r 2178c2a96863 price_list.py
--- a/price_list.py     Sun Nov 18 17:23:41 2018 +0100
+++ b/price_list.py     Sat Dec 29 14:20:29 2018 +0100
@@ -4,6 +4,7 @@
 
 from simpleeval import simple_eval
 
+from trytond.i18n import gettext
 from trytond.model import ModelView, ModelSQL, MatchMixin, fields, \
     sequence_ordered
 from trytond.tools import decistmt
@@ -11,6 +12,8 @@
 from trytond.transaction import Transaction
 from trytond.pool import Pool
 
+from .exceptions import FormulaError
+
 __all__ = ['PriceList', 'PriceListLine']
 
 
@@ -103,14 +106,6 @@
         help=('Python expression that will be evaluated with:\n'
             '- unit_price: the original unit_price'))
 
-    @classmethod
-    def __setup__(cls):
-        super(PriceListLine, cls).__setup__()
-        cls._error_messages.update({
-                'invalid_formula': ('Invalid formula "%(formula)s" in price '
-                    'list line "%(line)s" with exception "%(exception)s".'),
-                })
-
     @staticmethod
     def default_formula():
         return 'unit_price'
@@ -137,11 +132,11 @@
             if not isinstance(self.get_unit_price(**context), Decimal):
                 raise ValueError
         except Exception as exception:
-            self.raise_user_error('invalid_formula', {
-                    'formula': self.formula,
-                    'line': self.rec_name,
-                    'exception': exception,
-                    })
+            raise FormulaError(
+                gettext('product_price_list.msg_invalid_format',
+                    formula=self.formula,
+                    line=self.rec_name,
+                    exception=exception)) from exception
 
     def match(self, pattern):
         if 'quantity' in pattern:
diff -r bdbaa4c6b177 -r 2178c2a96863 tryton.cfg
--- a/tryton.cfg        Sun Nov 18 17:23:41 2018 +0100
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -6,3 +6,4 @@
     product
 xml:
     price_list.xml
+    message.xml

Reply via email to