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 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 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 getTopSellingProducts(self, token): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) productDao = ProductDao() result, exception = productDao.getTopSellingProducts(user) if exception != None: return ResponseUtils.returnError(exception) else: return ResponseUtils.returnSuccess(result)
def searchProduct(self, token, searchKey): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) productDao = ProductDao() result, exception = productDao.searchProduct(user, searchKey) if exception != None: return ResponseUtils.returnError(exception) else: return ResponseUtils.returnSuccess(result)
def getProducts(self, token): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) # TODO: add pagination productDao = ProductDao() products, exception = productDao.getProducts(user) if (exception != None): return ResponseUtils.returnError(exception) else: return ResponseUtils.returnSuccess(products)
def updateProductQuantityAndOriginalPrice(self, token, products): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) productDao = ProductDao() for product in products: exception = productDao.updateQuantityAndOrginalPrice( user, product['id'], product['quantity'], product['original_price']) if (exception != None): return ResponseUtils.returnError(exception) return ResponseUtils.returnSuccess(None)
def getAllAccountStatement(self, token): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) accountStatementDao = AccountStatementDao() data, exception = accountStatementDao.getAll(user) if (exception != None): return ResponseUtils.returnError(exception) for accountSta in data: accountSta['start_date'] = TimestampUtils.getDateFromDatetime( accountSta['start_date']) accountSta['end_date'] = TimestampUtils.getDateFromDatetime( accountSta['end_date']) return ResponseUtils.returnSuccess(data)
def getAccountStatementInfo(self, token, accountStatementId): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) asExceptionDao = AccountStatementExceptionDao() asExceptions, exception = asExceptionDao.getAll( user, accountStatementId) if (exception != None): return ResponseUtils.returnError(exception) orderItemDao = OrderItemDao() orderItems, exception = orderItemDao.getOrderItemByAccountStatement( user, accountStatementId) if (exception != None): return ResponseUtils.returnError(exception) result = {"exceptions": asExceptions, "orderItems": orderItems} return ResponseUtils.returnSuccess(result)
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 createShop(self, token, shop): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) # Test api key lazadaStatisticApi = LazadaStatisticApi() result, exception = lazadaStatisticApi.getStatistic(user, shop) if (exception != None): return ResponseUtils.returnError( "Lazada email or api-key is incorrect") # create shop shopDao = ShopDao() result, exception = shopDao.insert(user, shop) if (exception != None): return ResponseUtils.returnError(exception) # Start cronjob # Done return ResponseUtils.returnSuccess(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()
def changeOriginPrice(self, token, orderItems, accountStatementId): user, exception = Validation.validateToken(token) if (exception != None): return ResponseUtils.returnError(exception) orderItemDao = OrderItemDao() for orderItem in orderItems: # Get current OrderItem curOrderItem, exception = orderItemDao.getOrderItemByOrderItemId( user, orderItem['order_item_id']) if (exception != None): return ResponseUtils.returnError(exception) # Recompute earned/income and update commission = curOrderItem['actual_paid_price'] - curOrderItem[ 'earned'] - curOrderItem['original_price'] orderItem['earned'] = curOrderItem['actual_paid_price'] - ( commission + orderItem['original_price']) exception = orderItemDao.changeOriginalPrice(user, orderItem) if (exception != None): return ResponseUtils.returnError(exception) # Update product's orginal price if its value is Zero if (curOrderItem['original_price'] == 0): productDao = ProductDao() exception = productDao.updateOriginalPriceByShopSku( user, orderItem['shop_sku'], orderItem['original_price']) if (exception != None): return ResponseUtils.returnError(exception) # Compute an account statement income income, exception = orderItemDao.getTotalEarningOfAccountStatement( user, accountStatementId) if (exception != None): return ResponseUtils.returnError(exception) # Recompute account statment income accountStatementDao = AccountStatementDao() updatedDate = TimestampUtils.getCurrentDatetime() exception = accountStatementDao.update(user, accountStatementId, income, updatedDate) if (exception != None): return ResponseUtils.returnError(exception) return ResponseUtils.generateSuccessResponse(None)
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)