From 703295aaed249487144f7b25add46896998f8598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Dec 2018 14:20:28 +0100 Subject: [PATCH] Add ir.message and use custom exceptions issue3672 --- exceptions.py | 7 +++++++ message.xml | 10 ++++++++++ reporting_tax.py | 14 +++++--------- tryton.cfg | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 exceptions.py create mode 100644 message.xml diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..b9deaeff0e --- /dev/null +++ b/exceptions.py @@ -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 --git a/message.xml b/message.xml new file mode 100644 index 0000000000..a6c9be4ea9 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + To generate the report the periods must be in the same fiscal year. + + + diff --git a/reporting_tax.py b/reporting_tax.py index 0a7ca8ea19..793619a11f 100644 --- a/reporting_tax.py +++ b/reporting_tax.py @@ -9,6 +9,7 @@ from sql.aggregate import Count 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.transaction import Transaction from trytond.wizard import Wizard, StateView, StateTransition, StateReport, \ Button +from .exceptions import PrintError + __all__ = ['AEAT111', 'AEAT115', 'AEAT303', 'PrintAEATStart', 'PrintAEAT'] @@ -309,14 +312,6 @@ class PrintAEAT(Wizard): 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 @@ class PrintAEAT(Wizard): 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 --git a/tryton.cfg b/tryton.cfg index 0be6a9b35d..3169a28aa2 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -12,3 +12,4 @@ xml: tax_pyme.xml view.xml reporting_tax.xml + message.xml