Beispiel #1
0
def delete(id):
    """ Remove purchase.
    """

    marketplaceModel = marketplace.get_marketplace()

    purchase = ndb.Key('PurchaseModel', int(id),
                       parent=marketplaceModel.key).get()

    if purchase is None:
        raise NotFoundEntityException("messages.purchase.notfound")

    # Update stock
    stock.remove_item_from_stock(purchase)

    # Delete from datastore
    purchase.key.delete()
Beispiel #2
0
def delete(id):
    """ Remove purchase.
    """

    marketplaceModel = marketplace.get_marketplace()

    purchase = ndb.Key('PurchaseModel', int(
        id), parent=marketplaceModel.key).get()

    if purchase is None:
        raise NotFoundEntityException("messages.purchase.notfound")

    # Update stock
    stock.remove_item_from_stock(purchase)

    # Delete from datastore
    purchase.key.delete()
Beispiel #3
0
def save(purchase):
    """ Add or update for purchase.
    """

    # Get parent
    marketplaceModel = marketplace.get_marketplace()

    logging.debug("Get user marketplace")

    if purchase.id is not None:

        # Create purchase with id
        purchaseModel = PurchaseModel(id=int(purchase.id),
                                      parent=marketplaceModel.key)

        try:

            # Reverse in stock
            stock.remove_item_from_stock(purchaseModel)

        except IllegalStateException as error:
            logging.warning("Stock couldn't be reversed by error %s", error)

    else:

        # Create supplier with random unique id
        purchaseModel = PurchaseModel(parent=marketplaceModel.key)

    logging.debug("Purchase model created")

    # Get product
    productKey = ndb.Key('ProductModel',
                         int(purchase.product.id),
                         parent=marketplaceModel.key)

    if productKey is None:
        raise NotFoundEntityException("messages.product.notfound")

    purchaseModel.product = productKey

    logging.debug("Get product child entity ok")

    # Get supplier
    supplierKey = ndb.Key('SupplierModel',
                          int(purchase.supplier.id),
                          parent=marketplaceModel.key)
    if supplierKey is None:
        raise NotFoundEntityException("messages.supplier.notfound")

    purchaseModel.supplier = supplierKey

    logging.debug("Get supplier child entity ok")

    # Set attributes
    purchaseModel.quantity = purchase.quantity
    purchaseModel.purchase_date = purchase.purchase_date
    purchaseModel.received_date = purchase.received_date
    purchaseModel.cost = purchase.cost
    purchaseModel.total_cost = purchase.total_cost
    purchaseModel.exchange_dollar = purchase.exchange_dollar
    purchaseModel.cost_dollar = purchase.cost_dollar
    purchaseModel.total_cost_dollar = purchase.total_cost_dollar
    purchaseModel.shipping_cost = purchase.shipping_cost
    purchaseModel.track_code = purchase.track_code
    purchaseModel.invoice = purchase.invoice
    purchaseModel.payment_date = purchase.payment_date
    purchaseModel.purchase_link = purchase.purchase_link

    # Persiste it
    purchaseModel.put()

    logging.debug("Purchase %d persisted successfully", purchaseModel.key.id())

    # Update stock
    stock.add_item_to_stock(purchaseModel)

    logging.debug("Stock updated successfully")

    # Return it
    return purchaseModel
Beispiel #4
0
def save(purchase):
    """ Add or update for purchase.
    """

    # Get parent
    marketplaceModel = marketplace.get_marketplace()

    logging.debug("Get user marketplace")

    if purchase.id is not None:

        # Create purchase with id
        purchaseModel = PurchaseModel(
            id=int(purchase.id), parent=marketplaceModel.key)

        try:
            
            # Reverse in stock
            stock.remove_item_from_stock(purchaseModel)

        except IllegalStateException as error:
            logging.warning("Stock couldn't be reversed by error %s", error)

    else:

        # Create supplier with random unique id
        purchaseModel = PurchaseModel(parent=marketplaceModel.key)

    logging.debug("Purchase model created")

    # Get product
    productKey = ndb.Key('ProductModel', int(purchase.product.id),
                         parent=marketplaceModel.key)

    if productKey is None:
        raise NotFoundEntityException("messages.product.notfound")

    purchaseModel.product = productKey

    logging.debug("Get product child entity ok")

    # Get supplier
    supplierKey = ndb.Key('SupplierModel', int(purchase.supplier.id),
                            parent=marketplaceModel.key)
    if supplierKey is None:
        raise NotFoundEntityException("messages.supplier.notfound")

    purchaseModel.supplier = supplierKey

    logging.debug("Get supplier child entity ok")

    # Set attributes
    purchaseModel.quantity = purchase.quantity
    purchaseModel.purchase_date = purchase.purchase_date
    purchaseModel.received_date = purchase.received_date
    purchaseModel.cost = purchase.cost
    purchaseModel.total_cost = purchase.total_cost
    purchaseModel.exchange_dollar = purchase.exchange_dollar
    purchaseModel.cost_dollar = purchase.cost_dollar
    purchaseModel.total_cost_dollar = purchase.total_cost_dollar
    purchaseModel.shipping_cost = purchase.shipping_cost
    purchaseModel.track_code = purchase.track_code
    purchaseModel.invoice = purchase.invoice
    purchaseModel.payment_date = purchase.payment_date
    purchaseModel.purchase_link = purchase.purchase_link

    # Persiste it
    purchaseModel.put()

    logging.debug("Purchase %d persisted successfully",
                  purchaseModel.key.id())

    # Update stock
    stock.add_item_to_stock(purchaseModel)

    logging.debug("Stock updated successfully")

    # Return it
    return purchaseModel