def post(self): if not self.ValidateToken(): self.write(json_util.dumps({"error": "invalid token"})) else: order_id = self.get_argument("order_id", "") tracking_code = self.get_argument("tracking_code", "") provider_id = self.get_argument("provider_id", "") new_cellar_id = self.get_argument("new_cellar_id", "") c = Cellar() res_reservation = c.GetReservationCellar() if "success" in res_reservation: new_cellar_id = res_reservation["success"] if order_id == "": self.write(json_util.dumps({"error": "invalid order_id"})) elif tracking_code == "": self.write(json_util.dumps({"error": "invalid tracking_code"})) elif provider_id == "": self.write(json_util.dumps({"error": "invalid provider_id"})) else: cellar = Cellar() order_detail = OrderDetail() details_res = order_detail.ListByOrderId(order_id) if "success" in details_res: details = details_res["success"] for detail in details: sku = detail["sku"] quantity = detail["quantity"] operation = Kardex.OPERATION_SELL sell_price = detail["price"] _size = Size() _size.name = detail["size"] res_name = _size.initByName() if "success" in res_name: size = _size.id else: print res_name["error"] color = detail["color"] user = '******' k = Kardex() find_kardex = k.FindKardex(sku, new_cellar_id, size) balance_price = 0 units = 0 if "success" in find_kardex: balance_price = k.balance_price units = k.balance_units if int(units) >= int(quantity): kardex = Kardex() kardex.product_sku = sku kardex.cellar_identifier = new_cellar_id kardex.date = str( datetime.datetime.now( pytz.timezone( 'Chile/Continental')).isoformat()) kardex.operation_type = operation kardex.units = quantity kardex.price = balance_price kardex.size_id = size kardex.sell_price = sell_price kardex.color = color kardex.user = user response_kardex = kardex.Insert() if "error" in response_kardex: self.write(json_util.dumps(response_kardex)) return else: self.write( json_util.dumps({ "error": "Stock insuficiente para realizar el movimiento" })) return shipping = Shipping() res = shipping.SaveTrackingCode(order_id, tracking_code, provider_id) self.write(json_util.dumps(res))
def post(self): #validate constrains if not self.ValidateToken(): return ids = self.get_argument("ids", "") cellar_id = None web_cellar = None cellar = Cellar() res_reservation_cellar = cellar.GetReservationCellar() if "success" in res_reservation_cellar: cellar_id = res_reservation_cellar["success"] else: self.write( json_util.dumps({"error": res_reservation_cellar["error"]})) if ids == "": self.write(json_util.dumps({"error": "ids viene vacio"})) else: identificadores = [] for identificador in ids.split(","): order = Order() res_order = order.GetOrderById(identificador) cancelable = True if "success" in res_order: o = res_order["success"] if o["state"] != Order.ESTADO_CANCELADO and o[ "state"] != Order.ESTADO_DESPACHADO: order_detail = OrderDetail() details_res = order_detail.ListByOrderId(identificador) if "success" in details_res: details = details_res["success"] # recorre cada producto del detalle de orden y determina si la orden es cancelable for d in details: k = Kardex() find_kardex = k.FindKardex( d["sku"], cellar_id, d['size_id']) units = 0 if "success" in find_kardex: units = k.balance_units if int(units) < int(d['quantity']): cancelable = False # end for # si no es cancelable la orden se guarda en el array identificadores para avisar al usuario if not cancelable: identificadores.append({ "identificador": identificador, "error": "no tiene stock suficiente" }) else: cellar = Cellar() res_web_cellar = cellar.GetWebCellar() if "success" in res_web_cellar: web_cellar = res_web_cellar["success"] # mueve c/u de los productos desde la bodega de reserva a la bodega web kardex = Kardex() res = kardex.moveOrder(details, web_cellar, cellar_id) if "error" in res: identificadores.append({ "identificador": identificador, "error": res["error"] }) else: if identificador not in identificadores: identificadores.append({ "identificador": identificador, "error": details_res["error"] }) elif o["state"] == Order.ESTADO_DESPACHADO: if identificador not in identificadores: identificadores.append( identificadores.append({ "identificador": identificador, "error": "Pedido no puede ser cancelado, ya que se encuentra despachado" })) else: if identificador not in identificadores: identificadores.append( identificadores.append({ "identificador": identificador, "error": "Pedido ya esta cancelado" })) else: if identificador not in identificadores: identificadores.append( identificadores.append({ "identificador": identificador, "error": res_order["error"] })) if len(identificadores) > 0: self.write(json_util.dumps({"error": identificadores})) else: self.write(json_util.dumps({"success": "ok"}))
def post(self): cellar = Cellar() self.write(json_util.dumps(cellar.GetReservationCellar()))