diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-04-06 12:31:38 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | 0f96790ca2866d205b262c96ddb1b155abb80ef6 (patch) | |
tree | 1ac684557b5b6d2b7457b80040f8955e0db19d07 /archaeological_warehouse/management/commands/migrate_to_new_container_management.py | |
parent | 8b69114b1932329283f3563077a3cb53149af7c8 (diff) | |
download | Ishtar-0f96790ca2866d205b262c96ddb1b155abb80ef6.tar.bz2 Ishtar-0f96790ca2866d205b262c96ddb1b155abb80ef6.zip |
New container localisation - adapt sheets, imports
Diffstat (limited to 'archaeological_warehouse/management/commands/migrate_to_new_container_management.py')
-rw-r--r-- | archaeological_warehouse/management/commands/migrate_to_new_container_management.py | 13 |
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 |