Skip to content

Commit ef17e16

Browse files
committed
stock_warehouse_archive: fix purging inventory
1 parent 0fe329e commit ef17e16

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stock_warehouse_archive/models/stock_warehouse.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def _action_cancel_related_move_from_location(self, locations):
133133
def _action_purge_with_inventory(self, locations):
134134
for location in locations:
135135
if location.usage == "internal":
136+
if not location.active:
137+
location.active = True
138+
136139
inventory = self.env["stock.inventory"].create(
137140
{
138141
"name": _("Archive %(warehouse)s %(location)s")
@@ -142,11 +145,14 @@ def _action_purge_with_inventory(self, locations):
142145
}
143146
)
144147
inventory.action_start()
145-
146-
# Compatibility with stock_inventory_location_state
147-
if "sub_location_ids" in inventory._fields:
148-
inventory.sub_location_ids.state = "done"
149-
inventory._action_done()
148+
if inventory.line_ids:
149+
# Compatibility with stock_inventory_location_state
150+
if "sub_location_ids" in inventory._fields:
151+
inventory.sub_location_ids.state = "done"
152+
inventory._action_done()
153+
else:
154+
inventory.action_cancel_draft()
155+
inventory.unlink()
150156

151157
def force_archive(self):
152158

0 commit comments

Comments
 (0)