def make_second_copy(request, invoice): user = request.user invoice = Invoice.objects.get(pk=invoice) aux = Invoice.objects.filter(status=1, organization=invoice.organization, due_date__gt=datetime.now()).count() if aux <= 0: inv = Invoice() inv.organization = invoice.organization inv.due_date = datetime.now() + timedelta(days=7) inv.expiry_date = invoice.expiry_date inv.ammount = invoice.ammount inv.discount = invoice.discount inv.status = 1 inv.plan = invoice.plan inv.save() invoice.status = 3 invoice.save() data = BradescoBilletData.objects.all()[0] billet_url = gera_boleto_bradesco(request.user.id, inv, days=data.default_second_copy_days, second_copy=True) inv.billet_url = billet_url inv.save() aux = True message = 'Second copy details saved successfully' else: message = 'Second copy not generated: there are billets that still requiring payment.' aux = False return render_to_response('organization/second_copy.html', locals(), context_instance=RequestContext(request))