From cf7ea2ea18db25d08a6ddd8f77ba35ba93d7bbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Dec 2018 14:20:30 +0100 Subject: [PATCH] Add ir.message and use custom exceptions issue3672 --- message.xml | 10 ++++++++++ stock.py | 18 +++++++++--------- tryton.cfg | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 message.xml diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..555cc77e91 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + There are some productions that are late. + + + diff --git a/stock.py b/stock.py index 4721978873..fbe244b71c 100644 --- a/stock.py +++ b/stock.py @@ -2,10 +2,13 @@ # this repository contains the full copyright notices and license terms. import datetime +from trytond.i18n import gettext from trytond.pyson import Eval, If from trytond.pool import PoolMeta, Pool from trytond.wizard import StateAction +from trytond.modules.stock_supply.exceptions import SupplyWarning + __all__ = ['OrderPoint', 'LocationLeadTime', 'StockSupply'] @@ -69,13 +72,6 @@ class StockSupply(metaclass=PoolMeta): production = StateAction('stock_supply_production.act_production_request') - @classmethod - def __setup__(cls): - super(StockSupply, cls).__setup__() - cls._error_messages.update({ - 'late_productions': 'There are some late productions.', - }) - @classmethod def types(cls): return super(StockSupply, cls).types() + ['production'] @@ -84,6 +80,7 @@ class StockSupply(metaclass=PoolMeta): pool = Pool() Date = pool.get('ir.date') Move = pool.get('stock.move') + Warning = pool.get('res.user.warning') today = Date.today() if Move.search([ ('from_location.type', '=', 'production'), @@ -91,8 +88,11 @@ class StockSupply(metaclass=PoolMeta): ('state', '=', 'draft'), ('planned_date', '<', today), ], order=[]): - self.raise_user_warning('%s@%s' % (self.__name__, today), - 'late_productions') + key = '%s@%s' % (self.__name__, today) + if Warning.check(key): + raise SupplyWarning( + key, + gettext('stock_supply_production.msg_late_productions')) return super(StockSupply, self).transition_create_() @property diff --git a/tryton.cfg b/tryton.cfg index e7d7d4fe06..92799c9fee 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -9,3 +9,4 @@ depends: xml: production.xml stock.xml + message.xml