Esempio n. 1
0
def reserve_items(ident, qty, earmark, die_if_not=True):
    if qty <= 0:
        raise ValueError
    if fpiswire_ident(ident) and not isinstance(qty, Length):
        qty = Length(str(qty) + 'm')
    for location in inventory_locations:
        if not location.is_valid:
            continue
        lqty = location.get_ident_qty(ident)
        if lqty is not None:
            if lqty > qty:
                location.reserve_ident_qty(ident, qty, earmark)
                return 0
            elif lqty > 0:
                location.reserve_ident_qty(ident, lqty, earmark)
                qty -= lqty
        if qty == 0:
            return 0
    if qty > 0:
        logger.warning('Partial Reservation of ' + ident + ' for ' + earmark +
                       ' : Short by ' + str(qty))
        if die_if_not is True:
            raise ValueError("Insufficient Qty. "
                             "Call with die_if_not=True if handled downstream")
    return qty
Esempio n. 2
0
 def avail_qty(self):
     try:
         if fpiswire_ident(self._ident):
             return Length(str(self._qty) + 'm') - self.reserved_qty
         else:
             return self._qty - self.reserved_qty
     except AttributeError:
         return self._qty - self.reserved_qty
Esempio n. 3
0
 def avail_qty(self):
     try:
         if fpiswire_ident(self._ident):
             qty = self._qty
             if not isinstance(qty, Length):
                 qty = Length(str(self._qty) + 'm')
             return qty - self.reserved_qty
         else:
             return self._qty - self.reserved_qty
     except AttributeError:
         return self._qty - self.reserved_qty
Esempio n. 4
0
    def reserve_qty(self, value, earmark):
        try:
            if fpiswire_ident(self._ident) and not isinstance(value, Length):
                value = Length(str(value) + 'm')
        except AttributeError:
            pass
        if value > self.avail_qty:
            raise ValueError

        logger.debug("Reserving " + self.ident + " in " + self._parent._dname +
                     " for " + earmark + " : " + str(value))
        self._reservations.append((value, earmark))
Esempio n. 5
0
    def reserve_qty(self, value, earmark):
        try:
            if fpiswire_ident(self._ident) and not isinstance(value, Length):
                value = Length(str(value) + 'm')
        except AttributeError:
            pass
        if value > self.avail_qty:
            raise ValueError

        logger.debug("Reserving " + self.ident + " in " +
                     self._parent._dname + " for " + earmark +
                     " : " + str(value))
        self._reservations.append((value, earmark))
Esempio n. 6
0
 def validate_qty(form, field):
     # TODO integrate this with inventory core?
     ident = str(form.ident.data.strip())
     if fpiswire_ident(ident):
         try:
             Decimal(field.data.strip())
             raise ValidationError("Include Units")
         except (ValidationError, KeyboardInterrupt, SystemExit):
             raise
         except:
             pass
         try:
             qty = lengths.Length(field.data.strip())
             if qty <= 0:
                 raise ValidationError("Invalid Length")
         except:
             raise ValidationError("Invalid Length")
     else:
         try:
             qty = int(field.data.strip())
             if qty <= 0:
                 raise ValidationError("Invalid Qty")
         except:
             raise ValidationError("Invalid Qty")
Esempio n. 7
0
 def validate_qty(form, field):
     # TODO integrate this with inventory core?
     ident = str(form.ident.data.strip())
     if fpiswire_ident(ident):
         try:
             Decimal(field.data.strip())
             raise ValidationError("Include Units")
         except ValidationError:
             raise
         except:
             pass
         try:
             qty = lengths.Length(field.data.strip())
             if qty <= 0:
                 raise ValidationError("Invalid Length")
         except:
             raise ValidationError("Invalid Length")
     else:
         try:
             qty = int(field.data.strip())
             if qty <= 0:
                 raise ValidationError("Invalid Qty")
         except:
             raise ValidationError("Invalid Qty")
Esempio n. 8
0
def reserve_items(ident, qty, earmark, die_if_not=True):
    if qty <= 0:
        raise ValueError
    if fpiswire_ident(ident) and not isinstance(qty, Length):
        qty = Length(str(qty) + 'm')
    for location in inventory_locations:
        lqty = location.get_ident_qty(ident)
        if lqty is not None:
            if lqty > qty:
                location.reserve_ident_qty(ident, qty, earmark)
                return 0
            elif lqty > 0:
                location.reserve_ident_qty(ident, lqty, earmark)
                qty -= lqty
        if qty == 0:
            return 0
    if qty > 0:
        logger.warning('Partial Reservation of ' + ident +
                       ' for ' + earmark + ' : Short by ' + str(qty))
        if die_if_not is True:
            raise ValueError("Insufficient Qty. "
                             "Call with die_if_not=True if handled downstream"
                             )
    return qty