Remove lines that have not plan

This commit is contained in:
Raimon Esteve 2023-11-06 16:15:55 +01:00
parent b92142b0db
commit 153af1ecd8
1 changed files with 14 additions and 1 deletions

15
plan.py
View File

@ -449,8 +449,21 @@ class Plan(DeactivableMixin, ModelSQL, ModelView):
@classmethod
def delete(cls, plans):
pool = Pool()
CostLine = pool.get('product.cost.plan.cost')
Line = pool.get('product.cost.plan.product_line')
to_delete = []
to_delete2 = []
for plan in plans:
to_delete += plan.costs
to_delete2 += [line for line in plan.all_products
if line.plan is None]
with Transaction().set_context(reset_costs=True):
super(Plan, cls).delete(plans)
CostLine.delete(to_delete)
Line.delete(to_delete2)
super(Plan, cls).delete(plans)
class PlanBOM(ModelSQL, ModelView):