changeset 908feec11e28 in modules/stock_supply_production:default details: https://hg.tryton.org/modules/stock_supply_production?cmd=changeset;node=908feec11e28 description: Add ir.message and use custom exceptions
issue3672 diffstat: message.xml | 10 ++++++++++ stock.py | 18 +++++++++--------- tryton.cfg | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diffs (75 lines): diff -r 6dd9cbb393c9 -r 908feec11e28 message.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/message.xml Sat Dec 29 14:20:30 2018 +0100 @@ -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_late_productions"> + <field name="text">There are some productions that are late.</field> + </record> + </data> +</tryton> diff -r 6dd9cbb393c9 -r 908feec11e28 stock.py --- a/stock.py Wed Oct 31 18:17:35 2018 +0100 +++ b/stock.py Sat Dec 29 14:20:30 2018 +0100 @@ -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'] @@ -70,13 +73,6 @@ 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 @@ 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 @@ ('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 -r 6dd9cbb393c9 -r 908feec11e28 tryton.cfg --- a/tryton.cfg Wed Oct 31 18:17:35 2018 +0100 +++ b/tryton.cfg Sat Dec 29 14:20:30 2018 +0100 @@ -9,3 +9,4 @@ xml: production.xml stock.xml + message.xml