Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:29 +01:00
parent 0d4fef3357
commit 1d0bf91c18
4 changed files with 22 additions and 15 deletions
+10
View File
@@ -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>
+9 -13
View File
@@ -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,
})
+2 -2
View File
@@ -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')
+1
View File
@@ -7,3 +7,4 @@ extras_depend:
stock_supply
xml:
stock.xml
message.xml