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

        issue3672
diffstat:

 exceptions.py    |   7 +++++++
 message.xml      |  10 ++++++++++
 reporting_tax.py |  14 +++++---------
 tryton.cfg       |   1 +
 4 files changed, 23 insertions(+), 9 deletions(-)

diffs (75 lines):

diff -r 39c584eab6e2 -r bcfec489b24a exceptions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py     Sat Dec 29 14:20:28 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 PrintError(ValidationError):
+    pass
diff -r 39c584eab6e2 -r bcfec489b24a message.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml       Sat Dec 29 14:20:28 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_report_same_fiscalyear">
+            <field name="text">To generate the report the periods must be in 
the same fiscal year.</field>
+        </record>
+    </data>
+</tryton>
diff -r 39c584eab6e2 -r bcfec489b24a reporting_tax.py
--- a/reporting_tax.py  Wed Oct 31 18:17:35 2018 +0100
+++ b/reporting_tax.py  Sat Dec 29 14:20:28 2018 +0100
@@ -9,6 +9,7 @@
 from sql.conditionals import Case
 from sql.functions import Substring, Position
 
+from trytond.i18n import gettext
 from trytond.model import ModelView, fields
 from trytond.model.modelsql import convert_from
 from trytond.pool import Pool
@@ -17,6 +18,8 @@
 from trytond.wizard import Wizard, StateView, StateTransition, StateReport, \
     Button
 
+from .exceptions import PrintError
+
 __all__ = ['AEAT111', 'AEAT115', 'AEAT303', 'PrintAEATStart', 'PrintAEAT']
 
 
@@ -309,14 +312,6 @@
     model_115 = StateReport('account.reporting.aeat115')
     model_303 = StateReport('account.reporting.aeat303')
 
-    @classmethod
-    def __setup__(cls):
-        super().__setup__()
-        cls._error_messages.update({
-                'same_fiscalyear': ("Periods should be of the same fiscalyear "
-                    "to generate the report."),
-                })
-
     def transition_choice(self):
         validate = getattr(self, 'validate_%s' % self.start.report, None)
         if validate:
@@ -332,4 +327,5 @@
 
     def validate_303(self):
         if len(set(p.fiscalyear for p in self.start.periods)) > 1:
-            self.raise_user_error('same_fiscalyear')
+            raise PrintError(
+                gettext('account_es.msg_report_same_fiscalyear'))
diff -r 39c584eab6e2 -r bcfec489b24a tryton.cfg
--- a/tryton.cfg        Wed Oct 31 18:17:35 2018 +0100
+++ b/tryton.cfg        Sat Dec 29 14:20:28 2018 +0100
@@ -12,3 +12,4 @@
     tax_pyme.xml
     view.xml
     reporting_tax.xml
+    message.xml

Reply via email to