No validate plan parent when copy a product plan

#162998
This commit is contained in:
Raimon Esteve 2023-10-26 10:27:34 +02:00
parent c8fa70cace
commit 9813e951e2
1 changed files with 12 additions and 3 deletions

15
plan.py
View File

@ -462,9 +462,10 @@ class Plan(DeactivableMixin, ModelSQL, ModelView):
_get_children(child)
new_plan, = super(Plan, self).copy([self], default=default)
lines = ProductLine.copy(self.products, default={
'plan': new_plan.id,
})
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:
@ -678,7 +679,15 @@ class PlanProductLine(ModelSQL, ModelView, tree(separator='/')):
@classmethod
def validate(cls, lines):
context = Transaction().context
super().validate(lines)
if not context.get('skip_validate_plan_parent', False):
cls._validate_plan_parent(lines)
@classmethod
def _validate_plan_parent(cls, lines):
for line in lines:
if ((line.parent and line.plan) or (not line.parent and not line.plan)):
raise UserError(gettext(