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

        issue3672
diffstat:

 exceptions.py |   8 ++++++++
 message.xml   |  10 ++++++++++
 purchase.py   |  20 +++++++++-----------
 tryton.cfg    |   1 +
 4 files changed, 28 insertions(+), 11 deletions(-)

diffs (88 lines):

diff -r 9d8c49baf006 -r b83d8419d931 exceptions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py     Sat Dec 29 14:20:29 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 UserWarning
+
+
+class PreviousQuotation(UserWarning):
+    pass
diff -r 9d8c49baf006 -r b83d8419d931 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,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_previous_quotation">
+            <field name="text">A quotation was already made for request 
"%(request)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r 9d8c49baf006 -r b83d8419d931 purchase.py
--- a/purchase.py       Mon Oct 01 13:38:21 2018 +0200
+++ b/purchase.py       Sat Dec 29 14:20:29 2018 +0100
@@ -5,6 +5,7 @@
 from itertools import groupby
 from sql.conditionals import Case
 
+from trytond.i18n import gettext
 from trytond.model import Workflow, ModelView, fields, ModelSQL
 from trytond.modules.company import CompanyReport
 from trytond.modules.product import price_digits
@@ -13,6 +14,8 @@
 from trytond.transaction import Transaction
 from trytond.wizard import Wizard, StateView, StateTransition, Button
 
+from .exceptions import PreviousQuotation
+
 
 __all__ = ['Configuration', 'ConfigurationSequence', 'Quotation',
     'QuotationLine', 'CreatePurchaseRequestQuotationAskSuppliers',
@@ -458,17 +461,10 @@
             Button('Close', 'end', 'tryton-close', True),
             ])
 
-    @classmethod
-    def __setup__(cls):
-        super(CreatePurchaseRequestQuotation, cls).__setup__()
-        cls._error_messages.update({
-                'previous_quotation': ('A quotation was already made for '
-                    'the request "%(request)s".'),
-                })
-
     def transition_start(self):
         pool = Pool()
         Request = pool.get('purchase.request')
+        Warning = pool.get('res.user.warning')
 
         requests = Request.browse(Transaction().context['active_ids'])
 
@@ -476,9 +472,11 @@
         if reqs:
             for r in reqs:
                 if r.state == 'quotation':
-                    self.raise_user_warning(str(r),
-                                'previous_quotation',
-                                {'request': r.rec_name, })
+                    if Warning.check(str(r)):
+                        raise PreviousQuotation(str(r),
+                            gettext('purchase_request_quotation'
+                                '.msg_previous_quotation',
+                                request=r.rec_name))
             return 'ask_suppliers'
         return 'end'
 
diff -r 9d8c49baf006 -r b83d8419d931 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 13:38:21 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -10,3 +10,4 @@
 xml:
     purchase.xml
     purchase_request.xml
+    message.xml

Reply via email to