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

        issue3672
diffstat:

 exceptions.py |   8 ++++++++
 message.xml   |  14 ++++++++++++++
 product.py    |  24 +++++++++---------------
 tryton.cfg    |   1 +
 4 files changed, 32 insertions(+), 15 deletions(-)

diffs (100 lines):

diff -r 5775e8e636c0 -r e70913d85aa6 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 UserError
+
+
+class UpdateCostPriceError(UserError):
+    pass
diff -r 5775e8e636c0 -r e70913d85aa6 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,14 @@
+<?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_product_change_cost_price">
+            <field name="text">You cannot change the cost price of a product 
which is associated to stock moves.
+You must use the "Update Cost Price" wizard.</field>
+        </record>
+        <record model="ir.message" id="msg_update_cost_price_same_account">
+            <field name="text">To update cost price, you must change the 
counterpart account "%(account)s".</field>
+        </record>
+    </data>
+</tryton>
diff -r 5775e8e636c0 -r e70913d85aa6 product.py
--- a/product.py        Mon Oct 01 12:54:50 2018 +0200
+++ b/product.py        Sat Dec 29 14:20:29 2018 +0100
@@ -3,6 +3,7 @@
 from decimal import Decimal
 
 from trytond import backend
+from trytond.i18n import gettext
 from trytond.model import ModelView, fields
 from trytond.wizard import Wizard, StateView, StateTransition, Button
 from trytond.pyson import Eval
@@ -12,6 +13,7 @@
 from trytond.modules.account_product.product import (
     account_used, template_property)
 from trytond.modules.product import price_digits
+from .exceptions import UpdateCostPriceError
 
 __all__ = ['Category', 'CategoryAccount', 'Template',
     'Product', 'UpdateCostPriceAsk',
@@ -183,12 +185,9 @@
     @classmethod
     def __setup__(cls):
         super(Template, cls).__setup__()
-        cls._modify_no_move.append(('cost_price', 'change_cost_price'))
-        cls._error_messages.update({
-                'change_cost_price': ('You cannot change the cost price for '
-                    'a product which is associated to stock moves.\n'
-                    'You must use the "Update Cost Price" wizard.'),
-                })
+        cls._modify_no_move.append(
+            ('cost_price',
+                'account_stock_continental.msg_product_change_cost_price'))
 
     @property
     @account_used('account_stock', 'account_category')
@@ -283,14 +282,6 @@
     create_move = StateTransition()
     update_price = StateTransition()
 
-    @classmethod
-    def __setup__(cls):
-        super(UpdateCostPrice, cls).__setup__()
-        cls._error_messages.update({
-                'same_account': ('The stock account and the counterpart can '
-                    'not be the same account'),
-                })
-
     def default_ask_price(self, fields):
         pool = Pool()
         Product = pool.get('product.product')
@@ -391,7 +382,10 @@
         Move = Pool().get('account.move')
 
         if self.show_move.counterpart == self.show_move.stock_account:
-            self.raise_user_error('same_account')
+            raise UpdateCostPriceError(
+                gettext('account_stock_continental'
+                    '.msg_update_cost_price_same_account',
+                    account=self.show_move.counterpart.rec_name))
         move = self.get_move()
         move.save()
         Move.post([move])
diff -r 5775e8e636c0 -r e70913d85aa6 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 12:54:50 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -19,3 +19,4 @@
     minimal_chart_pt.xml
     minimal_chart_ru.xml
     minimal_chart_sl.xml
+    message.xml

Reply via email to