Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
0300d6c208
commit
cd2e5bf7cd
4 files changed
+27
-13
No files matched your search
@@ -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
|
||||
+10
@@ -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>
|
||||
+8
-13
@@ -4,6 +4,7 @@ from decimal import Decimal
|
||||
|
||||
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.pyson import If, Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from .exceptions import FormulaError
|
||||
|
||||
__all__ = ['PriceList', 'PriceListLine']
|
||||
|
||||
|
||||
@@ -103,14 +106,6 @@ class PriceListLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
|
||||
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 @@ class PriceListLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
|
||||
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:
|
||||
|
||||
@@ -6,3 +6,4 @@ depends:
|
||||
product
|
||||
xml:
|
||||
price_list.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user