From a065ebb2b78a8f9fb27428cde87fbaf2f161d923 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 --- account.py | 27 +++++++++++++-------------- exceptions.py | 8 ++++++++ message.xml | 16 ++++++++++++++++ tryton.cfg | 1 + 4 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 exceptions.py create mode 100644 message.xml diff --git a/account.py b/account.py index 163c2771ae..f9e5173313 100644 --- a/account.py +++ b/account.py @@ -6,14 +6,18 @@ import logging import requests +from trytond.i18n import gettext from trytond.config import config from trytond.model import ModelSQL, ModelView, Workflow, Unique, fields +from trytond.model.exceptions import AccessError from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval, Bool, If from trytond.transaction import Transaction from trytond.modules.company.model import CompanyValueMixin +from .exceptions import InvoiceChorusValidationError + CERT = ( config.get('account_fr_chorus', 'certificate'), config.get('account_fr_chorus', 'privatekey')) @@ -137,16 +141,9 @@ class InvoiceChorus(ModelSQL, ModelView, _SyntaxMixin, metaclass=PoolMeta): t = cls.__table__() cls._sql_constraints = [ ('invoice_unique', Unique(t, t.invoice), - "Invoice can be registered only once for Chorus."), + 'account_fr_chorus.msg_invoice_unique'), ] - cls._error_messages.update({ - 'no_siret': 'The address "%(address)s" is missing a SIRET.', - 'delete_sent': ( - 'The Chorus invoice "%(invoice)s" can not be deleted ' - 'once sent.'), - }) - @classmethod def default_syntax(cls): pool = Pool() @@ -163,17 +160,19 @@ class InvoiceChorus(ModelSQL, ModelView, _SyntaxMixin, metaclass=PoolMeta): record.invoice.invoice_address] for address in addresses: if not address.siret: - cls.raise_user_error('no_siret', { - 'address': address.rec_name, - }) + raise InvoiceChorusValidationError( + gettext('account_fr_chorus' + '.msg_invoice_address_no_siret', + invoice=record.invoice.rec_name, + address=address.rec_name)) @classmethod def delete(cls, records): for record in records: if record.number: - cls.raise_user_error('delete_sent', { - 'invoice': record.invoice.rec_name, - }) + raise AccessError( + gettext('account_fr_chorus.msg_invoice_delete_sent', + invoice=record.invoice.rec_name)) super(InvoiceChorus, cls).delete(records) def _send_context(self): diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..6e5031f7b6 --- /dev/null +++ b/exceptions.py @@ -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 InvoiceChorusValidationError(ValidationError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..1657a11c8b --- /dev/null +++ b/message.xml @@ -0,0 +1,16 @@ + + + + + + You can create only one Chorus invoice per invoice. + + + To create a Chorus invoice for "%(invoice)s", you must set a SIRET on address "%(address)s". + + + You cannot delete Chorus invoice "%(invoice)s" because it is sent. + + + diff --git a/tryton.cfg b/tryton.cfg index 06e934cb75..7593c8e43d 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -12,3 +12,4 @@ extras_depend: xml: account.xml party.xml + message.xml