changeset b8cf8e8c7a94 in modules/stock_package:default
details: 
https://hg.tryton.org/modules/stock_package?cmd=changeset;node=b8cf8e8c7a94
description:
        Add ir.message and use custom exceptions

        issue3672
diffstat:

 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(-)

diffs (105 lines):

diff -r 198753b160bf -r b8cf8e8c7a94 exceptions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py     Sat Dec 29 14:20:30 2018 +0100
@@ -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 -r 198753b160bf -r b8cf8e8c7a94 message.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml       Sat Dec 29 14:20:30 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_package_mismatch">
+            <field name="text">To process shipment "%(shipment)s", you must 
pack all its moves.</field>
+        </record>
+    </data>
+</tryton>
diff -r 198753b160bf -r b8cf8e8c7a94 stock.py
--- a/stock.py  Mon Oct 01 13:00:59 2018 +0200
+++ b/stock.py  Sat Dec 29 14:20:30 2018 +0100
@@ -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 @@
                 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):
@@ -180,14 +185,6 @@
     __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')
     def pack(cls, shipments):
@@ -210,14 +207,6 @@
     __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')
     def done(cls, shipments):
diff -r 198753b160bf -r b8cf8e8c7a94 tests/scenario_stock_package.rst
--- a/tests/scenario_stock_package.rst  Mon Oct 01 13:00:59 2018 +0200
+++ b/tests/scenario_stock_package.rst  Sat Dec 29 14:20:30 2018 +0100
@@ -95,7 +95,7 @@
     >>> 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 -r 198753b160bf -r b8cf8e8c7a94 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 13:00:59 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:30 2018 +0100
@@ -6,3 +6,4 @@
     stock
 xml:
     stock.xml
+    message.xml

Reply via email to