diff options
Diffstat (limited to 'archaeological_warehouse/models.py')
| -rw-r--r-- | archaeological_warehouse/models.py | 36 | 
1 files changed, 34 insertions, 2 deletions
| diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 35e5536fa..31701dbf9 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -21,10 +21,10 @@ import datetime  from django.conf import settings  from django.contrib.gis.db import models -from django.db.models import Q, Count +from django.db.models import Q  from django.db.models.signals import post_save, post_delete  from django.template.defaultfilters import slugify -from django.utils.translation import ugettext_lazy as _, ugettext +from django.utils.translation import ugettext_lazy as _  from ishtar_common.utils import cached_label_changed @@ -328,6 +328,38 @@ class Container(LightHistorizedItem, ImageModel):      def precise_location(self):          return self.location.name + u" - " + self.divisions_lbl +    def get_localisations(self): +        """ +        Get precise localisation of the container in the warehouse. + +        :return: tuple of strings with localisations +        """ +        return tuple(( +            loca.reference +            for loca in ContainerLocalisation.objects.filter( +                container=self).order_by('division__order') +        )) + +    def set_localisation(self, place, value): +        """ +        Set the reference for the localisation number "place" (starting from 0) +        :param place: the number of the localisation +        :param value: the reference to be set +        :return: the container location object or None if the place does not +        exist +        """ +        q = WarehouseDivisionLink.objects.filter( +            warehouse=self.location).order_by('order') +        for idx, division_link in enumerate(q.all()): +            if idx == place: +                break +        else: +            return +        obj, created = ContainerLocalisation.objects.update_or_create( +            container=self, division=division_link, +            defaults={'reference': value}) +        return obj +      @property      def divisions_lbl(self):          locas = [ | 
