diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..76bdb502e3 --- /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 DepositError(ValidationError): + pass diff --git a/invoice.py b/invoice.py index 7866be3048..4834ef178e 100644 --- a/invoice.py +++ b/invoice.py @@ -1,11 +1,14 @@ # 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.i18n import gettext from trytond.pool import PoolMeta, Pool from trytond.model import ModelView, Workflow, fields from trytond.wizard import Wizard, StateView, StateTransition, Button from trytond.pyson import Eval from trytond.transaction import Transaction +from .exceptions import DepositError + __all__ = ['Invoice', 'InvoiceLine', 'DepositRecall', 'DepositRecallStart'] @@ -16,11 +19,6 @@ class Invoice(metaclass=PoolMeta): @classmethod def __setup__(cls): super(Invoice, cls).__setup__() - cls._error_messages.update({ - 'deposit_not_enough': ( - 'The account "%(account)s" for party "%(party)s" ' - 'has not enough deposit.'), - }) cls._buttons.update({ 'recall_deposit': { 'invisible': Eval('state') != 'draft', @@ -106,10 +104,10 @@ class Invoice(metaclass=PoolMeta): for party, account, sign in to_check: if not party.check_deposit(account, sign): - cls.raise_user_error('deposit_not_enough', { - 'account': account.rec_name, - 'party': party.rec_name, - }) + raise DepositError( + gettext('account_deposit.msg_deposit_not_enough', + account=account.rec_name, + party=party.rec_name)) class InvoiceLine(metaclass=PoolMeta): diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..d620c788d1 --- /dev/null +++ b/message.xml @@ -0,0 +1,13 @@ + + + + + + You cannot erase party "%(party)s" while they have deposit at company "%(company)s". + + + The account "%(account)s" has not enough deposit from party "%(party)s". + + + diff --git a/party.py b/party.py index 07e295ef5f..10dd7674e5 100644 --- a/party.py +++ b/party.py @@ -6,12 +6,15 @@ from sql import Null, Literal, For from sql.aggregate import Sum from sql.conditionals import Coalesce +from trytond.i18n import gettext from trytond.pool import PoolMeta, Pool from trytond.model import fields from trytond.pyson import Eval from trytond.transaction import Transaction from trytond.tools import grouped_slice, reduce_ids +from trytond.modules.party.exceptions import EraseError + __all__ = ['Party', 'PartyErase'] @@ -135,18 +138,9 @@ class Party(metaclass=PoolMeta): class PartyErase(metaclass=PoolMeta): __name__ = 'party.erase' - @classmethod - def __setup__(cls): - super(PartyErase, cls).__setup__() - cls._error_messages.update({ - 'deposit': ( - 'The party "%(party)s" can not be erased ' - 'because he has deposit for the company "%(company)s".'), - }) - def check_erase_company(self, party, company): if party.deposit: - self.raise_user_error('deposit', { - 'party': party.rec_name, - 'company': company.rec_name, - }) + raise EraseError( + gettext('account_deposit.msg_erase_party_deposit', + party=party.rec_name, + company=company.rec_name)) diff --git a/tryton.cfg b/tryton.cfg index 5a49d55b8f..fae0a850f3 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -20,4 +20,4 @@ xml: minimal_chart_pt.xml minimal_chart_ru.xml minimal_chart_sl.xml - + message.xml