Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier committed 2018-12-29 14:20:29 +01:00
1 parent b6d165185f
commit 8d31bc3ffe
4 files changed
+52 -37

No files matched your search

+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 UserError, UserWarning
class LotExpiredError(UserError):
pass
class LotExpiredWarning(UserWarning):
pass
+16
View File
@@ -0,0 +1,16 @@
<?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_lot_modify_expiration_date_period_close">
<field name="text">You cannot modify expiration dates of lot "%(lot)s because it is used on move "%(move)s" in a closed period.</field>
</record>
<record model="ir.message" id="msg_move_lot_expired">
<field name="text">You cannot process move "%(move)s" because its lot "%(lot)s" has expired.</field>
</record>
<record model="ir.message" id="msg_period_close_sled">
<field name="text">You cannot close periods before the expiration of lot "%(lot)s" (%(date)s).</field>
</record>
</data>
</tryton>
+23 -37
View File
@@ -5,12 +5,17 @@ import datetime
from sql import Union, Join, Select, Table, Null, As
from sql.conditionals import Greatest
from trytond.i18n import gettext
from trytond.pool import PoolMeta, Pool
from trytond.model import ModelView, Workflow, ModelSQL, ValueMixin, fields
from trytond.model.exceptions import AccessError
from trytond.pyson import Eval
from trytond.transaction import Transaction
from trytond.tools import grouped_slice
from trytond.modules.stock.exceptions import PeriodCloseError
from .exceptions import LotExpiredError, LotExpiredWarning
__all__ = ['Configuration', 'ConfigurationLotShelfLife',
'Lot', 'Move', 'Period']
@@ -66,15 +71,6 @@ class Lot(metaclass=PoolMeta):
fields.Selection(DATE_STATE, 'Expiration State'),
'on_change_with_expiration_state')
@classmethod
def __setup__(cls):
super(Lot, cls).__setup__()
cls._error_messages.update({
'period_closed_expiration_dates': ('You can not modify '
'the expiration dates of lot "%(lot)s" because '
'it is used on a move "%(move)s" in a closed period'),
})
@fields.depends('product')
def on_change_with_shelf_life_expiration_state(self, name=None):
if self.product:
@@ -138,23 +134,16 @@ class Lot(metaclass=PoolMeta):
]], limit=1)
if moves:
move, = moves
cls.raise_user_error('period_closed_expiration_dates', {
'lot': move.lot.rec_name,
'move': move.rec_name,
})
raise AccessError(
gettext('stock_lot_sled'
'.msg_lot_modify_expiration_date_period_close',
lot=move.lot.rec_name,
move=move.rec_name))
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
@classmethod
def __setup__(cls):
super(Move, cls).__setup__()
cls._error_messages.update({
'expiration_dates': ('The lot "%(lot)s" '
'on move "%(move)s" is expired'),
})
@classmethod
@ModelView.button
@Workflow.transition('done')
@@ -191,6 +180,7 @@ class Move(metaclass=PoolMeta):
Group = pool.get('res.group')
User = pool.get('res.user')
ModelData = pool.get('ir.model.data')
Warning = pool.get('res.user.warning')
types = cls.check_expiration_dates_types()
locations = cls.check_expiration_dates_locations()
@@ -219,10 +209,15 @@ class Move(metaclass=PoolMeta):
'lot': move.lot.rec_name if move.lot else '',
}
if not in_group():
cls.raise_user_error('expiration_dates', values)
raise LotExpiredError(
gettext('stock_lot_sled.msg_move_lot_expired',
**values))
else:
cls.raise_user_warning('%s.check_expiration_dates' % move,
'expiration_dates', values)
warning_name = '%s.check_expiration_dates' % move
if Warning.check(warning_name):
raise LotExpiredWarning(warning_name,
gettext('stock_lot_sled.msg_move_lot_expired',
**values))
@classmethod
def compute_quantities_query(cls, location_ids, with_childs=False,
@@ -327,15 +322,6 @@ class Move(metaclass=PoolMeta):
class Period(metaclass=PoolMeta):
__name__ = 'stock.period'
@classmethod
def __setup__(cls):
super(Period, cls).__setup__()
cls._error_messages.update({
'close_period_sled': ('You can not close a period '
'before the Shelf Live Expiration Date "%(date)s" '
'of Lot "%(lot)s"'),
})
@classmethod
@ModelView.button
def close(cls, periods):
@@ -367,7 +353,7 @@ class Period(metaclass=PoolMeta):
lot_id, = lot_id
lot = Lot(lot_id)
lang = Lang.get()
cls.raise_user_error('close_period_sled', {
'date': lang.strftime(lot.shelf_life_expiration_date),
'lot': lot.rec_name,
})
raise PeriodCloseError(
gettext('stock_lot_sled.msg_period_close_sled',
lot=lot.rec_name,
date=lang.strftime(lot.shelf_life_expiration_date)))
+1
View File
@@ -8,3 +8,4 @@ depends:
xml:
stock.xml
product.xml
message.xml