Add ir.message and use UserWarning/UserError
This commit is contained in:
parent
19a3f45b31
commit
543110c3dc
|
@ -0,0 +1,13 @@
|
|||
<?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="cannot_delete_with_process">
|
||||
<field name="text">BOM "%(bom)s" cannot be removed because it was created by process "%(process)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="cannot_delete_with_process_route">
|
||||
<field name="text">Route "%(route)s" cannot be removed because it was created by process "%(process)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
|
@ -4,6 +4,8 @@ from trytond.pool import Pool, PoolMeta
|
|||
from trytond.pyson import Bool, Eval
|
||||
from trytond.modules.production.production import BOM_CHANGES
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
|
||||
__all__ = ['Process', 'Step', 'BOMInput', 'BOMOutput', 'Operation', 'BOM',
|
||||
|
@ -291,40 +293,22 @@ class Operation(metaclass=PoolMeta):
|
|||
class BOM(metaclass=PoolMeta):
|
||||
__name__ = 'production.bom'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(BOM, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'cannot_delete_with_process': ('BOM "%(bom)s" cannot be '
|
||||
'removed because it was created by process '
|
||||
'"%(process)s".'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def delete(cls, boms):
|
||||
Process = Pool().get('production.process')
|
||||
processes = Process.search([('bom', 'in', [x.id for x in boms])],
|
||||
limit=1)
|
||||
if processes:
|
||||
cls.raise_user_error('cannot_delete_with_process', {
|
||||
'bom': processes[0].bom.rec_name,
|
||||
'process': processes[0].rec_name,
|
||||
})
|
||||
raise UserError(gettext(
|
||||
'production_process.cannot_delete_with_process',
|
||||
bom=processes[0].bom.rec_name,
|
||||
process=processes[0].rec_name))
|
||||
super(BOM, cls).delete(boms)
|
||||
|
||||
|
||||
class Route(metaclass=PoolMeta):
|
||||
__name__ = 'production.route'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Route, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'cannot_delete_with_process': ('Route "%(route)s" cannot be '
|
||||
'removed because it was created by process '
|
||||
'"%(process)s".'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def delete(cls, routes):
|
||||
Process = Pool().get('production.process')
|
||||
|
@ -332,10 +316,10 @@ class Route(metaclass=PoolMeta):
|
|||
limit=1)
|
||||
if processes:
|
||||
process, = processes
|
||||
cls.raise_user_error('cannot_delete_with_process', {
|
||||
'route': process.route.rec_name,
|
||||
'process': process.rec_name,
|
||||
})
|
||||
raise UserError(gettext(
|
||||
'production_process.cannot_delete_with_process_route',
|
||||
route=process.route.rec_name,
|
||||
process=process.rec_name))
|
||||
super(Route, cls).delete(routes)
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=4.8.0
|
||||
version=4.9.0
|
||||
depends:
|
||||
production
|
||||
production_operation
|
||||
|
@ -8,3 +8,4 @@ extras_depend:
|
|||
xml:
|
||||
product.xml
|
||||
production.xml
|
||||
message.xml
|
||||
|
|
Loading…
Reference in New Issue