Exemplo n.º 1
0
def get_shop_overview_block(request, currency, for_date=None):
    end = to_aware(for_date, time=time.max) if for_date else local_now()
    start_of_day = to_aware(end.date(), time=time.min)
    start_of_month = start_of_day.replace(day=1)
    start_of_year = start_of_day.replace(month=1, day=1)
    daily = get_order_overview_for_date_range(currency, start_of_day, end)
    mtd = get_order_overview_for_date_range(currency, start_of_month, end)
    ytd = get_order_overview_for_date_range(currency, start_of_year, end)
    totals = get_orders_by_currency(currency).complete().aggregate(
        num_orders=Count("id"),
        num_customers=Count("customer", distinct=True),
        sales=Sum("taxful_total_price_value")
    )
    anon_orders = get_orders_by_currency(currency).complete().filter(customer__isnull=True).aggregate(
        num_orders=Count("id"))
    totals["num_customers"] += anon_orders["num_orders"]
    totals["sales"] = TaxfulPrice(totals["sales"] or 0, currency)
    block = DashboardContentBlock.by_rendering_template(
        "store_overview", request, "shuup/admin/sales_dashboard/_store_overview_dashboard_block.jinja", {
            "daily": daily,
            "mtd": mtd,
            "ytd": ytd,
            "totals": totals
        })
    block.size = "small"
    return block
Exemplo n.º 2
0
def get_shop_overview_block(request, currency, for_date=None):
    end = to_aware(for_date, time=time.max) if for_date else local_now()
    start_of_day = to_aware(end.date(), time=time.min)
    start_of_month = start_of_day.replace(day=1)
    start_of_year = start_of_day.replace(month=1, day=1)
    shop = request.shop

    if not currency:
        currency = shop.currency

    daily = get_order_overview_for_date_range(currency, start_of_day, end, shop=shop)
    mtd = get_order_overview_for_date_range(currency, start_of_month, end, shop=shop)
    ytd = get_order_overview_for_date_range(currency, start_of_year, end)
    totals = get_orders_by_currency(currency).complete().aggregate(
        num_orders=Count("id"),
        num_customers=Count("customer", distinct=True),
        sales=Sum("taxful_total_price_value")
    )
    anon_orders = get_orders_by_currency(currency).complete().filter(customer__isnull=True, shop=shop).aggregate(
        num_orders=Count("id"))
    totals["num_customers"] += anon_orders["num_orders"]
    totals["sales"] = TaxfulPrice(totals["sales"] or 0, currency)
    block = DashboardContentBlock.by_rendering_template(
        "store_overview", request, "shuup/admin/sales_dashboard/_store_overview_dashboard_block.jinja", {
            "daily": daily,
            "mtd": mtd,
            "ytd": ytd,
            "totals": totals
        })
    block.size = "medium"
    return block
Exemplo n.º 3
0
def test_interface_with_response(request):
    shop = get_shop(request)
    configuration.set(shop, MC_LAST_CHECK, to_timestamp(local_now()))

    if not interface_test(shop):
        configuration.set(shop, MC_CHECK_SUCCESS, False)
        return JsonResponse({"message": _("Testing configuration failed")}, status=400)

    configuration.set(shop, MC_CHECK_SUCCESS, True)
    return JsonResponse({"message": _("Configuration test successful")})
Exemplo n.º 4
0
def parse_date_range_preset(value):
    from shuup.reports.forms import DateRangeChoices
    now = local_now()
    if value == DateRangeChoices.TODAY:
        midnight = now.replace(hour=0, minute=0, second=0)
        tomorrow = midnight + datetime.timedelta(days=1) - datetime.timedelta(seconds=1)
        return (midnight, tomorrow)
    if value == DateRangeChoices.RUNNING_WEEK:
        return (now - datetime.timedelta(days=7), now)
    if value == DateRangeChoices.RUNNING_MONTH:
        return (now - datetime.timedelta(days=30), now)
    if value == DateRangeChoices.THIS_MONTH:
        return (now.replace(day=1), now)
    if value == DateRangeChoices.THIS_YEAR:
        return (now.replace(day=1, month=1), now)
    if value == DateRangeChoices.ALL_TIME:
        return (now.replace(year=2000), now)
Exemplo n.º 5
0
def parse_date_range_preset(value):
    from shuup.reports.forms import DateRangeChoices
    now = dates.local_now()
    today_start = now.replace(hour=0, minute=0, second=0)
    if value == DateRangeChoices.TODAY:
        return (today_start, now)
    elif value == DateRangeChoices.RUNNING_WEEK:
        return (today_start - datetime.timedelta(days=7), now)
    elif value == DateRangeChoices.THIS_WEEK:
        return (get_first_day_of_the_current_week(today_start), now)
    elif value == DateRangeChoices.RUNNING_MONTH:
        return (today_start - datetime.timedelta(days=30), now)
    elif value == DateRangeChoices.THIS_MONTH:
        return (today_start.replace(day=1), now)
    elif value == DateRangeChoices.THIS_YEAR:
        return (today_start.replace(day=1, month=1), now)
    elif value == DateRangeChoices.ALL_TIME:
        return (today_start.replace(year=2000), now)
Exemplo n.º 6
0
def parse_date_range_preset(value):
    from shuup.reports.forms import DateRangeChoices
    now = dates.local_now()
    today_start = now.replace(hour=0, minute=0, second=0)
    if value == DateRangeChoices.TODAY:
        return (today_start, now)
    elif value == DateRangeChoices.RUNNING_WEEK:
        return (today_start - datetime.timedelta(days=7), now)
    elif value == DateRangeChoices.THIS_WEEK:
        return (get_first_day_of_the_current_week(today_start), now)
    elif value == DateRangeChoices.RUNNING_MONTH:
        return (today_start - datetime.timedelta(days=30), now)
    elif value == DateRangeChoices.THIS_MONTH:
        return (today_start.replace(day=1), now)
    elif value == DateRangeChoices.THIS_YEAR:
        return (today_start.replace(day=1, month=1), now)
    elif value == DateRangeChoices.ALL_TIME:
        return (today_start.replace(year=2000), now)
Exemplo n.º 7
0
 def _set_paid(self):
     if self.payment_status != PaymentStatus.FULLY_PAID:  # pragma: no branch
         self.add_log_entry(_("Order was marked as paid."))
         self.payment_status = PaymentStatus.FULLY_PAID
         self.payment_date = local_now()
         self.save()
Exemplo n.º 8
0
 def since(self, days, tz=None):
     since_date = (local_now(tz) - datetime.timedelta(days=days)).date()
     since = to_aware(since_date, tz=tz)
     return self.in_date_range(since, None)
Exemplo n.º 9
0
 def _set_paid(self):
     if self.payment_status != PaymentStatus.FULLY_PAID:  # pragma: no branch
         self.add_log_entry(_('Order marked as paid.'))
         self.payment_status = PaymentStatus.FULLY_PAID
         self.payment_date = local_now()
         self.save()
Exemplo n.º 10
0
 def since(self, days, tz=None):
     since_date = (local_now(tz) - datetime.timedelta(days=days)).date()
     since = to_aware(since_date, tz=tz)
     return self.in_date_range(since, None)