Compare commits

...

2 commits

Author SHA1 Message Date
Albert Cervera i Areny
d08a80d270 Fix tests. 2023-11-07 16:59:16 +01:00
Raimon Esteve
8d03eff9cc Delete cost plan and return UOM category in case all childreen has same category
#163212
2023-11-07 15:19:31 +01:00

17
plan.py
View file

@ -449,12 +449,20 @@ class Plan(DeactivableMixin, ModelSQL, ModelView):
@classmethod @classmethod
def delete(cls, plans): def delete(cls, plans):
CostLine = Pool().get('product.cost.plan.cost') pool = Pool()
CostLine = pool.get('product.cost.plan.cost')
Line = pool.get('product.cost.plan.product_line')
to_delete = [] to_delete = []
to_delete2 = []
for plan in plans: for plan in plans:
to_delete += plan.costs 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): with Transaction().set_context(reset_costs=True):
CostLine.delete(to_delete) CostLine.delete(to_delete)
Line.delete(to_delete2)
super(Plan, cls).delete(plans) super(Plan, cls).delete(plans)
@ -547,8 +555,11 @@ class PlanProductLine(ModelSQL, ModelView, tree(separator='/')):
@fields.depends('children', 'product', 'plan', '_parent_plan.uom') @fields.depends('children', 'product', 'plan', '_parent_plan.uom')
def on_change_with_uom_category(self, name=None): def on_change_with_uom_category(self, name=None):
if self.children and self.children[0].uom: if self.children:
return self.children[0].uom.category.id uoms = set([child.uom.category for child in self.children
if child.uom])
if len(uoms) == 1:
return list(uoms)[0].id
elif self.product: elif self.product:
return self.product.default_uom.category.id return self.product.default_uom.category.id
elif self.plan and self.plan.uom: elif self.plan and self.plan.uom: