diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-02 18:48:32 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:24 +0100 | 
| commit | 265648d0a8232499d3468c198d4371833363d298 (patch) | |
| tree | 02a2ba40cad1698f8f3b7a1243492f69822b0c90 | |
| parent | 77cbfe3a5c67c5a844e87078eb4f0afb84770a97 (diff) | |
| download | Ishtar-265648d0a8232499d3468c198d4371833363d298.tar.bz2 Ishtar-265648d0a8232499d3468c198d4371833363d298.zip | |
No index for stationary containers
| -rw-r--r-- | archaeological_warehouse/migrations/0109_auto_20210202_1844.py | 24 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 11 | ||||
| -rw-r--r-- | archaeological_warehouse/tests.py | 46 | 
3 files changed, 77 insertions, 4 deletions
| diff --git a/archaeological_warehouse/migrations/0109_auto_20210202_1844.py b/archaeological_warehouse/migrations/0109_auto_20210202_1844.py new file mode 100644 index 000000000..a9e44b213 --- /dev/null +++ b/archaeological_warehouse/migrations/0109_auto_20210202_1844.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2021-02-02 18:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_warehouse', '0108_container_collection'), +    ] + +    operations = [ +        migrations.AlterField( +            model_name='container', +            name='index', +            field=models.IntegerField(blank=True, null=True, verbose_name='Container ID'), +        ), +        migrations.AlterUniqueTogether( +            name='container', +            unique_together=set([('location', 'container_type', 'parent', 'reference')]), +        ), +    ] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 77ae3c6d1..d80559acc 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -870,7 +870,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem,      parent = models.ForeignKey("Container", verbose_name=_("Parent container"),                                 on_delete=models.SET_NULL,                                 related_name="children", blank=True, null=True) -    index = models.IntegerField(_("Container ID"), default=0) +    index = models.IntegerField(_("Container ID"), blank=True, null=True)      old_reference = models.TextField(_("Old reference"), blank=True, default="")      external_id = models.TextField(_("External ID"), blank=True, default="")      auto_external_id = models.BooleanField( @@ -891,8 +891,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem,          verbose_name = _("Container")          verbose_name_plural = _("Containers")          ordering = ('cached_label',) -        unique_together = [('index', 'location'), -                           ('location', 'container_type', 'parent', +        unique_together = [('location', 'container_type', 'parent',                              'reference')]          permissions = (              ("view_container", "Can view all Containers"), @@ -972,6 +971,8 @@ class Container(DocumentItem, Merge, LightHistorizedItem,          return self.precise_location      def _generate_cached_location(self): +        if not self.index: +            return self.location.name          items = [self.location.name, str(self.index)]          cached_label = " - ".join(items)          return cached_label @@ -1365,6 +1366,8 @@ class Container(DocumentItem, Merge, LightHistorizedItem,                  self.collection_id = self.location_id              else:                  self.collection = self.location +        if self.container_type.stationary: +            return          q = Container.objects.filter(index=self.index, location=self.location)          if self.id:              q = q.exclude(id=self.id) @@ -1405,7 +1408,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem,          self._update_warehouse_max_division()          updated = False -        if not self.index: +        if not self.index and not self.container_type.stationary:              self.skip_history_when_saving = True              q = Container.objects.filter(responsible=self.responsible).exclude(                  pk=self.pk).order_by('-index') diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index 5ff09e202..93acafa9f 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -948,3 +948,49 @@ class ContainerTest(FindInit, TestCase):          self.assertEqual(container.location, self.alt_warehouse)          self.assertEqual(container.parent, None) +    def test_index(self): +        ct = models.ContainerType.objects.all()[0] +        ct.stationary = False +        ct.save() +        ct2 = models.ContainerType.objects.all()[1] +        ct2.stationary = True +        ct2.save() + +        q = models.Container.objects.filter( +            location=self.main_warehouse).order_by("-index") +        if q.count(): +            base_index = q.all()[0].index +        else: +            base_index = 0 +        container_1 = models.Container.objects.create( +            reference="Ref 1", +            location=self.main_warehouse, +            container_type=ct) +        self.assertEqual(models.Container.objects.get(pk=container_1.pk).index, +                         base_index + 1) +        container_2 = models.Container.objects.create( +            reference="Ref 2", +            location=self.main_warehouse, +            container_type=ct) +        self.assertEqual(models.Container.objects.get(pk=container_2.pk).index, +                         base_index + 2) +        container_3 = models.Container.objects.create( +            reference="Ref 3", +            location=self.main_warehouse, +            container_type=ct2) +        self.assertEqual(container_3.index, None) +        self.assertEqual(models.Container.objects.get(pk=container_3.pk).index, +                         None) +        container_4 = models.Container.objects.create( +            reference="Ref 4", +            location=self.main_warehouse, +            container_type=ct2) +        self.assertEqual(container_4.index, None) +        self.assertEqual(models.Container.objects.get(pk=container_4.pk).index, +                         None) +        container_5 = models.Container.objects.create( +            reference="Ref 5", +            location=self.main_warehouse, +            container_type=ct) +        self.assertEqual(models.Container.objects.get(pk=container_5.pk).index, +                         base_index + 3) | 
