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 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 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 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 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 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)