def createOrder(self, order_details): order = Order(order_details=[ OrderDetail(product_id=order_detail['product_id'], product_name=order_detail['product_name'], price=order_detail['price'], quantity=order_detail['quantity'], currency=order_detail['currency']) for order_detail in order_details ]) self.order_db.add(order) self.order_db.commit() order = OrderSchema().dump(order).data try: # self.event_dispatcher('order_created', { # 'order': order # }) self.products_rpc.handleOrderCreated({'order': order}) except RemoteError as ex: self.logger.info("orders.createOrder: %s" % ex) raise OutOfStock(str(ex)) # self.logger.info("createOrder: order: %s" % order) # Hide real Id from DB order['hash_id'] = self.hashids.encrypt(order['id']) return order
def get_order(self, order_id): order = self.db.query(Order).get(order_id) if not order: raise NotFound('Order with id {} not found'.format(order_id)) return OrderSchema().dump(order).data
def test_can_update_order(orders_rpc, order): order_payload = OrderSchema().dump(order).data for order_detail in order_payload['order_details']: order_detail['quantity'] += 1 updated_order = orders_rpc.update_order(order_payload) assert updated_order['order_details'] == order_payload['order_details']
def update_order(self, order): order_details = { order_details['id']: order_details for order_details in order['order_details'] } order = self.db.query(Order).get(order['id']) for order_detail in order.order_details: order_detail.price = order_details[order_detail.id]['price'] order_detail.quantity = order_details[order_detail.id]['quantity'] self.db.commit() return OrderSchema().dump(order).data
def getOrder(self, hashed_order_id): order_id = self.hashids.decrypt(hashid=hashed_order_id) # self.logger.info("order_id: %s" % order_id) order = self.order_db.query(Order).get(order_id) if not order: raise NotFound( 'Order with id {} not found'.format(hashed_order_id)) # Hide real Id from DB data = OrderSchema().dump(order).data data['id'] = hashed_order_id return data
def create_order(self, order_details): order = Order(order_details=[ OrderDetail(product_id=order_detail['product_id'], price=order_detail['price'], quantity=order_detail['quantity']) for order_detail in order_details ]) self.db.add(order) self.db.commit() order = OrderSchema().dump(order).data self.event_dispatcher('order_created', { 'order': order, }) return order
def _createCart(self, order_data, customer_id): order = Order(customer_id=customer_id, order_details=[ OrderDetail( product_id=order_detail['product_id'], product_name=order_detail['product_name'], price=order_detail['price'], quantity=order_detail['quantity'], currency=order_detail['currency'], ) for order_detail in order_data["order_details"] ]) self.order_db.add(order) self.order_db.commit() order = OrderSchema().dump(order).data # Hide real Id from DB order['hash_id'] = self.hashids.encrypt(order['id']) return "Create successful!"
def get_order(self, order_id): order = self.db.query(Order).get(order_id) return OrderSchema().dump(order).data