Revision d551c841 snf-quotaholder-app/quotaholder_django/quotaholder_app/callpoint.py

b/snf-quotaholder-app/quotaholder_django/quotaholder_app/callpoint.py
668 668
                h = db_get_holding(entity=entity, resource=resource,
669 669
                                   for_update=True)
670 670
            except Holding.DoesNotExist:
671
                m = ("There is not enough quantity "
671
                m = ("There is no quantity "
672 672
                     "to allocate from in %s.%s" % (entity, resource))
673 673
                raise NoQuantityError(m,
674 674
                                      source=entity, target=target,
......
677 677

  
678 678
            hp = h.policy
679 679

  
680
            current = h.exporting
681
            limit = hp.export_limit
682
            if current + quantity > limit:
683
                m = ("Export limit reached for %s.%s" % (entity, resource))
684
                raise ExportLimitError(m,
685
                                       source=entity, target=target,
686
                                       resource=resource, requested=quantity,
687
                                       current=current, limit=limit)
688

  
689
            limit = hp.quantity
690
            current = (+ h.exporting + h.releasing
691
                       - h.imported - h.returned)
692
            if current + quantity > limit:
693
                m = ("There is not enough quantity "
694
                     "to allocate from in %s.%s" % (entity, resource))
695
                raise NoQuantityError(m,
696
                                      source=entity, target=target,
697
                                      resource=resource, requested=quantity,
698
                                      current=current, limit=limit)
680
            if not release:
681
                current = h.exporting
682
                limit = hp.export_limit
683
                if current + quantity > limit:
684
                    m = ("Export limit reached for %s.%s" % (entity, resource))
685
                    raise ExportLimitError(m,
686
                                           source=entity, target=target,
687
                                           resource=resource, requested=quantity,
688
                                           current=current, limit=limit)
689

  
690
                limit = hp.quantity + h.imported - h.releasing
691
                unavailable = h.exporting - h.returned
692
                available = limit - unavailable
693

  
694
                if quantity > available:
695
                    m = ("There is not enough quantity "
696
                         "to allocate from in %s.%s" % (entity, resource))
697
                    raise NoQuantityError(m,
698
                                          source=entity, target=target,
699
                                          resource=resource, requested=quantity,
700
                                          current=unavailable, limit=limit)
701
            else:
702
                current = (+ h.importing + h.returning
703
                           - h.exported  - h.returned)
704
                limit = hp.capacity
705
                if current - quantity > limit:
706
                    m = ("There is not enough capacity "
707
                         "to release to in %s.%s" % (entity, resource))
708
                    raise NoQuantityError(m,
709
                                          source=entity, target=target,
710
                                          resource=resource, requested=quantity,
711
                                          current=current, limit=limit)
699 712

  
700 713
            # Target limits checks
701 714
            try:
......
711 724

  
712 725
            tp = th.policy
713 726

  
714
            limit = tp.import_limit
715
            current = th.importing
716
            if current + quantity > limit:
717
                m = ("Import limit reached for %s.%s" % (target, resource))
718
                raise ImportLimitError(m,
719
                                       source=entity, target=target,
720
                                       resource=resource, requested=quantity,
721
                                       current=current, limit=limit)
727
            if not release:
728
                limit = tp.import_limit
729
                current = th.importing
730
                if current + quantity > limit:
731
                    m = ("Import limit reached for %s.%s" % (target, resource))
732
                    raise ImportLimitError(m,
733
                                           source=entity, target=target,
734
                                           resource=resource, requested=quantity,
735
                                           current=current, limit=limit)
722 736

  
723
            limit = tp.capacity
724
            current = (+ th.importing + th.returning
725
                       - th.exported - th.released)
737
                current = (+ th.importing + th.returning
738
                           - th.exported - th.released)
726 739

  
727
            if not release and (current + quantity > limit):
740
                if current + quantity > tp.quantity + tp.capacity:
728 741
                    m = ("There is not enough capacity "
729 742
                         "to allocate into in %s.%s" % (target, resource))
730 743
                    raise NoCapacityError(m,
731 744
                                          source=entity, target=target,
732 745
                                          resource=resource, requested=quantity,
733 746
                                          current=current, limit=limit)
747
            else:
748
                limit = tp.quantity + th.imported - th.releasing
749
                unavailable = th.exporting - th.returned
750
                available = limit - unavailable
751

  
752
                if available + quantity < 0:
753
                    m = ("There is not enough quantity "
754
                         "to release from in %s.%s" % (target, resource))
755
                    raise NoCapacityError(m,
756
                                          source=entity, target=target,
757
                                          resource=resource, requested=quantity,
758
                                          current=unavailable, limit=limit)
734 759

  
735 760
            Provision.objects.create(   serial      =   commission,
736 761
                                        entity      =   e,

Also available in: Unified diff