changeset 57a974598a2d in modules/stock_location_move:default
details:
https://hg.tryton.org/modules/stock_location_move?cmd=changeset;node=57a974598a2d
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
message.xml | 10 ++++++++++
stock.py | 22 +++++++++-------------
tests/scenario_stock_location_move.rst | 4 ++--
tryton.cfg | 1 +
4 files changed, 22 insertions(+), 15 deletions(-)
diffs (99 lines):
diff -r 24dd6cc67914 -r 57a974598a2d message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 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_location_already_assigned">
+ <field name="text">The location "%(location)s" has already been
assigned by "%(assigned_by)s".</field>
+ </record>
+ </data>
+</tryton>
diff -r 24dd6cc67914 -r 57a974598a2d stock.py
--- a/stock.py Mon Oct 01 15:21:40 2018 +0200
+++ b/stock.py Sat Dec 29 14:20:29 2018 +0100
@@ -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']
@@ -126,15 +129,6 @@
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')
@clear_location_assignation
@@ -159,15 +153,17 @@
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 -r 24dd6cc67914 -r 57a974598a2d tests/scenario_stock_location_move.rst
--- a/tests/scenario_stock_location_move.rst Mon Oct 01 15:21:40 2018 +0200
+++ b/tests/scenario_stock_location_move.rst Sat Dec 29 14:20:29 2018 +0100
@@ -70,7 +70,7 @@
>>> shipment.click('assign_try') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
- UserError: ...
+ DomainValidationError: ...
Concurrently move pallet::
@@ -91,7 +91,7 @@
>>> shipment2.click('assign_try') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
- UserError: ...
+ AssignError: ...
>>> shipment1.click('done')
diff -r 24dd6cc67914 -r 57a974598a2d tryton.cfg
--- a/tryton.cfg Mon Oct 01 15:21:40 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
stock_supply
xml:
stock.xml
+ message.xml