changeset 6ce2d561c3ed in modules/stock_supply:default
details:
https://hg.tryton.org/modules/stock_supply?cmd=changeset;node=6ce2d561c3ed
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
exceptions.py | 12 ++++++++++++
message.xml | 24 ++++++++++++++++++++++++
order_point.py | 28 +++++++++-------------------
stock.py | 24 ++++++++++++------------
tryton.cfg | 1 +
5 files changed, 58 insertions(+), 31 deletions(-)
diffs (180 lines):
diff -r b17fefe97cf8 -r 6ce2d561c3ed exceptions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py Sat Dec 29 14:20:30 2018 +0100
@@ -0,0 +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.exceptions import UserWarning
+from trytond.model.exceptions import ValidationError
+
+
+class SupplyWarning(UserWarning):
+ pass
+
+
+class OrderPointValidationError(ValidationError):
+ pass
diff -r b17fefe97cf8 -r 6ce2d561c3ed message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:30 2018 +0100
@@ -0,0 +1,24 @@
+<?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_order_point_unique">
+ <field name="text">Only one order point is allowed for each
product-location pair.</field>
+ </record>
+ <record model="ir.message"
id="msg_order_point_concurrent_provisioning_location_internal">
+ <field name="text">You cannot define for the same product two
order points with opposite locations
+(from "Storage Location" to "Provisioning Location" and vice versa).</field>
+ </record>
+ <record model="ir.message"
id="msg_order_point_concurrent_overflowing_location_internal">
+ <field name="text">You cannot define for the same product two
order points with opposite locations
+(from "Overflowing Location" to "Provisioning Location" and vice
versa).</field>
+ </record>
+ <record model="ir.message" id="msg_late_supplier_moves">
+ <field name="text">There are some supplier moves that are
late.</field>
+ </record>
+ <record model="ir.message" id="msg_late_customer_moves">
+ <field name="text">There are some customer moves that are
late.</field>
+ </record>
+ </data>
+</tryton>
diff -r b17fefe97cf8 -r 6ce2d561c3ed order_point.py
--- a/order_point.py Mon Nov 12 17:20:07 2018 +0100
+++ b/order_point.py Sat Dec 29 14:20:30 2018 +0100
@@ -2,10 +2,13 @@
# this repository contains the full copyright notices and license terms.
from sql import Null
+from trytond.i18n import gettext
from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import If, Equal, Eval, Not, In
from trytond.transaction import Transaction
+from .exceptions import OrderPointValidationError
+
__all__ = ['OrderPoint']
@@ -106,22 +109,6 @@
'get_unit_digits')
@classmethod
- def __setup__(cls):
- super(OrderPoint, cls).__setup__()
- cls._error_messages.update({
- 'unique_op': ('Only one order point is allowed '
- 'for each product-location pair.'),
- 'concurrent_provisioning_location_internal_op': ('You can not '
- 'define on the same product two order points with '
- 'opposite locations (from "Storage Location" to '
- '"Provisioning Location" and vice versa).'),
- 'concurrent_overflowing_location_internal_op': ('You can not '
- 'define on the same product two order points with '
- 'opposite locations (from "Storage Location" to '
- '"Overflowing Location" and vice versa).'),
- })
-
- @classmethod
def __register__(cls, module_name):
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
@@ -194,8 +181,10 @@
('type', '=', 'internal')]
query.append(arg)
if query and cls.search(['OR'] + query):
- cls.raise_user_error(
- 'concurrent_%s_internal_op' % location_name)
+ raise OrderPointValidationError(
+ gettext('stock_supply'
+ '.msg_order_point_concurrent_%s_internal' %
+ location_name))
@staticmethod
def _type2field(type=None):
@@ -226,7 +215,8 @@
]
query.append(arg)
if cls.search(query):
- cls.raise_user_error('unique_op')
+ raise OrderPointValidationError(
+ gettext('stock_supply.msg_order_point_unique'))
def get_rec_name(self, name):
return "%s@%s" % (self.product.name, self.location.name)
diff -r b17fefe97cf8 -r 6ce2d561c3ed stock.py
--- a/stock.py Mon Nov 12 17:20:07 2018 +0100
+++ b/stock.py Sat Dec 29 14:20:30 2018 +0100
@@ -1,10 +1,13 @@
# 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 Pool
from trytond.model import ModelView
from trytond.wizard import (Wizard, StateView, StateAction, StateTransition,
Button)
+from .exceptions import SupplyWarning
+
__all__ = ['StockSupply', 'StockSupplyStart']
@@ -22,14 +25,6 @@
purchase = StateAction('purchase_request.act_purchase_request_form')
@classmethod
- def __setup__(cls):
- super(StockSupply, cls).__setup__()
- cls._error_messages.update({
- 'late_supplier_moves': 'There are some late supplier moves.',
- 'late_customer_moves': 'There are some late customer moves.',
- })
-
- @classmethod
def types(cls):
return ['internal', 'purchase']
@@ -46,6 +41,7 @@
Move = pool.get('stock.move')
ShipmentInternal = pool.get('stock.shipment.internal')
Date = pool.get('ir.date')
+ Warning = pool.get('res.user.warning')
today = Date.today()
if Move.search([
('from_location.type', '=', 'supplier'),
@@ -53,16 +49,20 @@
('state', '=', 'draft'),
('planned_date', '<', today),
], order=[]):
- self.raise_user_warning('%s.supplier@%s' % (self.__name__, today),
- 'late_supplier_moves')
+ name = '%s.supplier@%s' % (self.__name__, today)
+ if Warning.check(name):
+ raise SupplyWarning(name,
+ gettext('stock_supply.msg_late_supplier_moves'))
if Move.search([
('from_location.type', '=', 'storage'),
('to_location.type', '=', 'customer'),
('state', '=', 'draft'),
('planned_date', '<', today),
], order=[]):
- self.raise_user_warning('%s.customer@%s' % (self.__name__, today),
- 'late_customer_moves')
+ name = '%s..customer@%s' % (self.__name__, today)
+ if Warning.check(name):
+ raise SupplyWarning(name,
+ gettext('stock_supply.msg_late_customer_moves'))
first = True
created = False
diff -r b17fefe97cf8 -r 6ce2d561c3ed tryton.cfg
--- a/tryton.cfg Mon Nov 12 17:20:07 2018 +0100
+++ b/tryton.cfg Sat Dec 29 14:20:30 2018 +0100
@@ -15,3 +15,4 @@
product.xml
location.xml
stock.xml
+ message.xml