diff --git a/account.py b/account.py index a6122986fa..48ddc89df6 100644 --- a/account.py +++ b/account.py @@ -1,7 +1,9 @@ # 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 import backend +from trytond.i18n import gettext from trytond.model import ModelSQL, fields +from trytond.model.exceptions import AccessError from trytond.pyson import Eval from trytond.pool import PoolMeta, Pool from trytond.tools.multivalue import migrate_property @@ -134,14 +136,6 @@ class Move(metaclass=PoolMeta): class Period(metaclass=PoolMeta): __name__ = 'account.period' - @classmethod - def __setup__(cls): - super(Period, cls).__setup__() - cls._error_messages.update({ - 'running_assets_close': ('Some asset lines "%(names)s" are still ' - 'running for this period "%(period)s".'), - }) - def check_asset_line_running(self): """ Check if it exist some asset lines without account move for the curent @@ -161,10 +155,10 @@ class Period(metaclass=PoolMeta): names = ', '.join(a.rec_name for a in assets[:5]) if len(assets) > 5: names += '...' - self.raise_user_error('running_assets_close', { - 'period': self.rec_name, - 'names': names, - }) + raise AccessError( + gettext('account_asset.msg_asset_running_close_period', + period=self.rec_name, + assets=names)) @classmethod def close(cls, periods): diff --git a/asset.py b/asset.py index 7677548052..084d6d008a 100644 --- a/asset.py +++ b/asset.py @@ -8,7 +8,9 @@ from dateutil import rrule from itertools import groupby from cached_property import cached_property +from trytond.i18n import gettext from trytond.model import Workflow, ModelSQL, ModelView, fields, Unique +from trytond.model.exceptions import AccessError from trytond.pyson import Eval, Bool, If from trytond.pool import Pool from trytond.transaction import Transaction @@ -173,11 +175,8 @@ class Asset(Workflow, ModelSQL, ModelView): table = cls.__table__() cls._sql_constraints = [ ('invoice_line_uniq', Unique(table, table.supplier_invoice_line), - 'Supplier Invoice Line can be used only once on asset.'), + 'account_asset.msg_asset_invoice_line_unique'), ] - cls._error_messages.update({ - 'delete_draft': 'Asset "%s" must be in draft to be deleted.', - }) cls._transitions |= set(( ('draft', 'running'), ('running', 'closed'), @@ -630,7 +629,9 @@ class Asset(Workflow, ModelSQL, ModelView): def delete(cls, assets): for asset in assets: if asset.state != 'draft': - cls.raise_user_error('delete_draft', asset.rec_name) + raise AccessError( + gettext('account_asset.msg_delete_draft', + asset=asset.rec_name)) return super(Asset, cls).delete(assets) diff --git a/invoice.py b/invoice.py index 40f58c5ec9..a494727220 100644 --- a/invoice.py +++ b/invoice.py @@ -30,7 +30,7 @@ class InvoiceLine(metaclass=PoolMeta): table = cls.__table__() cls._sql_constraints += [ ('asset_uniq', Unique(table, table.asset), - 'Asset can be used only once on invoice line!'), + 'account_asset.msg_invoice_line_asset_unique'), ] @fields.depends('product', 'invoice', 'invoice_type', diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..6ea64eb4af --- /dev/null +++ b/message.xml @@ -0,0 +1,22 @@ + + + + + + You cannot delete asset "%(asset)s" because it is not in "draft" state. + + + You cannot close period "%(period)s" because some assets "%(assets)s" still have lines without move. + + + Invoice line can be used only once on asset. + + + To invoice purchase "%(purchase)s", you must set an account asset on product "%(product)s". + + + Asset can be used only once on invoice line. + + + diff --git a/purchase.py b/purchase.py index cdb95eedca..e8ad61255b 100644 --- a/purchase.py +++ b/purchase.py @@ -1,21 +1,16 @@ # 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 +from trytond.modules.account_product.exceptions import AccountError + __all__ = ['PurchaseLine'] class PurchaseLine(metaclass=PoolMeta): __name__ = 'purchase.line' - @classmethod - def __setup__(cls): - super(PurchaseLine, cls).__setup__() - cls._error_messages.update({ - 'missing_account_asset': ('It misses ' - 'an "Account Asset" on product "%s".'), - }) - def get_invoice_line(self): invoice_lines = super(PurchaseLine, self).get_invoice_line() if (self.product @@ -25,6 +20,9 @@ class PurchaseLine(metaclass=PoolMeta): if invoice_line.product == self.product: invoice_line.account = self.product.account_asset_used if not invoice_line.account: - self.raise_user_error('missing_account_asset', - error_args=(self.product.rec_name,)) + raise AccountError( + gettext('account_asset' + '.msg_purchase_product_missing_account_asset', + purchase=self.purchase.rec_name, + product=self.product.rec_name)) return invoice_lines diff --git a/tests/scenario_account_asset.rst b/tests/scenario_account_asset.rst index df10513b8b..e8df37a59f 100644 --- a/tests/scenario_account_asset.rst +++ b/tests/scenario_account_asset.rst @@ -150,7 +150,7 @@ Trying to close the period to check error:: >>> period.click('close') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + AccessError: ... Create Moves for 3 months:: diff --git a/tryton.cfg b/tryton.cfg index 834fecc34b..50204e9d33 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -24,3 +24,4 @@ xml: minimal_chart_pt.xml minimal_chart_ru.xml minimal_chart_sl.xml + message.xml