Ejemplo n.º 1
0
def get_stock_adjustment_div(request, supplier, product):
    """
    Get html string to adjust stock values

    Contains inputs for purchase_price_value and delta

    :param request: HTTP request
    :type request: django.http.HttpRequest
    :param supplier: shuup Supplier
    :type supplier: shuup.core.models.Supplier
    :param product: shuup Product
    :type product: shuup.core.models.Product
    :return: html div as a string
    :rtype: str
    """
    stock = StockCount.objects.get_or_create(product=product,
                                             supplier=supplier)[0]
    latest_adjustment = StockAdjustment.objects.filter(
        product=product, supplier=supplier,
        type=StockAdjustmentType.INVENTORY).last()
    purchase_price = latest_adjustment.purchase_price.as_rounded(
    ).value if latest_adjustment else Decimal()
    context = {
        "product":
        product,
        "supplier":
        supplier,
        "adjustment_form":
        StockAdjustmentForm(
            initial={
                "purchase_price": purchase_price,
                "delta": None,
            },
            sales_unit=product.sales_unit,
        ),
        "stock":
        stock,
        "stock_managed_form":
        StockManagedForm(initial={"stock_managed": not stock.stock_managed}),
    }
    if "shuup.notify" in settings.INSTALLED_APPS:
        initial_alert_limit = stock.alert_limit or Decimal()
        precision = Decimal(
            "0.1"
        )**product.sales_unit.decimals if product.sales_unit.decimals else Decimal(
            "1")
        context["alert_limit_form"] = AlertLimitForm(
            initial={"alert_limit": initial_alert_limit.quantize(precision)},
            sales_unit=product.sales_unit)
        if not get_missing_permissions(request.user, ("notify.script.list", )):
            context["notify_url"] = reverse("shuup_admin:notify.script.list")
        else:
            context["notify_url"] = ""
    return render_to_string("shuup/simple_supplier/admin/add_stock_form.jinja",
                            context=context,
                            request=request)
Ejemplo n.º 2
0
def get_stock_adjustment_div(request, supplier, product):
    """
    Get html string to adjust stock values

    Contains inputs for purchase_price_value and delta

    :param request: HTTP request
    :type request: django.http.HttpRequest
    :param supplier: shuup Supplier
    :type supplier: shuup.core.models.Supplier
    :param product: shuup Product
    :type product: shuup.core.models.Product
    :return: html div as a string
    :rtype: str
    """
    latest_adjustment = StockAdjustment.objects.filter(
        product=product, supplier=supplier,
        type=StockAdjustmentType.INVENTORY).last()
    purchase_price = (latest_adjustment.purchase_price_value
                      if latest_adjustment else Decimal("0.00"))
    context = {
        "product":
        product,
        "supplier":
        supplier,
        "delta_step":
        pow(0.1, product.sales_unit.decimals)
        if product.sales_unit.decimals else 0,
        "adjustment_form":
        StockAdjustmentForm(initial={
            "purchase_price": purchase_price,
            "delta": None
        }),
    }
    if "shuup.notify" in settings.INSTALLED_APPS:
        from shuup.notify.models import Notification
        context["alert_limit_form"] = AlertLimitForm(
            initial={"alert_limit": 0})
        if not get_missing_permissions(
                request.user, get_default_model_permissions(Notification)):
            context["notify_url"] = reverse("shuup_admin:notify.script.list")
        else:
            context["notify_url"] = ""
    return render_to_string("shuup/simple_supplier/admin/add_stock_form.jinja",
                            context=context,
                            request=request)