def test_refunds_report(rf): shop = get_default_shop() get_default_tax_class() creator = OrderCreator() source1 = seed_source() source2 = seed_source() source3 = seed_source() source4 = seed_source() order1 = creator.create_order(source1) order2 = creator.create_order(source2) order3 = creator.create_order(source3) order4 = creator.create_order(source4) # pay orders [o.create_payment(o.taxful_total_price) for o in Order.objects.all()] order1.create_full_refund() order2.create_refund( [{"line": order2.lines.first(), "amount": order2.taxful_total_price.amount * Decimal(0.5), "quantity": 1}] ) order3.create_refund( [{"line": order3.lines.first(), "amount": order3.taxful_total_price.amount * Decimal(0.3), "quantity": 1}] ) order4.create_refund( [{"line": order4.lines.first(), "amount": order4.taxful_total_price.amount * Decimal(0.1), "quantity": 1}] ) total_refunded = (order1.get_total_refunded_amount() + order2.get_total_refunded_amount() + order3.get_total_refunded_amount() + order4.get_total_refunded_amount()) data = { "report": RefundedSalesReport.get_name(), "shop": shop.pk, "date_range": DateRangeChoices.ALL_TIME, "writer": "json", "force_download": 1, } report = RefundedSalesReport(**data) writer = get_writer_instance(data["writer"]) response = writer.get_response(report=report) if hasattr(response, "render"): response.render() json_data = json.loads(response.content.decode("utf-8")) assert force_text(RefundedSalesReport.title) in json_data.get("heading") data = json_data.get("tables")[0].get("data") assert len(data) == 1 data = data[0] expected_data = { "refunded_orders": "4", "total_refunded": str(total_refunded.value) } for k, v in expected_data.items(): assert data[k] == v