Exemple #1
0
def create_product(sku, shop=None, supplier=None, default_price=None, **attrs):
    if default_price is not None:
        default_price = shop.create_price(default_price)
    if "fractional" in attrs:
        attrs.pop("fractional")
        get_sales_unit = get_fractional_sales_unit
    else:
        get_sales_unit = get_default_sales_unit

    product_attrs = dict(
        type=get_default_product_type(),
        tax_class=get_default_tax_class(),
        sku=sku,
        name=sku.title(),
        width=100,
        height=100,
        depth=100,
        net_weight=100,
        gross_weight=100,
        sales_unit=get_sales_unit(),
    )
    product_attrs.update(attrs)
    product = Product(**product_attrs)
    product.full_clean()
    product.save()
    if shop:
        sp = ShopProduct.objects.create(
            product=product, shop=shop, default_price=default_price, visibility=ShopProductVisibility.ALWAYS_VISIBLE
        )
        if supplier:
            sp.suppliers.add(supplier)
        sp.save()

    return product
Exemple #2
0
def create_product(sku, shop=None, supplier=None, default_price=None, **attrs):
    if default_price is not None:
        default_price = shop.create_price(default_price)

    product_attrs = dict(
        type=get_default_product_type(),
        tax_class=get_default_tax_class(),
        sku=sku,
        name=sku.title(),
        width=100,
        height=100,
        depth=100,
        net_weight=100,
        gross_weight=100,
        sales_unit=get_default_sales_unit(),
        stock_behavior=StockBehavior.UNSTOCKED
    )
    product_attrs.update(attrs)
    product = Product(**product_attrs)
    product.full_clean()
    product.save()
    if shop:
        sp = ShopProduct.objects.create(
            product=product, shop=shop, default_price=default_price,
            visibility=ShopProductVisibility.ALWAYS_VISIBLE
        )
        if supplier:
            sp.suppliers.add(supplier)
        sp.save()

    return product
Exemple #3
0
def create_product(sku, shop=None, supplier=None, default_price=None, **attrs):
    if default_price is not None:
        default_price = shop.create_price(default_price)

    product_attrs = dict(type=get_default_product_type(),
                         tax_class=get_default_tax_class(),
                         sku=sku,
                         name=sku.title(),
                         width=100,
                         height=100,
                         depth=100,
                         net_weight=100,
                         gross_weight=100,
                         sales_unit=get_default_sales_unit(),
                         stock_behavior=StockBehavior.UNSTOCKED)
    product_attrs.update(attrs)
    product = Product(**product_attrs)
    product.full_clean()
    product.save()
    if shop:
        sp = ShopProduct.objects.create(product=product,
                                        shop=shop,
                                        default_price=default_price)
        if supplier:
            sp.suppliers.add(supplier)
        sp.save()

    return product
Exemple #4
0
def create_variation_product(parent_product: Product, shop: Shop, sku: str,
                             combination: Combination,
                             combination_hash: str) -> Product:
    variation_child = Product(
        name=get_variation_product_name(parent_product, combination),
        tax_class=parent_product.tax_class,
        sales_unit=parent_product.sales_unit,
        sku=sku,
        shipping_mode=parent_product.shipping_mode,
        type=parent_product.type,
        manufacturer=parent_product.manufacturer,
        height=parent_product.height,
        depth=parent_product.depth,
        net_weight=parent_product.net_weight,
        gross_weight=parent_product.gross_weight,
    )
    variation_child.full_clean()
    variation_child.save()
    variation_child.link_to_parent(parent_product,
                                   combination_hash=combination_hash)
    return variation_child