diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..2b011caa45 --- /dev/null +++ b/exceptions.py @@ -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 OverShipmentWarning(UserWarning): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..18ed3f0b32 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + The sale line "%(line)s" exceeds the over shipment tolerance. + + + diff --git a/sale.py b/sale.py index c7fe143131..5e1f077be9 100644 --- a/sale.py +++ b/sale.py @@ -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, Pool +from .exceptions import OverShipmentWarning + __all__ = ['SaleLine'] class SaleLine(metaclass=PoolMeta): __name__ = 'sale.line' - @classmethod - def __setup__(cls): - super(SaleLine, cls).__setup__() - cls._error_messages.update({ - 'over_shipment': ( - 'The Sale Line "%s" exceed the over shipment tolerance.'), - }) - def _test_under_shipment_tolerance(self, quantity): pool = Pool() Configuration = pool.get('sale.configuration') @@ -50,6 +45,7 @@ class SaleLine(metaclass=PoolMeta): def check_over_shipment(self): pool = Pool() Configuration = pool.get('sale.configuration') + Warning = pool.get('res.user.warning') config = Configuration(1) if self.quantity >= 0: @@ -61,6 +57,9 @@ class SaleLine(metaclass=PoolMeta): if tolerance is not None: maximal_quantity = abs(self.quantity * tolerance) if shipped_quantity > maximal_quantity: - self.raise_user_warning( - 'over_shipment_sale_line_%d' % self.id, - 'over_shipment', self.rec_name) + name = 'over_shipment_sale_line_%d' % self.id + if Warning.check(name): + raise OverShipmentWarning( + name, + gettext('sale_shipment_tolerance.msg_over_shipment', + line=self.rec_name)) diff --git a/tests/scenario_sale_over_shipment_tolerance.rst b/tests/scenario_sale_over_shipment_tolerance.rst index 77ef2573b2..6208ba46fe 100644 --- a/tests/scenario_sale_over_shipment_tolerance.rst +++ b/tests/scenario_sale_over_shipment_tolerance.rst @@ -86,7 +86,7 @@ Prevent over ship 13 products:: >>> shipment.click('pack') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserWarning: ... + OverShipmentWarning: ... Over ship 12 products:: diff --git a/tryton.cfg b/tryton.cfg index 880b3e85a9..4dd7ba24c8 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,3 +6,4 @@ depends: stock xml: configuration.xml + message.xml