Example #1
0
    def __updatePriceModel(self, priceModel, itemPrice):
        wgGetIntegralFormat = BigWorld.wg_getIntegralFormat
        statsMoney = self.__stats.money
        price = itemPrice.price
        defPrice = itemPrice.defPrice
        currencyType = priceModel.getType()
        currencyValue = price.get(currencyType)
        if currencyValue is not None:
            priceModel.setPrice(wgGetIntegralFormat(currencyValue))
            priceModel.setDefPrice(
                wgGetIntegralFormat(defPrice.get(currencyType)))
        else:
            for currencyType in Currency.ALL:
                currencyValue = price.get(currencyType)
                if currencyValue:
                    priceModel.setType(currencyType)
                    priceModel.setPrice(
                        BigWorld.wg_getIntegralFormat(currencyValue))
                    break

        priceModel.setAction(itemPrice.getActionPrc())
        if self.__isPurchaseCurrencyAvailable(currencyType):
            isEnough = True
        else:
            isEnough = statsMoney.get(currencyType) >= currencyValue
        priceModel.setIsEnough(isEnough)
        hasAction = itemPrice.getActionPrcAsMoney().get(
            currencyType) is not None
        priceModel.setIsWithAction(hasAction)
        if hasAction:
            updateActionInViewModel(currencyType, priceModel, itemPrice)
        return
    def __updatePriceModel(self, priceModel, itemPrice):
        numberFormat = self.gui.systemLocale.getNumberFormat
        statsMoney = self.__stats.money
        price = itemPrice.price
        defPrice = itemPrice.defPrice
        currencyType = priceModel.getType()
        currencyValue = price.get(currencyType)
        if currencyValue is not None:
            priceModel.setPrice(numberFormat(currencyValue))
            priceModel.setDefPrice(numberFormat(defPrice.get(currencyType, 0)))
        else:
            for currencyType in Currency.ALL:
                currencyValue = price.get(currencyType)
                if currencyValue:
                    priceModel.setType(currencyType)
                    priceModel.setPrice(numberFormat(currencyValue))
                    break

        priceModel.setAction(itemPrice.getActionPrc())
        if self.__isPurchaseCurrencyAvailable(currencyType):
            isEnough = True
        else:
            isEnough = statsMoney.get(currencyType) >= currencyValue
        priceModel.setIsEnough(isEnough)
        hasAction = itemPrice.getActionPrcAsMoney().get(
            currencyType) is not None
        priceModel.setIsWithAction(hasAction)
        if hasAction:
            updateActionInViewModel(currencyType, priceModel, itemPrice)
        priceModel.setIsBootcamp(self.__bootcamp.isInBootcamp())
        return
Example #3
0
def getItemPricesViewModel(statsMoney, *itemPrices, **kwargs):
    result = []
    for itemPrice in itemPrices:
        priceModels = []
        if itemPrice.isDefined():
            for currency in Currency.ALL:
                currencyValue = itemPrice.price.get(currency)
                if currencyValue is not None:
                    actionPriceModel = ActionPriceModel()
                    isEnough = statsMoney.get(currency) >= currencyValue
                    if not isEnough and 'exchangeRate' in kwargs and currency == Currency.CREDITS:
                        isEnough = canBuyWithGoldExchange(itemPrice.price, statsMoney, kwargs.get('exchangeRate'))
                    actionPriceModel.setIsEnough(isEnough)
                    currencyAction = itemPrice.getActionPrcAsMoney().get(currency)
                    hasAction = currencyAction is not None
                    if hasAction:
                        updateActionInViewModel(currency, actionPriceModel, itemPrice)
                    actionPriceModel.setType(currency)
                    actionPriceModel.setIsWithAction(hasAction)
                    actionPriceModel.setPrice(backport.getIntegralFormat(currencyValue))
                    defPrice = backport.getIntegralFormat(itemPrice.defPrice.get(currency, 0))
                    actionPriceModel.setDefPrice(defPrice)
                    if 'isBootcamp' in kwargs:
                        actionPriceModel.setIsBootcamp(kwargs.get('isBootcamp'))
                    priceModels.append(actionPriceModel)

        else:
            actionPriceModel = ActionPriceModel()
            actionPriceModel.setIsFree(True)
            priceModels.append(actionPriceModel)
        if priceModels:
            result.append(priceModels)

    return result
    def __updateTotalPrice(self):
        totalPrice = self.__getTotalItemPrice()
        with self.viewModel.equipmentBlock.transaction() as equipmentBlockVm:
            if self.__isTradeIn():
                equipmentBlockVm.setConfirmGoldPrice(
                    totalPrice.price.get(Currency.GOLD))
                popoverIsAvailable = totalPrice.price.get(
                    Currency.GOLD) <= self.__stats.money.get(Currency.GOLD)
                self.__popoverIsAvailable = popoverIsAvailable
                equipmentBlockVm.setPopoverIsAvailable(
                    popoverIsAvailable and not self.__isRentVisible)
            totalPriceArray = equipmentBlockVm.totalPrice.getItems()
            for model in totalPriceArray:
                currencyType = model.getType()
                currencyValue = int(totalPrice.price.get(currencyType, 0))
                currencyDefValue = int(totalPrice.defPrice.get(
                    currencyType, 0))
                model.setPrice(
                    self.gui.systemLocale.getNumberFormat(currencyValue))
                model.setDefPrice(getIntegralFormat(currencyDefValue))
                if not self.__isPurchaseCurrencyAvailable(currencyType):
                    model.setIsEnough(
                        currencyValue <= self.__stats.money.get(currencyType))
                isAction = totalPrice.getActionPrcAsMoney().get(
                    currencyType
                ) is not None and currencyValue < currencyDefValue
                model.setShowOldValue(isAction)
                model.setIsWithAction(
                    isAction and (self.__tradeOffVehicle is None
                                  or not self.__isValidTradeOffSelected()))
                model.setIsBootcamp(self.__bootcamp.isInBootcamp())
                if isAction:
                    updateActionInViewModel(currencyType, model, totalPrice)

            self.__updateBuyBtnStatus(totalPrice)
        return