Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:30 +01:00
parent 7fd9c2fe4a
commit 9d1cbd8d7c
5 changed files with 26 additions and 18 deletions
+8
View File
@@ -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
+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_package_mismatch">
<field name="text">To process shipment "%(shipment)s", you must pack all its moves.</field>
</record>
</data>
</tryton>
+6 -17
View File
@@ -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')
+1 -1
View File
@@ -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()
+1
View File
@@ -6,3 +6,4 @@ depends:
stock
xml:
stock.xml
message.xml