def billings_pdf(request, id): billing_id = int(id) billing = Billing.objects.get(id=billing_id) articles = Article.objects.filter(billing_id=billing_id) get_sum_total_of_billing(billing_id) company = Company.objects.get(pk=billing.company_id) code = get_code_control(billing) qr_text = build_string_qr(billing) literal_amount = num2words(int(billing.total_billing), lang='es') decimal_amount = get_decimal_amount(billing_id) limit_date = billing.register_date + timedelta(days=90) html_string = render_to_string('billings/pdf.html', { 'pagesize': 'letter', 'company': company, 'billing': billing, 'instance_model': Billing, 'instance_model_b': Article, 'articles': articles, 'code_control': code, 'qr_text': qr_text, 'literal_amount': literal_amount, 'decimal_amount': decimal_amount, 'limit_date': limit_date, }, context_instance=RequestContext(request)) return build_pdf(html_string)
def billings_show(request, id): billing_id = int(id) billing = Billing.objects.get(id=billing_id) if billing.is_sale and billing.is_electronic: get_sum_total_of_billing(billing_id) billing = Billing.objects.get(id=billing_id) articles = Article.objects.filter(billing_id=billing_id) if request.method == 'POST': form = ArticleForm(request.POST) if form.is_valid(): save = form.save() form = ArticleForm message = 'Artículo agregado!' messages.add_message(request, messages.SUCCESS, message) return HttpResponseRedirect(reverse('billings-show', kwargs={'id': billing_id})) else: message = 'Se encontraron errores!' messages.add_message(request, messages.ERROR, message) else: form = ArticleForm if billing.is_sale: code = get_code_control(billing) else: code = billing.code qr_text = build_string_qr(billing) return render(request, 'billings/show.html', { 'form': form, 'billing': billing, 'instance_model': Billing, 'instance_model_b': Article, 'articles': articles, 'code_control': code, 'qr_text': qr_text })