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

        issue3672
diffstat:

 exceptions.py |   8 ++++++++
 invoice.py    |  16 +++++++---------
 message.xml   |  13 +++++++++++++
 party.py      |  20 +++++++-------------
 tryton.cfg    |   2 +-
 5 files changed, 36 insertions(+), 23 deletions(-)

diffs (125 lines):

diff -r 88ab745f9a55 -r 2170c41e3fe3 exceptions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py     Sat Dec 29 14:20:28 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.model.exceptions import ValidationError
+
+
+class DepositError(ValidationError):
+    pass
diff -r 88ab745f9a55 -r 2170c41e3fe3 invoice.py
--- a/invoice.py        Wed Nov 28 09:58:26 2018 +0100
+++ b/invoice.py        Sat Dec 29 14:20:28 2018 +0100
@@ -1,11 +1,14 @@
 # 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.i18n import gettext
 from trytond.pool import PoolMeta, Pool
 from trytond.model import ModelView, Workflow, fields
 from trytond.wizard import Wizard, StateView, StateTransition, Button
 from trytond.pyson import Eval
 from trytond.transaction import Transaction
 
+from .exceptions import DepositError
+
 __all__ = ['Invoice', 'InvoiceLine',
     'DepositRecall', 'DepositRecallStart']
 
@@ -16,11 +19,6 @@
     @classmethod
     def __setup__(cls):
         super(Invoice, cls).__setup__()
-        cls._error_messages.update({
-                'deposit_not_enough': (
-                    'The account "%(account)s" for party "%(party)s" '
-                    'has not enough deposit.'),
-                })
         cls._buttons.update({
                 'recall_deposit': {
                     'invisible': Eval('state') != 'draft',
@@ -106,10 +104,10 @@
 
         for party, account, sign in to_check:
             if not party.check_deposit(account, sign):
-                cls.raise_user_error('deposit_not_enough', {
-                        'account': account.rec_name,
-                        'party': party.rec_name,
-                        })
+                raise DepositError(
+                    gettext('account_deposit.msg_deposit_not_enough',
+                        account=account.rec_name,
+                        party=party.rec_name))
 
 
 class InvoiceLine(metaclass=PoolMeta):
diff -r 88ab745f9a55 -r 2170c41e3fe3 message.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml       Sat Dec 29 14:20:28 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_erase_party_deposit">
+            <field name="text">You cannot erase party "%(party)s" while they 
have deposit at company "%(company)s".</field>
+        </record>
+        <record model="ir.message" id="msg_deposit_not_enough">
+            <field name="text">The account "%(account)s" has not enough 
deposit from party "%(party)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r 88ab745f9a55 -r 2170c41e3fe3 party.py
--- a/party.py  Wed Nov 28 09:58:26 2018 +0100
+++ b/party.py  Sat Dec 29 14:20:28 2018 +0100
@@ -6,12 +6,15 @@
 from sql.aggregate import Sum
 from sql.conditionals import Coalesce
 
+from trytond.i18n import gettext
 from trytond.pool import PoolMeta, Pool
 from trytond.model import fields
 from trytond.pyson import Eval
 from trytond.transaction import Transaction
 from trytond.tools import grouped_slice, reduce_ids
 
+from trytond.modules.party.exceptions import EraseError
+
 
 __all__ = ['Party', 'PartyErase']
 
@@ -135,18 +138,9 @@
 class PartyErase(metaclass=PoolMeta):
     __name__ = 'party.erase'
 
-    @classmethod
-    def __setup__(cls):
-        super(PartyErase, cls).__setup__()
-        cls._error_messages.update({
-                'deposit': (
-                    'The party "%(party)s" can not be erased '
-                    'because he has deposit for the company "%(company)s".'),
-                })
-
     def check_erase_company(self, party, company):
         if party.deposit:
-            self.raise_user_error('deposit', {
-                    'party': party.rec_name,
-                    'company': company.rec_name,
-                    })
+            raise EraseError(
+                gettext('account_deposit.msg_erase_party_deposit',
+                    party=party.rec_name,
+                    company=company.rec_name))
diff -r 88ab745f9a55 -r 2170c41e3fe3 tryton.cfg
--- a/tryton.cfg        Wed Nov 28 09:58:26 2018 +0100
+++ b/tryton.cfg        Sat Dec 29 14:20:28 2018 +0100
@@ -20,4 +20,4 @@
     minimal_chart_pt.xml
     minimal_chart_ru.xml
     minimal_chart_sl.xml
-
+    message.xml

Reply via email to