From ef17e1695c8dc0f0b59a413ada97add40f2c1203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Mon, 5 Feb 2024 01:07:05 +0100 Subject: [PATCH] stock_warehouse_archive: fix purging inventory --- .../models/stock_warehouse.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stock_warehouse_archive/models/stock_warehouse.py b/stock_warehouse_archive/models/stock_warehouse.py index 0029b4e4..7f14b85f 100644 --- a/stock_warehouse_archive/models/stock_warehouse.py +++ b/stock_warehouse_archive/models/stock_warehouse.py @@ -133,6 +133,9 @@ def _action_cancel_related_move_from_location(self, locations): def _action_purge_with_inventory(self, locations): for location in locations: if location.usage == "internal": + if not location.active: + location.active = True + inventory = self.env["stock.inventory"].create( { "name": _("Archive %(warehouse)s %(location)s") @@ -142,11 +145,14 @@ def _action_purge_with_inventory(self, locations): } ) inventory.action_start() - - # Compatibility with stock_inventory_location_state - if "sub_location_ids" in inventory._fields: - inventory.sub_location_ids.state = "done" - inventory._action_done() + if inventory.line_ids: + # Compatibility with stock_inventory_location_state + if "sub_location_ids" in inventory._fields: + inventory.sub_location_ids.state = "done" + inventory._action_done() + else: + inventory.action_cancel_draft() + inventory.unlink() def force_archive(self):