def post(self): try: """ adds or deminishes x quantity of the y product in the given z store JSON example: { "store_id":123, "product_id":234, "quantity":1(positive values if wants to be added, negative if diminished) } :returns example: { "success": True, } """ inventory = Inventory() json = request.json inventory.modify_stock(json['store_id'], json['product_id'], json['quantity']) return {'success': True} except Exception as e: return {'success': False, 'Error': str(e)}
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)}
def test_modify_stock(): inventory = Inventory() inventory_info = inventory.modify_stock(1, 1, 5) assert inventory_info['success']