From 9d1cbd8d7c8d1ad3ab3900fb33ae54ba0fde878b 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 --- exceptions.py | 8 ++++++++ message.xml | 10 ++++++++++ stock.py | 23 ++++++----------------- tests/scenario_stock_package.rst | 2 +- tryton.cfg | 1 + 5 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 exceptions.py create mode 100644 message.xml diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..4982e53689 --- /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 UserError + + +class PackageError(UserError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..a3da967177 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + To process shipment "%(shipment)s", you must pack all its moves. + + + diff --git a/stock.py b/stock.py index d46a00dea6..7dee5beeab 100644 --- a/stock.py +++ b/stock.py @@ -1,11 +1,14 @@ # 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 import backend +from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, Workflow, fields, tree from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval from trytond.report import Report +from .exceptions import PackageError + __all__ = ['Configuration', 'ConfigurationSequence', 'Package', 'Type', 'Move', 'ShipmentOut', 'ShipmentInReturn', 'PackageLabel'] @@ -169,7 +172,9 @@ class PackageMixin(object): continue length = sum(len(p.moves) for p in shipment.packages) if len(list(shipment.packages_moves)) != length: - cls.raise_user_error('package_mismatch', shipment.rec_name) + raise PackageError( + gettext('stock_package.msg_package_mismatch', + shipment=shipment.rec_name)) @property def packages_moves(self): @@ -179,14 +184,6 @@ class PackageMixin(object): class ShipmentOut(PackageMixin, object, metaclass=PoolMeta): __name__ = 'stock.shipment.out' - @classmethod - def __setup__(cls): - super(ShipmentOut, cls).__setup__() - cls._error_messages.update({ - 'package_mismatch': ('Not all Outgoing Moves of ' - 'Customer Shipment "%s" are packaged.'), - }) - @classmethod @ModelView.button @Workflow.transition('packed') @@ -209,14 +206,6 @@ class ShipmentOut(PackageMixin, object, metaclass=PoolMeta): class ShipmentInReturn(PackageMixin, object, metaclass=PoolMeta): __name__ = 'stock.shipment.in.return' - @classmethod - def __setup__(cls): - super(ShipmentInReturn, cls).__setup__() - cls._error_messages.update({ - 'package_mismatch': ('Not all Moves of ' - 'Supplier Return Shipment "%s" are packaged.'), - }) - @classmethod @ModelView.button @Workflow.transition('done') diff --git a/tests/scenario_stock_package.rst b/tests/scenario_stock_package.rst index c0d01e16ad..ffa6f0fa6b 100644 --- a/tests/scenario_stock_package.rst +++ b/tests/scenario_stock_package.rst @@ -95,7 +95,7 @@ Package products:: >>> shipment_out.click('pack') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + PackageError: ... >>> package2 = shipment_out.packages.new(type=box) >>> moves = package2.moves.find() diff --git a/tryton.cfg b/tryton.cfg index aa6604f3c0..91c0c1414d 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,3 +6,4 @@ depends: stock xml: stock.xml + message.xml