Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:30 +01:00
parent 41456f1ae5
commit 407710cb1d
5 changed files with 58 additions and 31 deletions
+12
View File
@@ -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
+24
View File
@@ -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>
+9 -19
View File
@@ -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']
@@ -105,22 +108,6 @@ class OrderPoint(ModelSQL, ModelView):
unit_digits = fields.Function(fields.Integer('Unit Digits'),
'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()
@@ -194,8 +181,10 @@ class OrderPoint(ModelSQL, ModelView):
('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 @@ class OrderPoint(ModelSQL, ModelView):
]
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)
+12 -12
View File
@@ -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']
@@ -21,14 +24,6 @@ class StockSupply(Wizard):
internal = StateAction('stock.act_shipment_internal_form')
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 @@ class StockSupply(Wizard):
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 @@ class StockSupply(Wizard):
('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
+1
View File
@@ -15,3 +15,4 @@ xml:
product.xml
location.xml
stock.xml
message.xml