def __updateRentInfo(self): with self.viewModel.transaction() as vm: vm.setIsRentSelected(self.__selectedRentID >= 0) with self.viewModel.equipmentBlock.transaction() as equipmentBlockVm: selectedRentDays = 0 selectedRentSeason = 0 if self.__selectedRentID >= 0: rentType, packageID = parseRentID(self.__selectedRentID) rentPackage = self.__vehicle.rentPackages[ self.__selectedRentIdx] if rentType == constants.RentType.TIME_RENT: selectedRentDays = packageID elif rentType in (constants.RentType.SEASON_RENT, constants.RentType.SEASON_CYCLE_RENT): selectedRentSeason = rentPackage['seasonType'] else: rentType = constants.RentType.NO_RENT equipmentBlockVm.setSelectedRentID(self.__selectedRentID) equipmentBlockVm.setSelectedRentType(rentType) equipmentBlockVm.setSelectedRentDays(selectedRentDays) equipmentBlockVm.setSelectedRentSeason(selectedRentSeason) with equipmentBlockVm.vehicleRentBtn.transaction( ) as vehicleRentBtnVm: if self.__vehicle.hasRentPackages: vehicleRentBtnVm.setIcon( R.images.gui.maps.icons.library.rent_ico_big()) rentBtnAvailable = self.__isToggleRentAndTradeInState( ) and self.__isRentVisible rentBtnAvailable |= not self.__isToggleRentAndTradeInState( ) and self.__vehicle.hasRentPackages vehicleRentBtnVm.setIsVisible(rentBtnAvailable)
def _successHandler(self, code, ctx=None): rentType, packageID = parseRentID(self.rentPackageID) if rentType == RentType.TIME_RENT: rentPackageName = makeString(SYSTEM_MESSAGES.VEHICLE_RENT_TIMERENT, days=packageID) elif rentType in (RentType.SEASON_CYCLE_RENT, RentType.SEASON_RENT): seasonName = SEASON_NAME_BY_TYPE[self.rentPackage['seasonType']] durationKey = _SEASON_RENT_DURATION_KEY.get(rentType) rentPackageName = makeString('#system_messages:vehicle_rent/{}/{}'.format(seasonName, durationKey)) else: raise SoftException('Unknown rent type [{}]!'.format(rentType)) if not self.item.isDisabledForBuy and not self.item.isHidden: buyOption = makeString(SYSTEM_MESSAGES.VEHICLE_RENT_BUYOPTION) else: buyOption = '' return makeI18nSuccess('vehicle_rent/success', vehName=self.item.userName, rentPackageName=rentPackageName, price=formatPrice(self.price), type=self._getSysMsgType(), buyOption=buyOption)
def _getRentData(self, vehicle, vehiclePricesActionData): result = [] rentPackages = vehicle.rentPackages for rentPackage in rentPackages: rentID = rentPackage['rentID'] rentType, packageID = parseRentID(rentID) if rentType == constants.RentType.TIME_RENT: label = i18n.makeString(MENU.SHOP_MENU_VEHICLE_RENT_DAYS, days=packageID) enabled = isWithinMaxRentTime(vehicle.maxRentDuration, vehicle.rentLeftTime, packageID) elif rentType == constants.RentType.SEASON_RENT: seasonType = rentPackage['seasonType'] label = i18n.makeString(MENU.SHOP_MENU_VEHICLE_RENT_SEASON, season=packageID, seasonType=seasonType) enabled = True elif rentType == constants.RentType.SEASON_CYCLE_RENT: seasonType = rentPackage['seasonType'] label = i18n.makeString(MENU.SHOP_MENU_VEHICLE_RENT_CYCLE, cycle=packageID, seasonType=seasonType) enabled = True else: raise SoftException( 'Unknown rentType=[{}] in rentPackages ID [{}]!'.format( rentType, rentID)) actionRentPrice = None if rentPackage['rentPrice'] != rentPackage['defaultRentPrice']: actionRentPrice = packItemRentActionTooltipData( vehicle, rentPackage) result.append({ 'itemId': rentID, 'label': label, 'price': rentPackage['rentPrice'].toMoneyTuple(), 'enabled': enabled, 'actionPrice': actionRentPrice }) result = self._addPriceBlock(result, vehicle, vehiclePricesActionData) selectedId = -1 for ddItem in result: if ddItem['enabled']: selectedId = ddItem['itemId'] break return {'data': result, 'selectedId': selectedId}
def __getInitialVO(self): vehicle = self.itemsCache.items.getItemByCD(self.__vehicleIntCD) isEnoughStatuses = getMoneyVO( Money.makeFromMoneyTuple((True, True, True))) rentalTermSlots = [] isRestoreAvailable = vehicle.isRestoreAvailable() if isRestoreAvailable: enabled = isRestoreAvailable or not (constants.IS_CHINA and vehicle.rentalIsActive) rentalTermSlots.append({ 'itemId': -1, 'label': i18n.makeString(STORE.BUYVEHICLEWINDOW_RESTORE), 'price': getItemPricesVO( ItemPrice(vehicle.restorePrice, vehicle.restorePrice)), 'enabled': enabled, 'selected': self.__selectedRentID <= _NOT_RENT_IDX, 'isEnoughStatuses': isEnoughStatuses }) rentPackages = vehicle.rentPackages currentSeasonRent = vehicle.currentSeasonRent isSeasonRented = currentSeasonRent is not None for rentPackageIdx, rentPackage in enumerate(rentPackages): rentID = rentPackage['rentID'] rentType, packageID = parseRentID(rentID) if rentType == constants.RentType.TIME_RENT: days = packageID standardRentDays = STORE.getRentTermDays(days) if standardRentDays is not None: label = standardRentDays else: label = i18n.makeString( STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTANY, days=days) inMaxRentTime = isWithinMaxRentTime(vehicle.maxRentDuration, vehicle.rentLeftTime, days) enabled = not isSeasonRented and inMaxRentTime elif rentType in (constants.RentType.SEASON_RENT, constants.RentType.SEASON_CYCLE_RENT): seasonType = rentPackage['seasonType'] label = i18n.makeString( _SEASON_RENT_TERMS[seasonType][rentType]) if rentType == constants.RentType.SEASON_RENT: enabled = not isSeasonRented or isSeasonRented and currentSeasonRent.duration == SeasonRentDuration.SEASON_CYCLE else: enabled = not isSeasonRented else: raise SoftException( 'Unsupported rental type [{}]!'.format(rentType)) price = ItemPrice(rentPackage['rentPrice'], rentPackage['defaultRentPrice']) rentalTermSlots.append({ 'itemId': rentPackageIdx, 'label': label, 'price': getItemPricesVO(price), 'enabled': enabled, 'selected': self.__selectedRentID == rentID, 'isEnoughStatuses': isEnoughStatuses }) if not isRestoreAvailable: enabled = not vehicle.isDisabledForBuy and not vehicle.isHidden rentalTermSlots.append({ 'itemId': _NOT_RENT_IDX, 'label': i18n.makeString( STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTUNLIM), 'price': getItemPricesVO(vehicle.buyPrices.itemPrice), 'enabled': enabled, 'selected': self.__selectedRentID <= _NOT_RENT_IDX, 'isEnoughStatuses': isEnoughStatuses }) return { 'titleLabel': text_styles.highTitle(STORE.RENTALTERMSELECTIONPOPOVER_TITLELABEL), 'rentalTermSlots': rentalTermSlots }