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.pyson import Bool, Eval
|
||||||
from trytond.modules.production.production import BOM_CHANGES
|
from trytond.modules.production.production import BOM_CHANGES
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
|
from trytond.i18n import gettext
|
||||||
|
from trytond.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Process', 'Step', 'BOMInput', 'BOMOutput', 'Operation', 'BOM',
|
__all__ = ['Process', 'Step', 'BOMInput', 'BOMOutput', 'Operation', 'BOM',
|
||||||
|
@ -291,40 +293,22 @@ class Operation(metaclass=PoolMeta):
|
||||||
class BOM(metaclass=PoolMeta):
|
class BOM(metaclass=PoolMeta):
|
||||||
__name__ = 'production.bom'
|
__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
|
@classmethod
|
||||||
def delete(cls, boms):
|
def delete(cls, boms):
|
||||||
Process = Pool().get('production.process')
|
Process = Pool().get('production.process')
|
||||||
processes = Process.search([('bom', 'in', [x.id for x in boms])],
|
processes = Process.search([('bom', 'in', [x.id for x in boms])],
|
||||||
limit=1)
|
limit=1)
|
||||||
if processes:
|
if processes:
|
||||||
cls.raise_user_error('cannot_delete_with_process', {
|
raise UserError(gettext(
|
||||||
'bom': processes[0].bom.rec_name,
|
'production_process.cannot_delete_with_process',
|
||||||
'process': processes[0].rec_name,
|
bom=processes[0].bom.rec_name,
|
||||||
})
|
process=processes[0].rec_name))
|
||||||
super(BOM, cls).delete(boms)
|
super(BOM, cls).delete(boms)
|
||||||
|
|
||||||
|
|
||||||
class Route(metaclass=PoolMeta):
|
class Route(metaclass=PoolMeta):
|
||||||
__name__ = 'production.route'
|
__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
|
@classmethod
|
||||||
def delete(cls, routes):
|
def delete(cls, routes):
|
||||||
Process = Pool().get('production.process')
|
Process = Pool().get('production.process')
|
||||||
|
@ -332,10 +316,10 @@ class Route(metaclass=PoolMeta):
|
||||||
limit=1)
|
limit=1)
|
||||||
if processes:
|
if processes:
|
||||||
process, = processes
|
process, = processes
|
||||||
cls.raise_user_error('cannot_delete_with_process', {
|
raise UserError(gettext(
|
||||||
'route': process.route.rec_name,
|
'production_process.cannot_delete_with_process_route',
|
||||||
'process': process.rec_name,
|
route=process.route.rec_name,
|
||||||
})
|
process=process.rec_name))
|
||||||
super(Route, cls).delete(routes)
|
super(Route, cls).delete(routes)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[tryton]
|
[tryton]
|
||||||
version=4.8.0
|
version=4.9.0
|
||||||
depends:
|
depends:
|
||||||
production
|
production
|
||||||
production_operation
|
production_operation
|
||||||
|
@ -8,3 +8,4 @@ extras_depend:
|
||||||
xml:
|
xml:
|
||||||
product.xml
|
product.xml
|
||||||
production.xml
|
production.xml
|
||||||
|
message.xml
|
||||||
|
|
Loading…
Reference in New Issue