minified copy() plans
This commit is contained in:
parent
9813e951e2
commit
41921a8b71
37
plan.py
37
plan.py
|
@ -443,39 +443,30 @@ class Plan(DeactivableMixin, ModelSQL, ModelView):
|
|||
default = {}
|
||||
else:
|
||||
default = default.copy()
|
||||
default['products'] = None
|
||||
default['bom'] = None
|
||||
default.setdefault('bom', None)
|
||||
|
||||
with Transaction().set_context(skip_validate_plan_parent=True):
|
||||
new_plans = super().copy(plans, default=default)
|
||||
|
||||
# sure product.cost_plan.product_line that has parent, set null the plan
|
||||
cls._set_lines_plan_none(new_plans)
|
||||
|
||||
new_plans = []
|
||||
for plan in plans:
|
||||
new_plans.append(plan._copy_plan(default))
|
||||
return new_plans
|
||||
|
||||
def _copy_plan(self, default):
|
||||
@classmethod
|
||||
def _set_lines_plan_none(cls, plans):
|
||||
ProductLine = Pool().get('product.cost.plan.product_line')
|
||||
|
||||
product_lines = []
|
||||
|
||||
def _get_children(line):
|
||||
product_lines.append(line)
|
||||
for child in line.children:
|
||||
_get_children(child)
|
||||
|
||||
new_plan, = super(Plan, self).copy([self], default=default)
|
||||
with Transaction().set_context(skip_validate_plan_parent=True):
|
||||
lines = ProductLine.copy(self.products, default={
|
||||
'plan': new_plan.id,
|
||||
})
|
||||
|
||||
# sure product.cost_plan.product_line that has parent, set null the plan
|
||||
for line in lines:
|
||||
for child in line.children:
|
||||
_get_children(child)
|
||||
for plan in plans:
|
||||
for line in plan.all_products:
|
||||
if line.parent:
|
||||
product_lines.append(line)
|
||||
|
||||
# set plan to None
|
||||
ProductLine.write(product_lines, {'plan': None})
|
||||
|
||||
return new_plan
|
||||
|
||||
@classmethod
|
||||
def delete(cls, plans):
|
||||
CostLine = Pool().get('product.cost.plan.cost')
|
||||
|
|
Loading…
Reference in New Issue