def test_printouts_no_addresses(rf): try: import weasyprint except ImportError: pytest.skip() shop = get_default_shop() supplier = get_default_supplier() product = create_product("simple-test-product", shop) order = create_order_with_product(product, supplier, 6, 6, shop=shop) order.billing_address = None order.save() shipment = order.create_shipment_of_all_products(supplier) request = rf.get("/") response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200 order.shipping_address = None order.save() response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200
def test_printouts_no_addresses(rf): try: import weasyprint except ImportError: pytest.skip() shop = get_default_shop() supplier = get_default_supplier() product = create_product("simple-test-product", shop) order = create_order_with_product(product, supplier, 6, 6, shop=shop) order.billing_address = None order.save() shipment = order.create_shipment_of_all_products(supplier) request = apply_request_middleware(rf.get("/"), user=get_default_staff_user()) response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200 order.shipping_address = None order.save() response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200
def process(self, request, ids): if isinstance(ids, six.string_types) and ids == "all": return JsonResponse( {"error": ugettext("Selecting all is not supported.")}) shipment_ids = set( Shipment.objects.filter(order_id__in=ids).values_list("id", flat=True)) if len(shipment_ids) == 1: try: response = get_delivery_pdf(request, ids[0]) response[ 'Content-Disposition'] = 'attachment; filename=shipment_%s_delivery.pdf' % ids[ 0] return response except Exception as e: msg = e.message if hasattr(e, "message") else e return JsonResponse({"error": force_text(msg)}) buff = BytesIO() archive = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED) added = 0 errors = [] for id in shipment_ids: try: pdf_file = get_delivery_pdf(request, id) filename = "shipment_%d_delivery.pdf" % id archive.writestr(filename, pdf_file.content) added += 1 except Exception as e: msg = e.message if hasattr(e, "message") else e errors.append(force_text(msg)) continue if added: archive.close() buff.flush() ret_zip = buff.getvalue() buff.close() response = HttpResponse(content_type='application/zip') response[ 'Content-Disposition'] = 'attachment; filename=order_delivery_pdf.zip' response.write(ret_zip) return response return JsonResponse({"errors": errors})
def test_delivery_and_confirmation_pdf(shop, supplier): product = create_product("simple-test-product-%s-" % shop.pk, shop) order = create_order_with_product(product, supplier, 6, 6, shop=shop) shipment = order.create_shipment_of_all_products(supplier) request = apply_request_middleware(rf.get("/"), user=get_default_staff_user()) response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200
def process(self, request, ids): if isinstance(ids, six.string_types) and ids == "all": return JsonResponse({"error": ugettext("Selecting all is not supported.")}) shipment_ids = set(Shipment.objects.filter(order_id__in=ids).values_list("id", flat=True)) if len(shipment_ids) == 1: try: shipment_id = shipment_ids.pop() response = get_delivery_pdf(request, shipment_id) response['Content-Disposition'] = 'attachment; filename=shipment_%s_delivery.pdf' % shipment_id return response except Exception as e: msg = e.message if hasattr(e, "message") else e return JsonResponse({"error": force_text(msg)}) buff = BytesIO() archive = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED) added = 0 errors = [] for id in shipment_ids: try: pdf_file = get_delivery_pdf(request, id) filename = "shipment_%d_delivery.pdf" % id archive.writestr(filename, pdf_file.content) added += 1 except Exception as e: msg = e.message if hasattr(e, "message") else e errors.append(force_text(msg)) continue if added: archive.close() buff.flush() ret_zip = buff.getvalue() buff.close() response = HttpResponse(content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=order_delivery_pdf.zip' response.write(ret_zip) return response return JsonResponse({"errors": errors})
def process(self, request, ids): if len(ids) == 1: try: response = get_delivery_pdf(request, ids[0]) response[ 'Content-Disposition'] = 'attachment; filename=order_%s_delivery.pdf' % ids[ 0] return response except Exception as e: msg = e.message if hasattr(e, "message") else e return JsonResponse({"error": force_text(msg)}) buff = BytesIO() archive = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED) added = 0 errors = [] for id in ids: try: pdf_file = get_delivery_pdf(request, id) filename = "order_%d_delivery.pdf" % id archive.writestr(filename, pdf_file.content) added += 1 except Exception as e: msg = e.message if hasattr(e, "message") else e errors.append(force_text(msg)) continue if added: archive.close() buff.flush() ret_zip = buff.getvalue() buff.close() response = HttpResponse(content_type='application/zip') response[ 'Content-Disposition'] = 'attachment; filename=order_delivery_pdf.zip' response.write(ret_zip) return response return JsonResponse({"errors": errors})
def test_printouts(rf): try: import weasyprint except ImportError: pytest.skip() shop = get_default_shop() supplier = get_default_supplier() product = create_product("simple-test-product", shop) order = create_order_with_product(product, supplier, 6, 6, shop=shop) shipment = order.create_shipment_of_all_products(supplier) request = rf.get("/") response = get_delivery_pdf(request, shipment.id) assert response.status_code == 200 response = get_confirmation_pdf(request, order.id) assert response.status_code == 200