Ejemplo n.º 1
0
def test_insert_order():
    order = Order()
    order_to_db = {
        'customer_id': 1,
        'store_id': 1,
    }
    assert isinstance(order.insert_order(order_to_db), int)
Ejemplo n.º 2
0
    def post(self):
        try:
            order = Order()
            order_product = OrderProduct()
            json = request.json
            inventory = Inventory()
            order_to_db = {
                'customer_id': json['customer_id'],
                'store_id': json['store_id'],
            }
            order_id = order.insert_order(order_to_db)
            for product in json['products']:

                store_inventory = inventory.get_product_availability_in_specific_store(product['product_id'], json['store_id'])
                if product['quantity'] > store_inventory[0]['quantity']:
                    return {'success': False, 'Error': 'product unavailable '+product['product_id']}
                product['order_id'] = order_id
                order_product.insert_order_product(product)
                inventory.modify_stock(json['store_id'], product['product_id'], int(product['quantity'])*-1)
            return {'success': True, 'product': json}
        except Exception as e:
            return {'success': False, 'Error': str(e)}