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

        issue3672
diffstat:

 message.xml |  16 ++++++++++++++++
 stock.py    |  34 ++++++++++------------------------
 tryton.cfg  |   1 +
 3 files changed, 27 insertions(+), 24 deletions(-)

diffs (116 lines):

diff -r db54ebeee0ec -r e1ed82bb1056 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,16 @@
+<?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_change_product">
+            <field name="text">You cannot change the product of a stock lot 
which has stock moves.</field>
+        </record>
+        <record model="ir.message" id="msg_lot_required">
+            <field name="text">To move product "%(product)s" you must provide 
a stock lot.</field>
+        </record>
+        <record model="ir.message" id="msg_only_lot">
+            <field name="text">You must select a stock lot instead of a 
product for "%(product)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r db54ebeee0ec -r e1ed82bb1056 stock.py
--- a/stock.py  Mon Oct 01 13:00:35 2018 +0200
+++ b/stock.py  Sat Dec 29 14:20:29 2018 +0100
@@ -4,7 +4,9 @@
 from collections import defaultdict
 from functools import wraps
 
+from trytond.i18n import gettext
 from trytond.model import ModelView, ModelSQL, fields
+from trytond.model.exceptions import AccessError, RequiredValidationError
 from trytond.pyson import Eval
 from trytond.pool import Pool, PoolMeta
 from trytond.tools import grouped_slice
@@ -43,7 +45,7 @@
                 for field, state, error in cls._modify_no_move:
                     if field in values:
                         if find_moves(cls, records, state):
-                            cls.raise_user_error(error)
+                            raise AccessError(gettext(error))
                         # No moves for those records
                         break
         func(cls, *args)
@@ -64,12 +66,8 @@
     @classmethod
     def __setup__(cls):
         super(Lot, cls).__setup__()
-        cls._error_messages.update({
-                'change_product': ("You cannot change the product of a lot "
-                    "which is associated to stock moves."),
-                })
         cls._modify_no_move = [
-            ('product', None, 'change_product'),
+            ('product', None, 'stock_lot.msg_change_product'),
             ]
 
     @classmethod
@@ -132,13 +130,6 @@
             },
         depends=['state', 'product'])
 
-    @classmethod
-    def __setup__(cls):
-        super(Move, cls).__setup__()
-        cls._error_messages.update({
-                'lot_required': 'Lot is required for move of product "%s".',
-                })
-
     def check_lot(self):
         "Check if lot is required"
         if (self.state == 'done'
@@ -146,7 +137,9 @@
                 and not self.lot
                 and self.product.lot_is_required(
                     self.from_location, self.to_location)):
-            self.raise_user_error('lot_required', self.product.rec_name)
+            raise RequiredValidationError(
+                gettext('stock_lot.msg_lot_required',
+                    product=self.product.rec_name))
 
     @classmethod
     def validate(cls, moves):
@@ -297,13 +290,6 @@
 class InventoryCount(metaclass=PoolMeta):
     __name__ = 'stock.inventory.count'
 
-    @classmethod
-    def __setup__(cls):
-        super(InventoryCount, cls).__setup__()
-        cls._error_messages.update({
-                'lot_required': 'Only lot can be selected for "%(product)s".',
-                })
-
     def default_quantity(self, fields):
         pool = Pool()
         Product = pool.get('product.product')
@@ -314,9 +300,9 @@
             product = self.search.search
             if product.lot_is_required(
                     inventory.location, inventory.lost_found):
-                self.raise_user_error('lot_required', {
-                        'product': product.rec_name,
-                        })
+                raise RequiredValidationError(
+                    gettext('stock_lot.msg_only_lot',
+                        product=product.rec_name))
         return super(InventoryCount, self).default_quantity(fields)
 
     def get_line_domain(self, inventory):
diff -r db54ebeee0ec -r e1ed82bb1056 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 13:00:35 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
 xml:
     stock.xml
     product.xml
+    message.xml

Reply via email to