def handle(self, *args, **options): from tendenci.addons.recurring_payments.models import RecurringPayment from tendenci.addons.recurring_payments.utils import run_a_recurring_payment verbosity = int(options['verbosity']) recurring_payments = RecurringPayment.objects.filter(status_detail='active', status=True) for rp in recurring_payments: run_a_recurring_payment(rp, verbosity)
def run_now(request): """Run a recurring payment. """ rp_id = request.POST.get('rp_id') rp = get_object_or_404(RecurringPayment, pk=rp_id) result_data = {} result_data['processed'] = 'false' result_data['reason'] = 'done' payment_profiles = PaymentProfile.objects.filter( customer_profile_id=rp.customer_profile_id, status=True, status_detail='active' ).order_by('-update_dt') if not payment_profiles: valid_cpp_ids, invalid_cpp_ids = rp.populate_payment_profile() #print valid_cpp_ids, invalid_cpp_ids if valid_cpp_ids: payment_profiles = PaymentProfile.objects.filter( customer_profile_id=valid_cpp_ids[0]) if not payment_profiles: result_data['reason'] = 'not setup' else: if rp.status_detail == 'active': num_processed = run_a_recurring_payment(rp) if num_processed: result_data['processed'] = 'true' result_data['reason'] = 'processed' # get total_paid and balance for this rp result_data['total_paid'] = str(rp.total_paid) result_data['balance'] = str(rp.get_outstanding_balance()) # get total amount received for all rps d = RecurringPaymentInvoice.objects.filter( invoice__balance=0, ).aggregate(total_amount_received=Sum('invoice__total')) result_data['total_amount_received'] = d['total_amount_received'] if not result_data['total_amount_received']: result_data['total_amount_received'] = 0 result_data['total_amount_received'] = tcurrency(result_data['total_amount_received']) return HttpResponse(simplejson.dumps(result_data))
def run_now(request): """Run a recurring payment. """ rp_id = request.POST.get('rp_id') rp = get_object_or_404(RecurringPayment, pk=rp_id) result_data = {} result_data['processed'] = 'false' result_data['reason'] = 'done' payment_profiles = PaymentProfile.objects.filter( customer_profile_id=rp.customer_profile_id, status=True, status_detail='active').order_by('-update_dt') if not payment_profiles: valid_cpp_ids, invalid_cpp_ids = rp.populate_payment_profile() #print valid_cpp_ids, invalid_cpp_ids if valid_cpp_ids: payment_profiles = PaymentProfile.objects.filter( customer_profile_id=valid_cpp_ids[0]) if not payment_profiles: result_data['reason'] = 'not setup' else: if rp.status_detail == 'active': num_processed = run_a_recurring_payment(rp) if num_processed: result_data['processed'] = 'true' result_data['reason'] = 'processed' # get total_paid and balance for this rp result_data['total_paid'] = str(rp.total_paid) result_data['balance'] = str(rp.get_outstanding_balance()) # get total amount received for all rps d = RecurringPaymentInvoice.objects.filter( invoice__balance=0, ).aggregate( total_amount_received=Sum('invoice__total')) result_data['total_amount_received'] = d[ 'total_amount_received'] if not result_data['total_amount_received']: result_data['total_amount_received'] = 0 result_data['total_amount_received'] = tcurrency( result_data['total_amount_received']) return HttpResponse(simplejson.dumps(result_data))