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

        issue3672
diffstat:

 account.py    |  23 +++++++++--------------
 exceptions.py |   8 ++++++++
 message.xml   |  10 ++++++++++
 tryton.cfg    |   1 +
 4 files changed, 28 insertions(+), 14 deletions(-)

diffs (93 lines):

diff -r c6be62fd54f7 -r 2bd4820eae4f account.py
--- a/account.py        Mon Oct 01 13:12:35 2018 +0200
+++ b/account.py        Sat Dec 29 14:20:29 2018 +0100
@@ -6,11 +6,14 @@
 
 from sql import Null, Literal
 
+from trytond.i18n import gettext
 from trytond.model import ModelSQL, ModelView, Workflow, fields
 from trytond.pool import PoolMeta, Pool
 from trytond.pyson import Eval
 from trytond.transaction import Transaction
 
+from .exceptions import ClosePeriodWarning
+
 
 def _tax_group(tax):
     while tax.parent:
@@ -35,16 +38,6 @@
         "Tax Group On Cash Basis",
         help="The tax group reported on cash basis for this period.")
 
-    @classmethod
-    def __setup__(cls):
-        super(Period, cls).__setup__()
-        cls._error_messages.update({
-                'period_close_line_payment': (
-                    'There are payable/receivable lines '
-                    'from the period "%(period)s" not linked '
-                    'to an invoice.'),
-                })
-
     def is_on_cash_basis(self, tax):
         if not tax:
             return False
@@ -58,6 +51,7 @@
     def close(cls, periods):
         pool = Pool()
         MoveLine = pool.get('account.move.line')
+        Warning = pool.get('res.user.warning')
         super(Period, cls).close(periods)
         for period in periods:
             if (period.tax_group_on_cash_basis
@@ -72,10 +66,11 @@
                     warning_name = (
                         'period_close_line_payment.%s' % hashlib.md5(
                             str(move_lines).encode('utf-8')).hexdigest())
-                    cls.raise_user_warning(
-                        warning_name, 'period_close_line_payment', {
-                            'period': period.rec_name,
-                            })
+                    if Warning.check(warning_name):
+                        raise ClosePeriodWarning(warning_name,
+                            gettext('account_tax_cash'
+                                '.msg_close_period_line_payment',
+                                period=period.rec_name))
 
 
 class TaxGroupCash(ModelSQL):
diff -r c6be62fd54f7 -r 2bd4820eae4f 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 ClosePeriodWarning(UserWarning):
+    pass
diff -r c6be62fd54f7 -r 2bd4820eae4f 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_close_period_line_payment">
+            <field name="text">To close period "%(period)s" you must link all 
payable/receivable lines to invoices.</field>
+        </record>
+    </data>
+</tryton>
diff -r c6be62fd54f7 -r 2bd4820eae4f tryton.cfg
--- a/tryton.cfg        Mon Oct 01 13:12:35 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -8,3 +8,4 @@
 xml:
     account.xml
     party.xml
+    message.xml

Reply via email to