diff options
| -rw-r--r-- | archaeological_warehouse/migrations/0105_auto_20200407_1021.py | 20 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 16 | ||||
| -rw-r--r-- | archaeological_warehouse/tests.py | 35 | ||||
| -rw-r--r-- | ishtar_common/migrations/0203_auto_20200407_1142.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 3 | 
5 files changed, 89 insertions, 5 deletions
diff --git a/archaeological_warehouse/migrations/0105_auto_20200407_1021.py b/archaeological_warehouse/migrations/0105_auto_20200407_1021.py new file mode 100644 index 000000000..7465afd08 --- /dev/null +++ b/archaeological_warehouse/migrations/0105_auto_20200407_1021.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-04-07 10:21 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_warehouse', '0104_auto_container_views'), +    ] + +    operations = [ +        migrations.AlterUniqueTogether( +            name='container', +            unique_together=set([('index', 'responsible'), +                                 ('location', 'container_type', 'parent', 'reference')]), +        ), +    ] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index c4b26e3d1..c9e0ad4aa 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -724,10 +724,12 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,      DISABLE_POLYGONS = False      class Meta: -        verbose_name = _(u"Container") -        verbose_name_plural = _(u"Containers") +        verbose_name = _("Container") +        verbose_name_plural = _("Containers")          ordering = ('cached_label',) -        unique_together = ('index', 'responsible') +        unique_together = [('index', 'responsible'), +                           ('location', 'container_type', 'parent', +                            'reference')]          permissions = (              ("view_container", u"Can view all Containers"),              ("view_own_container", u"Can view own Container"), @@ -746,6 +748,12 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,      def short_label(self):          return "{} {}".format(self.container_type.label, self.reference) +    @property +    def parent_external_id(self): +        if not self.parent: +            return self.location.external_id +        return self.parent.external_id +      def natural_key(self):          return (self.uuid, ) @@ -843,7 +851,7 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,      def get_localisation(self, place):          locas = self.get_localisations() -        if len(locas) < (place + 1): +        if len(list(locas)) < (place + 1):              return ""          return locas[place] diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index 37c342ef7..a342dc1f9 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -683,3 +683,38 @@ class ContainerTest(FindInit, TestCase):          container = models.Container.objects.get(pk=container.pk)          self.assertEqual(container.x, 33) +    def test_external_id(self): +        ct = models.ContainerType.objects.all()[0] +        container_1 = models.Container.objects.create( +            reference="Test", responsible=self.main_warehouse, +            location=self.main_warehouse, +            container_type=ct +        ) +        container_2 = models.Container.objects.create( +            reference="Test 2", responsible=self.main_warehouse, +            parent=container_1, +            location=self.main_warehouse, +            container_type=ct +        ) +        container_3 = models.Container.objects.create( +            reference="Test 3", responsible=self.main_warehouse, +            parent=container_2, +            location=self.main_warehouse, +            container_type=ct +        ) +        self.assertEqual( +            container_1.external_id, +            "{}-{}-{}".format( +                self.main_warehouse.external_id, ct.txt_idx, +                container_1.reference)) +        self.assertEqual( +            container_2.external_id, +            "{}-{}-{}".format( +                container_1.external_id, ct.txt_idx, +                container_2.reference)) +        self.assertEqual( +            container_3.external_id, +            "{}-{}-{}".format( +                container_2.external_id, ct.txt_idx, +                container_3.reference)) + diff --git a/ishtar_common/migrations/0203_auto_20200407_1142.py b/ishtar_common/migrations/0203_auto_20200407_1142.py new file mode 100644 index 000000000..db6cbc50c --- /dev/null +++ b/ishtar_common/migrations/0203_auto_20200407_1142.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-04-07 11:42 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0202_auto_20200129_1941'), +    ] + +    operations = [ +        migrations.AlterField( +            model_name='ishtarsiteprofile', +            name='container_external_id', +            field=models.TextField(default='{location__external_id}-{container_type__txt_idx}-{parent_id}-{reference}', help_text='Formula to manage container external ID. Change this with care. With incorrect formula, the application might be unusable and import of external data can be destructive.', verbose_name='Container external id'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 4b4753fe3..38e5b2fb4 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2972,7 +2972,8 @@ class IshtarSiteProfile(models.Model, Cached):                      "data can be destructive."))      container_external_id = models.TextField(          _("Container external id"), -        default="{responsible__external_id}-{index}", +        default="{parent_external_id}-{container_type__txt_idx}-" +                "{reference}",          help_text=_("Formula to manage container external ID. "                      "Change this with care. With incorrect formula, the "                      "application might be unusable and import of external "  | 
