From 3a15e586ca2ce1664f8d9c953530c28708904955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 22 Apr 2023 18:43:45 +0200 Subject: [PATCH] Delete on cascade locations Closes #3689 --- modules/stock/location.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/stock/location.py b/modules/stock/location.py index 42e32ffbdd..c3f4c45953 100644 --- a/modules/stock/location.py +++ b/modules/stock/location.py @@ -59,7 +59,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView): ], "Location type") type_string = type.translated('type') parent = fields.Many2One( - "stock.location", "Parent", + "stock.location", "Parent", ondelete='CASCADE', left="left", right="right", help="Used to add structure above the location.") left = fields.Integer('Left', required=True) @@ -573,8 +573,16 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView): warehouse=warehouse.rec_name)) @classmethod - def delete(cls, *args): - super().delete(*args) + def delete(cls, locations): + # Delete also required children as CASCADING is done separately + extra_locations = [] + for location in locations: + extra_locations.extend(filter(None, [ + location.input_location, + location.output_location, + location.storage_location, + ])) + super().delete(locations + extra_locations) cls._default_warehouse_cache.clear() @classmethod