예제 #1
0
def get_unfinalized_cart_block(currency, days=14):
    days = int(days)

    early_cutoff = now() - datetime.timedelta(days=days)
    # The `hours` value for `late_cutoff` should maybe be tunable somehow.
    # Either way, we're currently considering baskets abandoned if they've been
    # unupdated for two hours.
    late_cutoff = now() - datetime.timedelta(hours=2)

    data = (StoredBasket.objects.filter(currency=currency).filter(
        updated_on__range=(early_cutoff, late_cutoff),
        product_count__gte=0).exclude(deleted=True, finished=True).aggregate(
            count=Count("id"), sum=Sum("taxful_total_price_value")))
    if not data["count"]:
        return

    return DashboardMoneyBlock(
        id="abandoned_carts_%d" % days,
        color="red",
        title=_("Abandoned Cart Value"),
        value=(data.get("sum") or 0),
        currency=currency,
        icon="fa fa-calculator",
        subtitle=_("Based on {b} carts over the last {d} days").format(
            b=data.get("count"), d=days))
예제 #2
0
def get_avg_purchase_size_block(request, currency=None):
    orders = get_orders_for_shop(request)
    shop = request.shop
    if not currency:
        currency = shop.currency

    lifetime_sales_data = orders.complete().aggregate(
        count=Count("id"),
        sum=Sum("taxful_total_price_value")
    )

    # Average size of purchase with amount of orders it is calculated from
    average_purchase_size = (
        Order.objects.filter(shop=shop)
        .aggregate(count=Count("id"), sum=Avg("taxful_total_price_value")))
    return DashboardMoneyBlock(
        id="average_purchase_sum",
        color="blue",
        title=_("Average Purchase"),
        value=(average_purchase_size.get("sum") or 0),
        currency=currency,
        icon="fa fa-shopping-cart",
        subtitle=get_subtitle(lifetime_sales_data.get("count")),
        sort_order=1
    )
예제 #3
0
 def get_dashboard_blocks(self, request):
     return [
         DashboardContentBlock(id="test-0", content="Hello",
                               size="invalid"),
         DashboardValueBlock(id="test-1", value="yes", title="hi"),
         DashboardNumberBlock(id="test-2", value=35, title="hello"),
         DashboardNumberBlock(id="test-3", value=35.3, title="hello"),
         DashboardMoneyBlock(id="test-4",
                             value=35,
                             title="hola",
                             currency="USD"),
     ]
예제 #4
0
파일: dashboard.py 프로젝트: zarlant/shuup
def get_sales_of_the_day_block(request, currency):
    orders = get_orders_by_currency(currency)
    # Sales of the day
    todays_order_data = (orders.complete().since(0).aggregate(
        count=Count("id"), sum=Sum("taxful_total_price_value")))

    return DashboardMoneyBlock(id="todays_order_sum",
                               color="green",
                               title=_("Today's Sales"),
                               value=(todays_order_data.get("sum") or 0),
                               currency=currency,
                               icon="fa fa-calculator",
                               subtitle=get_subtitle(
                                   todays_order_data.get("count")))
예제 #5
0
파일: dashboard.py 프로젝트: zarlant/shuup
def get_lifetime_sales_block(request, currency):
    orders = get_orders_by_currency(currency)

    # Lifetime sales
    lifetime_sales_data = orders.complete().aggregate(
        count=Count("id"), sum=Sum("taxful_total_price_value"))

    return DashboardMoneyBlock(id="lifetime_sales_sum",
                               color="green",
                               title=_("Lifetime Sales"),
                               value=(lifetime_sales_data.get("sum") or 0),
                               currency=currency,
                               icon="fa fa-line-chart",
                               subtitle=get_subtitle(
                                   lifetime_sales_data.get("count")))
예제 #6
0
파일: dashboard.py 프로젝트: zarlant/shuup
def get_open_orders_block(request, currency):
    orders = get_orders_by_currency(currency)

    # Open orders / open orders value
    open_order_data = (orders.incomplete().aggregate(
        count=Count("id"), sum=Sum("taxful_total_price_value")))

    return DashboardMoneyBlock(
        id="open_orders_sum",
        color="orange",
        title=_("Open Orders Value"),
        value=TaxfulPrice((open_order_data.get("sum") or 0), currency),
        currency=currency,
        icon="fa fa-inbox",
        subtitle=get_subtitle(open_order_data.get("count")))
예제 #7
0
def get_open_orders_block(request, currency=None):
    orders = get_orders_for_shop(request)
    if not currency:
        shop = request.shop
        currency = shop.currency

    # Open orders / open orders value
    open_order_data = orders.incomplete().aggregate(count=Count("id"), sum=Sum("taxful_total_price_value"))

    return DashboardMoneyBlock(
        id="open_orders_sum",
        color="orange",
        title=_("Open Orders Value"),
        value=TaxfulPrice((open_order_data.get("sum") or 0), currency),
        currency=currency,
        icon="fa fa-inbox",
        subtitle=get_subtitle(open_order_data.get("count")),
        sort_order=1,
    )