예제 #1
0
파일: logic.py 프로젝트: eliane/rapidsms
def transfer_item(sender, receiver, item, quantity):
    ''' Transfer an arbitrary quantity of goods between to StoreProvider '''
    try:
        sender_stock        = StockItem.by_peer_item(peer=sender, item=item)
    except StockItem.DoesNotExist:
        # Store has no such item in stock
        raise ItemNotInStore

    # Check if Store has enough items to share
    if sender_stock.quantity < quantity:
        raise NotEnoughItemInStock

    # retrieve or create StockItem for receiver    
    try:
        receiver_stock      = StockItem.by_peer_item(peer=receiver, item=item)
    except StockItem.DoesNotExist:
        receiver_stock      = StockItem.new_by_peer_item_qty(peer=receiver, item=item, quantity=0)
        #StockItem(peer=receiver, item=item, quantity=0)
        receiver_stock.save()

    log = TransferLog(sender=sender, receiver=receiver, item=item, quantity=quantity, date=datetime.now())

    # actual transfer
    try:
        sender_stock.quantity   -= quantity
        receiver_stock.quantity += quantity
        sender_stock.save()
        receiver_stock.save()
        log.save()
    except Exception, e:
        raise e
예제 #2
0
파일: logic.py 프로젝트: eliane/rapidsms
def add_stock_for_item(receiver, item, quantity):
    ''' Add to stock quantity for a pharmacist '''

    # retrieve or create StockItem for receiver
    # need to make it smarter to check to make sure sku item exists
    try:
        receiver_stock      = StockItem.by_peer_item(peer=receiver, item=item)
    except StockItem.DoesNotExist:
        receiver_stock      = StockItem.new_by_peer_item_qty(peer=receiver, item=item, quantity=0)
        receiver_stock.save()
        
    log = TransferLog(sender=receiver, receiver=receiver, item=item, quantity=quantity, date=datetime.now())

    # actual transfer
    try:
        receiver_stock.quantity += quantity
        receiver_stock.save()
        log.save()
    
    except Exception, e:
        raise e