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)
示例#2
0
    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)
示例#3
0
    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()