summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/management
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/management')
-rw-r--r--archaeological_warehouse/management/commands/migrate_to_new_container_management.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/archaeological_warehouse/management/commands/migrate_to_new_container_management.py b/archaeological_warehouse/management/commands/migrate_to_new_container_management.py
index b5885cbf0..d8f701793 100644
--- a/archaeological_warehouse/management/commands/migrate_to_new_container_management.py
+++ b/archaeological_warehouse/management/commands/migrate_to_new_container_management.py
@@ -30,18 +30,23 @@ class Command(BaseCommand):
def handle(self, *args, **options):
to_update = models.Container.objects.filter(
- division__pk__isnull=False)
+ division__pk__isnull=False, parent__isnull=True)
container_types = {}
created_nb = 0
for div_type in models.WarehouseDivision.objects.all():
container_type, c = models.ContainerType.objects.get_or_create(
txt_idx=slugify(div_type.label),
- defaults={"label": div_type.label})
+ defaults={"label": div_type.label,
+ "stationary": True})
if c:
created_nb += 1
sys.stdout.write("-> {} created\n".format(
div_type.label))
container_types[div_type.pk] = container_type
+ for wdl in models.WarehouseDivisionLink.objects.all():
+ wdl.container_type = container_types[wdl.division_id]
+ wdl.save()
+
if created_nb:
sys.stdout.write("* {} container types created\n".format(
created_nb))
@@ -50,10 +55,10 @@ class Command(BaseCommand):
potential_duplicate = {}
data = [("id", "warehouse", "reference",
"old cached division", "new cached division")]
- for idx, container in enumerate(models.Container.objects.filter(
- division__pk__isnull=False).all()):
+ for idx, container in enumerate(to_update.values("id").all()):
sys.stdout.write("* Updating: {}/{}\r".format(idx + 1, to_be_done))
sys.stdout.flush()
+ container = models.Container.objects.get(pk=container["id"])
if container.responsible_id not in potential_duplicate:
potential_duplicate[container.responsible_id] = {}
parent = None