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

        issue3672
diffstat:

 message.xml |  13 +++++++++++++
 move.py     |  13 +++++++------
 tryton.cfg  |   2 ++
 3 files changed, 22 insertions(+), 6 deletions(-)

diffs (63 lines):

diff -r 3f4869184e03 -r 250e70974e4a 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,13 @@
+<?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_move_delete_fifo">
+            <field name="text">You cannot delete move "%(move)s" because it is 
used for FIFO cost price calculation.</field>
+        </record>
+        <record model="ir.message" id="msg_move_fifo_quantity_greater">
+            <field name="text">The FIFO quantity on move cannot be greater 
than its quantity.</field>
+        </record>
+    </data>
+</tryton>
diff -r 3f4869184e03 -r 250e70974e4a move.py
--- a/move.py   Mon Oct 01 12:56:07 2018 +0200
+++ b/move.py   Sat Dec 29 14:20:29 2018 +0100
@@ -1,7 +1,10 @@
 # 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 decimal import Decimal
+
+from trytond.i18n import gettext
 from trytond.model import Workflow, ModelView, fields, Check
+from trytond.model.exceptions import AccessError
 from trytond.pool import Pool, PoolMeta
 from trytond.transaction import Transaction
 
@@ -21,12 +24,8 @@
         cls._sql_constraints += [
             ('check_fifo_quantity_out',
                 Check(t, t.quantity >= t.fifo_quantity),
-                'FIFO quantity can not be greater than quantity.'),
+                'product_cost_fifo.msg_move_fifo_quantity_greater'),
             ]
-        cls._error_messages.update({
-                'del_move_fifo': ('You can not delete move "%s" that is used '
-                    'for FIFO cost price.'),
-                })
 
     @staticmethod
     def default_fifo_quantity():
@@ -118,5 +117,7 @@
                 ('fifo_quantity', '!=', 0.0),
                 ])
         if fifo_moves:
-            cls.raise_user_error('del_move_fifo', (fifo_moves[0].rec_name,))
+            raise AccessError(
+                gettext('product_cost_fifo.msg_move_delete_fifo',
+                    move=fifo_moves[0].rec_name))
         super(Move, cls).delete(moves)
diff -r 3f4869184e03 -r 250e70974e4a tryton.cfg
--- a/tryton.cfg        Mon Oct 01 12:56:07 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -4,3 +4,5 @@
     ir
     product
     stock
+xml:
+    message.xml

Reply via email to