Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier committed 2018-12-29 14:20:29 +01:00
1 parent 3fcb862d3b
commit afddf3c5f7
5 files changed
+31 -12

No files matched your search

+8
View File
@@ -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.exceptions import UserWarning
class PurchaseWarning(UserWarning):
pass
+10
View File
@@ -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_pending_purchase_done">
<field name="text">The productions "%(productions)s" cannot be processed as they have pending purchases.</field>
</record>
</data>
</tryton>
+11 -11
View File
@@ -4,10 +4,13 @@ import hashlib
from decimal import Decimal
from itertools import groupby
from trytond.i18n import gettext
from trytond.model import ModelView, Workflow, fields
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool, If
from .exceptions import PurchaseWarning
class Routing(metaclass=PoolMeta):
__name__ = 'production.routing'
@@ -100,15 +103,6 @@ class Production(metaclass=PoolMeta):
depends=['company'],
help="The lines to add to the production cost.")
@classmethod
def __setup__(cls):
super(Production, cls).__setup__()
cls._error_messages.update({
'pending_purchase_done': (
'The productions "%s" can not be done '
'as they have pending purchases'),
})
def get_cost(self, name):
pool = Pool()
Currency = pool.get('currency.currency')
@@ -218,6 +212,9 @@ class Production(metaclass=PoolMeta):
@ModelView.button
@Workflow.transition('done')
def done(cls, productions):
pool = Pool()
Warning = pool.get('res.user.warning')
def pending_purchase(production):
return any(l.purchase_state in {'draft', 'quotation'}
for l in production.purchase_lines)
@@ -228,6 +225,9 @@ class Production(metaclass=PoolMeta):
names += '...'
warning_name = '%s.pending_purchase.done' % hashlib.md5(
str(pendings).encode('utf-8')).hexdigest()
cls.raise_user_warning(
warning_name, 'pending_purchase_done', names)
if Warning.check(warning_name):
raise PurchaseWarning(
warning_name,
gettext('production_outsourcing.msg_pending_purchase_done',
productions=names))
super(Production, cls).done(productions)
+1 -1
View File
@@ -153,7 +153,7 @@ Try to do the production with pending purchase::
>>> production.click('done') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserWarning: ...
PurchaseWarning: ...
Validate the purchase::
+1
View File
@@ -9,3 +9,4 @@ depends:
xml:
production.xml
purchase.xml
message.xml