diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..131b4f4b42 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + The location "%(location)s" has already been assigned by "%(assigned_by)s". + + + diff --git a/stock.py b/stock.py index 2bf141cda0..315a199086 100644 --- a/stock.py +++ b/stock.py @@ -2,11 +2,14 @@ # this repository contains the full copyright notices and license terms. import functools +from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, Workflow, fields from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval, If from trytond.transaction import Transaction +from trytond.modules.stock.exceptions import AssignError + __all__ = ['Location', 'ShipmentInternal', 'ShipmentInternal_Location', 'ShipmentOut', 'ShipmentInReturn', 'Supply'] @@ -125,15 +128,6 @@ class ShipmentInternal(metaclass=PoolMeta): }, depends=['state', 'from_location', 'to_location']) - @classmethod - def __setup__(cls): - super(ShipmentInternal, cls).__setup__() - cls._error_messages.update({ - 'location_already_assigned': ( - "The location '%(location)s' is already assigned " - "by '%(assigned_by)s'."), - }) - @classmethod @ModelView.button @Workflow.transition('draft') @@ -159,15 +153,17 @@ class ShipmentInternal(metaclass=PoolMeta): if not location.assigned_by: location.assigned_by = shipment if location in locations: - cls.raise_user_error( - 'location_already_assigned', { + raise AssignError( + gettext('stock_location_move' + '.msg_location_already_assigned') % { 'location': location.rec_name, 'assigned_by': locations[location].rec_name, }) locations[location] = location.assigned_by elif location.assigned_by != shipment: - cls.raise_user_error( - 'location_already_assigned', { + raise AssignError( + gettext('stock_location_move' + '.msg_location_already_assigned') % { 'location': location.rec_name, 'assigned_by': location.assigned_by.rec_name, }) diff --git a/tests/scenario_stock_location_move.rst b/tests/scenario_stock_location_move.rst index 054af32ae1..48ea6f37bd 100644 --- a/tests/scenario_stock_location_move.rst +++ b/tests/scenario_stock_location_move.rst @@ -70,7 +70,7 @@ Assign pallet from wrong location:: >>> shipment.click('assign_try') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + DomainValidationError: ... Concurrently move pallet:: @@ -91,7 +91,7 @@ Concurrently move pallet:: >>> shipment2.click('assign_try') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + AssignError: ... >>> shipment1.click('done') diff --git a/tryton.cfg b/tryton.cfg index edcbedd3c7..7832684579 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ extras_depend: stock_supply xml: stock.xml + message.xml