Ugly patch to allow copying processes.
This commit is contained in:
parent
8cad5817c0
commit
b0f180eec1
|
@ -84,16 +84,16 @@ class Process(ModelSQL, ModelView):
|
||||||
return super(Process, cls).create(with_boms + without_boms)
|
return super(Process, cls).create(with_boms + without_boms)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, steps):
|
def delete(cls, processes):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
BOM = pool.get('production.bom')
|
BOM = pool.get('production.bom')
|
||||||
Route = pool.get('production.route')
|
Route = pool.get('production.route')
|
||||||
boms = []
|
boms = []
|
||||||
routes = []
|
routes = []
|
||||||
for step in steps:
|
for process in processes:
|
||||||
boms.append(step.bom)
|
boms.append(process.bom)
|
||||||
routes.append(step.route)
|
routes.append(process.route)
|
||||||
super(Process, cls).delete(steps)
|
super(Process, cls).delete(processes)
|
||||||
BOM.delete(boms)
|
BOM.delete(boms)
|
||||||
Route.delete(routes)
|
Route.delete(routes)
|
||||||
|
|
||||||
|
@ -108,6 +108,52 @@ class Process(ModelSQL, ModelView):
|
||||||
if factor is not None:
|
if factor is not None:
|
||||||
return factor
|
return factor
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def copy(cls, processes, default=None):
|
||||||
|
|
||||||
|
def update_steps(old_lines, new_steps, new_lines):
|
||||||
|
old_map = {}
|
||||||
|
for line in old_lines:
|
||||||
|
old_map[line.product.id] = line.step.name
|
||||||
|
new_map = {}
|
||||||
|
for step in new_steps:
|
||||||
|
new_map[step.name] = step.id
|
||||||
|
for line in new_lines:
|
||||||
|
line.step = new_map[old_map[line.product.id]]
|
||||||
|
line.save()
|
||||||
|
|
||||||
|
pool = Pool()
|
||||||
|
BOM = pool.get('production.bom')
|
||||||
|
Route = pool.get('production.route')
|
||||||
|
if default is None:
|
||||||
|
default = {}
|
||||||
|
#for process in processes:
|
||||||
|
#if 'bom' not in default:
|
||||||
|
# default['bom'] = None
|
||||||
|
#if 'route' not in default:
|
||||||
|
# default['route'] = None
|
||||||
|
#return super(Process, cls).copy(processes, default)
|
||||||
|
|
||||||
|
res = []
|
||||||
|
for process in processes:
|
||||||
|
bom, = BOM.copy([process.bom])
|
||||||
|
for line in process.bom.inputs:
|
||||||
|
|
||||||
|
route, = Route.copy([process.route])
|
||||||
|
if 'bom' not in default:
|
||||||
|
default['bom'] = bom
|
||||||
|
if 'route' not in default:
|
||||||
|
default['route'] = route
|
||||||
|
new, = super(Process, cls).copy([process], default)
|
||||||
|
res.append(new)
|
||||||
|
|
||||||
|
update_steps(process.bom.inputs, new.steps, new.bom.inputs)
|
||||||
|
update_steps(process.bom.outputs, new.steps, new.bom.outputs)
|
||||||
|
|
||||||
|
|
||||||
|
# print "DEFAULTING: ", default
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class Step(ModelSQL, ModelView):
|
class Step(ModelSQL, ModelView):
|
||||||
'Production Process Step'
|
'Production Process Step'
|
||||||
|
@ -134,6 +180,15 @@ class Step(ModelSQL, ModelView):
|
||||||
table, _ = tables[None]
|
table, _ = tables[None]
|
||||||
return [table.sequence == None, table.sequence]
|
return [table.sequence == None, table.sequence]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def copy(cls, steps, default=None):
|
||||||
|
if default is None:
|
||||||
|
default = {}
|
||||||
|
default['inputs'] = None
|
||||||
|
default['outputs'] = None
|
||||||
|
default['operations'] = None
|
||||||
|
return super(Step, cls).copy(steps, default)
|
||||||
|
|
||||||
|
|
||||||
class BOMMixin:
|
class BOMMixin:
|
||||||
step = fields.Many2One('production.process.step', 'Step')
|
step = fields.Many2One('production.process.step', 'Step')
|
||||||
|
|
Loading…
Reference in New Issue