Ejemplo n.º 1
0
    def next_location(self):

        # Get the latest box based on its id
        box = Box.objects.filter(account=self.id).latest('id')

        # Num of empty locations given by empty accession fields
        empty_locations = BoxItem.objects.filter(used=False, box=box.id).count()

        # If box is full, create a new one
        if not empty_locations:
            latest_box = Box.objects.filter(account=self.id).latest('id')
            box = Box()
            box.account = self
            box.number = int(latest_box.number) + 1
            box.save()

            next_location = BoxItem.objects.get(box=box.id, slot='A1')

            return int(next_location.id)

        # Get the highest location value as an integer
        last_location_id = BoxItem.objects.filter(box=box.id).latest('id')
        last_location_id = int(last_location_id.id)

        # Next location_id value is last_location - empty_locations + 1
        next_location = last_location_id - empty_locations + 1

        return next_location
Ejemplo n.º 2
0
def account_receive(sender, **kwargs):

    # If instance is new and not updated
    created = kwargs.get('created')
    if created:
        name = kwargs.get('instance') # Instance = account name (unicode def in Account)
        account = Account.objects.get(name=name)

        # create first box
        box = Box()
        box.account_id = account.id
        box.number = 1
        box.save()
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     slug = helpers.randascii(4)
     box = Box(slug=slug, name="", user_key=helpers.randascii(10))
     box.save()
     return HttpResponseRedirect(reverse('boxes.views.settings', args=(box.slug, box.user_key)))
Ejemplo n.º 4
0
 def post(self, request, *args, **kwargs):
     slug = helpers.randascii(4)
     box = Box(slug=slug, name="", user_key=helpers.randascii(10))
     box.save()
     return HttpResponseRedirect(
         reverse('boxes.views.settings', args=(box.slug, box.user_key)))