Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:28 +01:00
parent 24eb88814f
commit 703295aaed
4 changed files with 23 additions and 9 deletions
+7
View File
@@ -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
+10
View File
@@ -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>
+5 -9
View File
@@ -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'))
+1
View File
@@ -12,3 +12,4 @@ xml:
tax_pyme.xml
view.xml
reporting_tax.xml
message.xml