Exemplo n.º 1
0
def del_addonservice(account_id, account_service_id):

    #Получаем нужные параметры аккаунта
    #connection.commit()
    account = Account.objects.filter(id=account_id)

    if not account:
        return 'ACCOUNT_DOES_NOT_EXIST'
            
            
    account = account[0]
    #Получаем нужные параметры услуги абонента
    
    accountservice = AccountAddonService.objects.filter(id=account_service_id)

    if not accountservice:
        return 'ACCOUNT_ADDON_SERVICE_DOES_NOT_EXIST'
    accountservice = accountservice[0]

    service = accountservice.service
    
    if service.cancel_subscription:
        
        if service.wyte_period:

            settlement_period = service.wyte_period

            settlement_period_start, settlement_period_end, delta = settlement_period_info(settlement_period.time_start, settlement_period.length_in, settlement_period.length)

        else:
            delta = 0
        now = datetime.datetime.now()
        
        if (((now-accountservice.activated).seconds+(now-accountservice.activated).days*86400)<delta) or (service.wyte_cost and delta == 0):

            ast = AddonServiceTransaction()
            ast.account = account
            ast.type = TransactionType.objects.get(internal_name='ADDONSERVICE_WYTE_PAY')
            ast.summ = service.wyte_cost
            ast.service = service
            ast.service_type = service.service_type
            ast.created = now
            if account.get_accounttarif():
                ast.accounttarif = account.get_accounttarif()
            ast.accountaddonservice = accountservice
            
            ast.save()
            
        #Отключаем услугу

        accountservice.deactivated=now
        accountservice.save()
        return True
    else:
        return 'NO_CANCEL_SUBSCRIPTION'
    return False
Exemplo n.º 2
0
def del_addonservice(account_id, account_service_id):

    #Получаем нужные параметры аккаунта
    #connection.commit()
    account = Account.objects.filter(id=account_id)

    if not account:
        return 'ACCOUNT_DOES_NOT_EXIST'
            
            
    account = account[0]
    #Получаем нужные параметры услуги абонента
    
    accountservice = AccountAddonService.objects.filter(id=account_service_id)

    if not accountservice:
        return 'ACCOUNT_ADDON_SERVICE_DOES_NOT_EXIST'
    accountservice = accountservice[0]

    service = accountservice.service
    
    if service.cancel_subscription:
        
        if service.wyte_period:

            settlement_period = service.wyte_period

            settlement_period_start, settlement_period_end, delta = settlement_period_info(settlement_period.time_start, settlement_period.length_in, settlement_period.length)

        else:
            delta = 0
        now = datetime.datetime.now()
        
        if (((now-accountservice.activated).seconds+(now-accountservice.activated).days*86400)<delta) or (service.wyte_cost and delta == 0):

            ast = AddonServiceTransaction()
            ast.account = account
            ast.type = TransactionType.objects.get(internal_name='ADDONSERVICE_WYTE_PAY')
            ast.summ = service.wyte_cost
            ast.service = service
            ast.service_type = service.service_type
            ast.created = now
            if account.get_accounttarif():
                ast.accounttarif = account.get_accounttarif()
            ast.accountaddonservice = accountservice
            
            ast.save()
            
        #Отключаем услугу

        accountservice.deactivated=now
        accountservice.save()
        return True
    else:
        return 'NO_CANCEL_SUBSCRIPTION'
    return False
Exemplo n.º 3
0
def traffic_limit_row(trafficlimit, user, iter_nom, last=False):
    settlement_period = trafficlimit.settlement_period or trafficlimit.tarif.settlement_period
    cursor = connection.cursor()
    if settlement_period and settlement_period.autostart==True:
        cursor.execute("""SELECT datetime FROM billservice_accounttarif WHERE account_id=%s and datetime<now() ORDER BY datetime DESC LIMIT 1""" % (user.id)) 
        sp_start = cursor.fetchone()
        sp_start = sp_start[0]
    else:
        settlement_period = user.get_account_tariff().settlement_period
        sp_start = settlement_period.time_start if settlement_period else None
    from billservice.utility import settlement_period_info
    settlement_period_start, settlement_period_end, delta = settlement_period_info(time_start=sp_start, repeat_after=settlement_period.length_in, repeat_after_seconds=settlement_period.length)
    #если нужно считать количество трафика за последнеие N секунд, а не за рачётный период, то переопределяем значения
    if trafficlimit.mode==True:
        now=datetime.datetime.now()
        settlement_period_start=now-datetime.timedelta(seconds=delta)
        settlement_period_end=now
    
    cursor.execute ("""SELECT sum(bytes) as size FROM billservice_groupstat
                        WHERE group_id=%s and account_id=%s and datetime>%s and datetime<%s 
                        """, (trafficlimit.group_id, user.id, settlement_period_start,  settlement_period_end))
    summ = cursor.fetchone()
    try:
        summ = summ[0]/(1024*1024)
    except:
        summ = 0 
    try:
        stay = trafficlimit.size/(1024*1024)
    except:
        stay = 0
    return {
            'trafficlimit': trafficlimit,
            'settlement_period_start': settlement_period_start,
            'settlement_period_end': settlement_period_end,
            'summ':summ,
            'stay':stay,
            'iter_nom':iter_nom,
            'last':last,
            }
Exemplo n.º 4
0
def add_addonservice(account_id, service_id, subaccount_id=None, ignore_locks = False, activation_date = None):
    #Получаем параметры абонента
    account = Account.objects.filter(id=account_id)

    if not account:
        return 'ACCOUNT_DOES_NOT_EXIST'
            
    account = account[0]
    #print account_id
    now = datetime.datetime.now()
    accountaddonservices = AccountAddonService.objects.filter(account=account, service__id=service_id).filter(Q(deactivated__gt=now) | Q(deactivated__isnull=True))

    
    if accountaddonservices:
        return 'SERVICE_ARE_ALREADY_ACTIVATED'
            
    service = AddonService.objects.filter(id=service_id)

    if service==[]:
        return 'ADDON_SERVICE_DOES_NOT_EXIST'
            
    service = service[0]



    if service.change_speed and ignore_locks==False:


        aas = AccountAddonService.objects.filter(account = account, service__change_speed=True, deactivated__isnull=True)

        if aas:

            return "ALERADY_HAVE_SPEED_SERVICE"

    # Проверка на возможность активации услуги при наличии блокировок
    if not ignore_locks:
        if service.allow_activation==False and (account.ballance<=0 or account.balance_blocked==True or account.disabled_by_limit==True or account.status!=1):
            return "ACCOUNT_BLOCKED"
    
    tarif_service = AddonServiceTarif.objects.filter(service=service, tarif=account.get_account_tariff())
    #Получаем нужные параметры услуги из тарифного плана

    
    if ignore_locks==False and tarif_service==[]:
        return 'ADDONSERVICE_TARIF_DOES_NOT_ALLOWED'

    tarif_service=tarif_service[0]  
    

    if tarif_service.activation_count!=0 and ignore_locks==False:

        if tarif_service.activation_count_period:

            

            settlement_period = tarif_service.activation_count_period
            if settlement_period.autostart:
                settlement_period.time_start = account.get_accounttariff().datetime
                
            settlement_period_start, settlement_period_end, delta = settlement_period_info(settlement_period.time_start, settlement_period.length_in, settlement_period.length)
            
            aas = AccountAddonService.objects.filter(account=account, service=service, activated__gte=settlement_period_start, activated__lte=settlement_period_end).count()
        else:
            aas = AccountAddonService.objects.filter(account=account, service=service).count()
        
                
        if aas>=tarif_service.activation_count: return "TOO_MUCH_ACTIVATIONS"
        

    accountaddonservice = AccountAddonService()
    accountaddonservice.service = service
    accountaddonservice.account = account

    if activation_date:
        accountaddonservice.activated = activation_date
       
    else:
        accountaddonservice.activated = now
    
    accountaddonservice.save()
    return True
Exemplo n.º 5
0
def add_addonservice(account_id, service_id, subaccount_id=None, ignore_locks = False, activation_date = None):
    #Получаем параметры абонента
    account = Account.objects.filter(id=account_id)

    if not account:
        return 'ACCOUNT_DOES_NOT_EXIST'
            
    account = account[0]
    #print account_id
    now = datetime.datetime.now()
    accountaddonservices = AccountAddonService.objects.filter(account=account, service__id=service_id).filter(Q(deactivated__gt=now) | Q(deactivated__isnull=True))

    
    if accountaddonservices:
        return 'SERVICE_ARE_ALREADY_ACTIVATED'
            
    service = AddonService.objects.filter(id=service_id)

    if service==[]:
        return 'ADDON_SERVICE_DOES_NOT_EXIST'
            
    service = service[0]



    if service.change_speed and ignore_locks==False:


        aas = AccountAddonService.objects.filter(account = account, service__change_speed=True, deactivated__isnull=True)

        if aas:

            return "ALERADY_HAVE_SPEED_SERVICE"

    # Проверка на возможность активации услуги при наличии блокировок
    if not ignore_locks:
        if service.allow_activation==False and (account.ballance<=0 or account.balance_blocked==True or account.disabled_by_limit==True or account.status!=1):
            return "ACCOUNT_BLOCKED"
    
    tarif_service = AddonServiceTarif.objects.filter(service=service, tarif=account.get_account_tariff())
    #Получаем нужные параметры услуги из тарифного плана

    
    if ignore_locks==False and tarif_service==[]:
        return 'ADDONSERVICE_TARIF_DOES_NOT_ALLOWED'

    tarif_service=tarif_service[0]  
    

    if tarif_service.activation_count!=0 and ignore_locks==False:

        if tarif_service.activation_count_period:

            

            settlement_period = tarif_service.activation_count_period
            if settlement_period.autostart:
                settlement_period.time_start = account.get_accounttariff().datetime
                
            settlement_period_start, settlement_period_end, delta = settlement_period_info(settlement_period.time_start, settlement_period.length_in, settlement_period.length)
            
            aas = AccountAddonService.objects.filter(account=account, service=service, activated__gte=settlement_period_start, activated__lte=settlement_period_end).count()
        else:
            aas = AccountAddonService.objects.filter(account=account, service=service).count()
        
                
        if aas>=tarif_service.activation_count: return "TOO_MUCH_ACTIVATIONS"
        

    accountaddonservice = AccountAddonService()
    accountaddonservice.service = service
    accountaddonservice.account = account

    if activation_date:
        accountaddonservice.activated = activation_date
       
    else:
        accountaddonservice.activated = now
    
    accountaddonservice.save()
    return True