Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
8619c06b00
commit
a9183a56cf
4 files changed
+21
-14
No files matched your search
+10
@@ -0,0 +1,10 @@
|
||||
<?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_analytic_account_required_for_quotation">
|
||||
<field name="text">To get a quote for purchase "%(purchase)s", you must enter a analytic account for "%(roots)s" on line "%(line)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+9
-13
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,3 +6,4 @@ depends:
|
||||
purchase
|
||||
xml:
|
||||
purchase.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user