Add ir.message and use custom exceptions
issue3672
This commit is contained in:
+6
-12
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -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',
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?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_asset_delete_draft">
|
||||
<field name="text">You cannot delete asset "%(asset)s" because it is not in "draft" state.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_asset_running_close_period">
|
||||
<field name="text">You cannot close period "%(period)s" because some assets "%(assets)s" still have lines without move.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_asset_invoice_line_unique">
|
||||
<field name="text">Invoice line can be used only once on asset.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_purchase_product_missing_account_asset">
|
||||
<field name="text">To invoice purchase "%(purchase)s", you must set an account asset on product "%(product)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invoice_line_asset_unique">
|
||||
<field name="text">Asset can be used only once on invoice line.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+8
-10
@@ -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
|
||||
|
||||
@@ -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::
|
||||
|
||||
|
||||
@@ -24,3 +24,4 @@ xml:
|
||||
minimal_chart_pt.xml
|
||||
minimal_chart_ru.xml
|
||||
minimal_chart_sl.xml
|
||||
message.xml
|
||||
|
||||
Reference in New Issue
Block a user