mirror of
https://github.com/NaN-tic/trytond-production_process.git
synced 2023-12-14 05:53:01 +01:00
Automatically fill the route when creating operations linked to steps
From changeset-2f640ca #049129
This commit is contained in:
parent
97f6e5d837
commit
bedcd2127f
1 changed files with 20 additions and 25 deletions
|
@ -18,10 +18,17 @@ class Process(DeactivableMixin, ModelSQL, ModelView):
|
||||||
name = fields.Char('Name', required=True)
|
name = fields.Char('Name', required=True)
|
||||||
steps = fields.One2Many('production.process.step', 'process', 'Steps',
|
steps = fields.One2Many('production.process.step', 'process', 'Steps',
|
||||||
context={
|
context={
|
||||||
'from_process': Eval('id'),
|
'from_route': Eval('route'),
|
||||||
},)
|
},
|
||||||
|
states={
|
||||||
|
'readonly': ~Eval('route'),
|
||||||
|
}, depends=['route'])
|
||||||
bom = fields.Many2One('production.bom', 'BOM', required=True)
|
bom = fields.Many2One('production.bom', 'BOM', required=True)
|
||||||
route = fields.Many2One('production.route', 'Route', required=True)
|
route = fields.Many2One('production.route', 'Route', required=True,
|
||||||
|
states={
|
||||||
|
'readonly': Bool(Eval('steps', [0])),
|
||||||
|
},
|
||||||
|
depends=['steps'])
|
||||||
inputs = fields.Function(fields.One2Many('production.bom.input', None,
|
inputs = fields.Function(fields.One2Many('production.bom.input', None,
|
||||||
'Inputs'), 'get_bom_field')
|
'Inputs'), 'get_bom_field')
|
||||||
outputs = fields.Function(fields.One2Many('production.bom.output', None,
|
outputs = fields.Function(fields.One2Many('production.bom.output', None,
|
||||||
|
@ -248,16 +255,21 @@ class Operation(metaclass=PoolMeta):
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super(Operation, cls).__setup__()
|
super(Operation, cls).__setup__()
|
||||||
|
|
||||||
if not cls.route.states:
|
if not cls.route.states:
|
||||||
cls.route.states = {}
|
cls.route.states = {}
|
||||||
new_invisible = Eval('context', {}).get('from_step', 0) != 0
|
new_readonly = Eval('context', {}).get('from_route', 0) != 0
|
||||||
old_invisible = cls.route.states.get('invisible')
|
readonly = cls.route.states.get('readonly')
|
||||||
if old_invisible:
|
if readonly:
|
||||||
new_invisible = new_invisible | old_invisible
|
new_readonly = new_readonly | readonly
|
||||||
cls.route.states.update({
|
cls.route.states.update({
|
||||||
'invisible': new_invisible,
|
'readonly': new_readonly,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_route():
|
||||||
|
return Transaction().context.get('from_route')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, vlist):
|
def create(cls, vlist):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
|
@ -267,23 +279,6 @@ class Operation(metaclass=PoolMeta):
|
||||||
values['route'] = Step(values['step']).process.route.id
|
values['route'] = Step(values['step']).process.route.id
|
||||||
return super(Operation, cls).create(vlist)
|
return super(Operation, cls).create(vlist)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def default_route():
|
|
||||||
pool = Pool()
|
|
||||||
Process = pool.get('production.process')
|
|
||||||
Step = pool.get('production.process.step')
|
|
||||||
|
|
||||||
process_id = Transaction().context.get('from_process')
|
|
||||||
if process_id and process_id > 0:
|
|
||||||
process = Process(process_id)
|
|
||||||
return process.route.id
|
|
||||||
|
|
||||||
step_id = Transaction().context.get('from_step')
|
|
||||||
if step_id and step_id > 0:
|
|
||||||
step = Step(step_id)
|
|
||||||
if step.process:
|
|
||||||
return step.process.route.id
|
|
||||||
|
|
||||||
|
|
||||||
class BOM(metaclass=PoolMeta):
|
class BOM(metaclass=PoolMeta):
|
||||||
__name__ = 'production.bom'
|
__name__ = 'production.bom'
|
||||||
|
|
Loading…
Reference in a new issue