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

        issue3672
diffstat:

 message.xml                          |  10 ++++++++++
 purchase.py                          |  22 +++++++++-------------
 tests/scenario_analytic_purchase.rst |   2 +-
 tryton.cfg                           |   1 +
 4 files changed, 21 insertions(+), 14 deletions(-)

diffs (84 lines):

diff -r 050a55fc93b7 -r 19849c6554d3 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_analytic_account_required_for_quotation">
+            <field name="text">To get a quote for purchase "%(purchase)s", you 
must enter a analytic account for "%(roots)s" on line "%(line)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r 050a55fc93b7 -r 19849c6554d3 purchase.py
--- a/purchase.py       Mon Oct 01 15:15:21 2018 +0200
+++ b/purchase.py       Sat Dec 29 14:20:29 2018 +0100
@@ -1,10 +1,12 @@
 # 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.model import fields
 from trytond.pool import Pool, PoolMeta
 from trytond.pyson import Eval, If
 
 from trytond.modules.analytic_account import AnalyticMixin
+from trytond.modules.purchase.exceptions import PurchaseQuotationError
 
 __all__ = ['Purchase', 'PurchaseLine', 'AnalyticAccountEntry']
 
@@ -12,14 +14,6 @@
 class Purchase(metaclass=PoolMeta):
     __name__ = "purchase.purchase"
 
-    @classmethod
-    def __setup__(cls):
-        super(Purchase, cls).__setup__()
-        cls._error_messages.update({
-                'analytic_account_required': ('Analytic account is required '
-                    'for "%(roots)s" on line "%(line)s".'),
-                })
-
     def check_for_quotation(self):
         pool = Pool()
         Account = pool.get('analytic_account.account')
@@ -36,11 +30,13 @@
             analytic_roots = {e.root for e in line.analytic_accounts
                 if e.account}
             if not mandatory_roots <= analytic_roots:
-                self.raise_user_error('analytic_account_required', {
-                        'line': line.rec_name,
-                        'roots': ', '.join(x.rec_name
-                            for x in mandatory_roots - analytic_roots),
-                        })
+                raise PurchaseQuotationError(
+                    gettext('analytic_purchase'
+                        '.msg_analytic_account_required_for_quotation',
+                        purchase=self.rec_name,
+                        line=line.rec_name,
+                        roots=', '.join(x.rec_name
+                            for x in mandatory_roots - analytic_roots)))
 
 
 class PurchaseLine(AnalyticMixin, metaclass=PoolMeta):
diff -r 050a55fc93b7 -r 19849c6554d3 tests/scenario_analytic_purchase.rst
--- a/tests/scenario_analytic_purchase.rst      Mon Oct 01 15:15:21 2018 +0200
+++ b/tests/scenario_analytic_purchase.rst      Sat Dec 29 14:20:29 2018 +0100
@@ -184,7 +184,7 @@
     >>> purchase.click('quote')  # doctest: +IGNORE_EXCEPTION_DETAIL
     Traceback (most recent call last):
         ...
-    UserError: ...
+    PurchaseQuotationError: ...
     >>> purchase_line, = purchase.lines
     >>> entry, mandatory_entry = purchase_line.analytic_accounts
     >>> mandatory_entry.account = mandatory_analytic_account
diff -r 050a55fc93b7 -r 19849c6554d3 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 15:15:21 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -6,3 +6,4 @@
     purchase
 xml:
     purchase.xml
+    message.xml

Reply via email to