def scanBarcode(self, token, barcode): user = ManagerHelper.validateToken(token) if not user: errorArray = ResponseUtils.convertToArryError("Token is invalid, please logout and login again !") return ResponseUtils.generateErrorResponse(errorArray) # Get orderNumer orderNumber = ConvertHelper.getOrderNumberFromBarcode(barcode) if not orderNumber: errorArray = ResponseUtils.convertToArryError("Barcode is invalid !") return ResponseUtils.generateErrorResponse(errorArray) # Get order by orderNumber orderDao = OrderDao() order, exception = orderDao.getOrderByOrderNumber(user, orderNumber) if exception != None: errorArray = ResponseUtils.convertToArryError(exception) return ResponseUtils.generateErrorResponse(errorArray) # Get orderItem by order orderItemDao = OrderItemDao() orderItems, exception = orderItemDao.getOrderItemByOrderId(user, order['order_id']) if exception != None: errorArray = ResponseUtils.convertToArryError(exception) return ResponseUtils.generateErrorResponse(errorArray) # Return success response result = { "order": order, "orderItems": orderItems } return ResponseUtils.generateSuccessResponse(result)
def insertSku(self, sku, token): user = self.validateToken(token) if 'error' in user: return user # Validate certain size skudao = SkuDao() userdao = UserDao() checkExistSku = skudao.checkExistSku(sku) if (checkExistSku > 0): return ResponseUtils.generateErrorResponse("You cannot add SKU already exist!!!") addedSize = skudao.getAddedSize(user['id']) certainSize = userdao.getCertainSize(user['id']) if (addedSize >= certainSize): return ResponseUtils.generateErrorResponse("You cannot add more SKU, please contact admin to improve your account!") # Validate SKU by product's data in database productDao = ProductDao() product, exception = productDao.getProductBySellerSku(user, sku) if exception != None: return ResponseUtils.generateErrorResponse(exception) # Add missing arguments and insert to our database sku['name'] = product['name'] sku['link'] = product['url'] sku['special_price'] = product['special_price'] skudao.insert(sku, user) return ResponseUtils.generateSuccessResponse()
def getAll(self, token): user = ManagerHelper.validateToken(token) if 'error' in user: return user priceByTime = PriceByTimeDao() result = priceByTime.getAll(user) if result: return ResponseUtils.generateSuccessResponse(result) else: return ResponseUtils.generateErrorResponse("Error")
def delete(self, sku, token): user = ManagerHelper.validateToken(token) if 'error' in user: return user priceByTime = PriceByTimeDao() result = priceByTime.delete(sku, user) if 'error' in result: return ResponseUtils.generateErrorResponse(result['error']) else: return ResponseUtils.generateSuccessResponse()
def setStatusToReadyToShip(self, token, orderItemIds, shippingProvider): user = ManagerHelper.validateToken(token) if not user: errorArray = ResponseUtils.convertToArryError("Token is invalid, please logout and login again !") return ResponseUtils.generateErrorResponse(errorArray) # Set status to Parked: this is necessary before set an order to Ready-To-Ship lazadaOrderApi = LazadaOrderApi() orders = lazadaOrderApi.setStatusToPackedByMarketplace(user, orderItemIds) if 'error' in orders: errorArray = ResponseUtils.convertToArryError(orders['error']) return ResponseUtils.generateErrorResponse(errorArray) # Set status to ready to ship orders = lazadaOrderApi.setStatusToReadyToShip(user, orderItemIds) if 'error' in orders: errorArray = ResponseUtils.convertToArryError(orders['error']) return ResponseUtils.generateErrorResponse(errorArray) return ResponseUtils.generateSuccessResponse("Set status to Ready-To-Ship is done", None)
def getAllHistory(self, token): user = self.validateToken(token) if 'error' in user: return user historyDao = HistoryDao() result = historyDao.getAllHistory(user) if 'error' in result: return ResponseUtils.generateErrorResponse(result['error']) for history in result: history['enemy_json'] = json.loads(history['enemy_json']) return ResponseHelper.generateSuccessResponse(result)
def insert(self, sku, token): user = ManagerHelper.validateToken(token) if 'error' in user: return user #Valide product by Sku productDao = ProductDao() product, exception = productDao.getProductBySellerSku(user, sku) if exception != None: return ResponseUtils.generateErrorResponse(exception) # Add missing arguments and insert to our database sku['name'] = product['name'].encode('utf-8') sku['link'] = product['url'].encode('utf-8') sku['special_price'] = product['special_price'] priceByTime = PriceByTimeDao() result = priceByTime.insert(sku, user) if 'error' in result: return ResponseUtils.generateErrorResponse(result['error']) else: return ResponseUtils.generateSuccessResponse()