コード例 #1
0
ファイル: tests.py プロジェクト: ZhiephieCook/cdr-stats
 def test_rebilling(self):
     """Test task : RebillingTask"""
     tday = datetime.today()
     voipplan_id = 1
     end_date = datetime(tday.year, tday.month, tday.day,
                         tday.hour, tday.minute, tday.second, tday.microsecond)
     start_date = end_date + relativedelta(days=-1)
     call_kwargs = {}
     call_kwargs['start_uepoch'] = {'$gte': start_date, '$lt': end_date}
     result = RebillingTask.delay(call_kwargs, voipplan_id)
コード例 #2
0
ファイル: tests.py プロジェクト: rewvad/test-cdr
 def test_rebilling(self):
     """Test task : RebillingTask"""
     tday = datetime.today()
     voipplan_id = 1
     end_date = datetime(tday.year, tday.month, tday.day, tday.hour,
                         tday.minute, tday.second, tday.microsecond)
     start_date = end_date + relativedelta(days=-1)
     call_kwargs = {}
     call_kwargs['start_uepoch'] = {'$gte': start_date, '$lt': end_date}
     result = RebillingTask.delay(call_kwargs, voipplan_id)
コード例 #3
0
ファイル: admin.py プロジェクト: rewvad/test-cdr
    def rebilling(self, request):
        """
        Re-billing successful VoIP Calls
        """
        opts = VoIPPlan._meta
        # default values for form
        tday = datetime.today()
        to_date = from_date = tday.strftime('%Y-%m-%d')
        form = RebillForm(request.POST or None,
                          initial={'from_date': from_date, 'to_date': to_date,
                                   'confirmation': CONFIRMATION_TYPE.NO})
        call_rebill_count = 0
        if request.method == 'POST':
            form = RebillForm(request.POST)
            if "from_date" in request.POST:
                # From
                from_date = request.POST['from_date']
                start_date = ceil_strdate(from_date, 'start')

            if "to_date" in request.POST:
                # To
                to_date = request.POST['to_date']
                end_date = ceil_strdate(to_date, 'end')

            call_kwargs = {}
            daily_kwargs = {}
            monthly_kwargs = {}
            if start_date and end_date:
                call_kwargs['start_uepoch'] = {'$gte': start_date, '$lt': end_date}

                # get kwargs for aggregate
                daily_kwargs['metadata.date'] = {'$gte': start_date.strftime('%Y-%m-%d'),
                                                 '$lt': end_date.strftime('%Y-%m-%d')}
                monthly_kwargs['metadata.date'] = {'$gte': start_date.strftime('%Y-%m'),
                                                   '$lt': end_date.strftime('%Y-%m')}

            if not request.user.is_superuser:  # not superuser
                call_kwargs['accountcode'] = request.user.userprofile.accountcode
                monthly_kwargs['metadata.accountcode'] =\
                    daily_kwargs['metadata.accountcode'] = call_kwargs['accountcode']

            # Get total no of calls which are going to rebill
            # call_rebill_count = mongodb.cdr_common.find(call_kwargs).count()

            if "confirmation" in request.POST:
                confirmation = request.POST.get('confirmation')
                # To confirm re-billing
                if confirmation == CONFIRMATION_TYPE.NO:
                    request.POST['confirmation'] = CONFIRMATION_TYPE.YES
                    form.fields['from_date'].widget = form.fields['to_date'].widget = forms.HiddenInput()
                    ctx = RequestContext(request, {
                        'form': form,
                        'start_date': start_date,
                        'end_date': end_date,
                        'opts': opts,
                        'model_name': opts.object_name.lower(),
                        'title': _('Rebill VoIP Call'),
                        'call_rebill_count': call_rebill_count,
                        'CONFIRMATION_TYPE': CONFIRMATION_TYPE,
                    })
                    return render_to_response('admin/voip_billing/voipplan/rebilling.html', context_instance=ctx)

                voipplan_id = request.user.userprofile.voipplan_id

                # re-billing is confirmed by user
                if confirmation == CONFIRMATION_TYPE.YES:
                    if call_rebill_count != 0:
                        # Rebill all calls
                        RebillingTask.delay(call_kwargs, voipplan_id)

                    msg = _('Re-billing is done')
                    messages.info(request, msg)
                    request.POST['confirmation'] = CONFIRMATION_TYPE.NO
                    call_rebill_count = 0

        ctx = RequestContext(request, {
            'form': form,
            'opts': opts,
            'model_name': opts.object_name.lower(),
            'title': _('Rebill VoIP Call'),
            'call_rebill_count': call_rebill_count,
        })
        return render_to_response('admin/voip_billing/voipplan/rebilling.html', context_instance=ctx)