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

        issue3672
diffstat:

 message.xml                                |  10 ++++++++++
 sale.py                                    |  16 ++++++----------
 tests/scenario_sale_subscription_asset.rst |   4 ++--
 tryton.cfg                                 |   1 +
 4 files changed, 19 insertions(+), 12 deletions(-)

diffs (81 lines):

diff -r 106617eeb511 -r 901879ee8100 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_asset_line_overlap">
+            <field name="text">The lines "%(line1)s" and "%(line2)s" overlap, 
you must use different dates.</field>
+        </record>
+    </data>
+</tryton>
diff -r 106617eeb511 -r 901879ee8100 sale.py
--- a/sale.py   Mon Oct 01 13:41:16 2018 +0200
+++ b/sale.py   Sat Dec 29 14:20:29 2018 +0100
@@ -2,7 +2,9 @@
 # this repository contains the full copyright notices and license terms.
 from sql import Null
 
+from trytond.i18n import gettext
 from trytond.model import fields, ModelSQL, ModelView, Workflow
+from trytond.model.exceptions import ValidationError
 from trytond.pool import PoolMeta, Pool
 from trytond.pyson import Eval, If, Bool
 from trytond.tools import grouped_slice, reduce_ids
@@ -99,12 +101,6 @@
             ]
         cls.quantity.depends.append('asset_lot')
 
-        cls._error_messages.update({
-                'asset_overlapping_dates': (
-                    'The lines "%(line1)s" and "%(line2)s" '
-                    'for the same lot overlap.'),
-                })
-
     @fields.depends('service')
     def on_change_with_asset_lot_required(self, name=None):
         if not self.service:
@@ -161,7 +157,7 @@
             overlapping = cursor.fetchone()
             if overlapping:
                 sline1, sline2 = cls.browse(overlapping)
-                cls.raise_user_error('asset_overlapping_dates', {
-                        'line1': sline1.rec_name,
-                        'line2': sline2.rec_name,
-                        })
+                raise ValidationError(
+                    gettext('sale_subscription_asset.msg_asset_line_overlap',
+                        line1=sline1.rec_name,
+                        line2=sline2.rec_name))
diff -r 106617eeb511 -r 901879ee8100 tests/scenario_sale_subscription_asset.rst
--- a/tests/scenario_sale_subscription_asset.rst        Mon Oct 01 13:41:16 
2018 +0200
+++ b/tests/scenario_sale_subscription_asset.rst        Sat Dec 29 14:20:29 
2018 +0100
@@ -104,7 +104,7 @@
     >>> subscription.click('run')  # doctest: +IGNORE_EXCEPTION_DETAIL
     Traceback (most recent call last):
         ...
-    UserError: ...
+    RequiredValidationError: ...
 
     >>> subscription.click('draft')
     >>> line, = subscription.lines
@@ -137,7 +137,7 @@
     >>> overlapping.save()  # doctest: +IGNORE_EXCEPTION_DETAIL
     Traceback (most recent call last):
         ...
-    UserError: ....
+    DomainValidationError: ....
 
 Cancelling the subscription will remove lot from the lines thus making it
 available again::
diff -r 106617eeb511 -r 901879ee8100 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 13:41:16 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
 xml:
     sale.xml
     stock.xml
+    message.xml

Reply via email to