def test_total_sales_customers_report(rf): shop = get_default_shop() supplier = get_default_supplier(shop) p1 = create_product("p1", shop=shop, supplier=supplier, default_price="5") p2 = create_product("p2", shop=shop, supplier=supplier, default_price="20") # orders for person 1 person1 = create_random_person() order1 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2]) order2 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2]) # orders for person 2 person2 = create_random_person() order3 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) order4 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) order5 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) # pay orders [o.create_payment(o.taxful_total_price) for o in Order.objects.all()] data = { "report": TotalSales.get_name(), "shop": shop.pk, "date_range": DateRangeChoices.ALL_TIME, "writer": "json", "force_download": 1, } report = TotalSales(**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(TotalSales.title) in json_data.get("heading") data = json_data.get("tables")[0].get("data")[0] avg_sales = (order1.taxful_total_price + order2.taxful_total_price + order3.taxful_total_price + order4.taxful_total_price + order5.taxful_total_price) / Decimal(5) assert int(data["customers"]) == 2 assert int(data["order_amount"]) == 5 assert data["customer_avg_sale"] == str( avg_sales.value.quantize(Decimal('0.01')))
def test_total_sales_customers_report(rf): shop = get_default_shop() supplier = get_default_supplier() p1 = create_product("p1", shop=shop, supplier=supplier, default_price="5") p2 = create_product("p2", shop=shop, supplier=supplier, default_price="20") # orders for person 1 person1 = create_random_person() order1 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2]) order2 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2]) # orders for person 2 person2 = create_random_person() order3 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) order4 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) order5 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2]) # pay orders [o.create_payment(o.taxful_total_price) for o in Order.objects.all()] data = { "report": TotalSales.get_name(), "shop": shop.pk, "date_range": DateRangeChoices.ALL_TIME, "writer": "json", "force_download": 1, } report = TotalSales(**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(TotalSales.title) in json_data.get("heading") data = json_data.get("tables")[0].get("data")[0] avg_sales = ( order1.taxful_total_price + order2.taxful_total_price + order3.taxful_total_price + order4.taxful_total_price + order5.taxful_total_price ) / Decimal(5) assert int(data["customers"]) == 2 assert int(data["order_amount"]) == 5 assert data["customer_avg_sale"] == str(avg_sales.value.quantize(Decimal('0.01')))