diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..87e0daa918 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + To get a quote for purchase "%(purchase)s", you must enter a analytic account for "%(roots)s" on line "%(line)s". + + + diff --git a/purchase.py b/purchase.py index 882c754e7f..9a560cfdcf 100644 --- a/purchase.py +++ b/purchase.py @@ -1,10 +1,12 @@ # 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.model import fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, If from trytond.modules.analytic_account import AnalyticMixin +from trytond.modules.purchase.exceptions import PurchaseQuotationError __all__ = ['Purchase', 'PurchaseLine', 'AnalyticAccountEntry'] @@ -12,14 +14,6 @@ __all__ = ['Purchase', 'PurchaseLine', 'AnalyticAccountEntry'] class Purchase(metaclass=PoolMeta): __name__ = "purchase.purchase" - @classmethod - def __setup__(cls): - super(Purchase, cls).__setup__() - cls._error_messages.update({ - 'analytic_account_required': ('Analytic account is required ' - 'for "%(roots)s" on line "%(line)s".'), - }) - def check_for_quotation(self): pool = Pool() Account = pool.get('analytic_account.account') @@ -36,11 +30,13 @@ class Purchase(metaclass=PoolMeta): analytic_roots = {e.root for e in line.analytic_accounts if e.account} if not mandatory_roots <= analytic_roots: - self.raise_user_error('analytic_account_required', { - 'line': line.rec_name, - 'roots': ', '.join(x.rec_name - for x in mandatory_roots - analytic_roots), - }) + raise PurchaseQuotationError( + gettext('analytic_purchase' + '.msg_analytic_account_required_for_quotation', + purchase=self.rec_name, + line=line.rec_name, + roots=', '.join(x.rec_name + for x in mandatory_roots - analytic_roots))) class PurchaseLine(AnalyticMixin, metaclass=PoolMeta): diff --git a/tests/scenario_analytic_purchase.rst b/tests/scenario_analytic_purchase.rst index c705107d9b..71bdf75a13 100644 --- a/tests/scenario_analytic_purchase.rst +++ b/tests/scenario_analytic_purchase.rst @@ -184,7 +184,7 @@ Analytic entries are not required until quotation:: >>> purchase.click('quote') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + PurchaseQuotationError: ... >>> purchase_line, = purchase.lines >>> entry, mandatory_entry = purchase_line.analytic_accounts >>> mandatory_entry.account = mandatory_analytic_account diff --git a/tryton.cfg b/tryton.cfg index 9796ea73d2..132c83f0fa 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,3 +6,4 @@ depends: purchase xml: purchase.xml + message.xml