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
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
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
def recover_deleted_product(parent_product: Product, shop: Shop, deleted_product: Product, combination: Combination, combination_hash: str) -> Product: deleted_product.name = get_variation_product_name(parent_product, combination) deleted_product.tax_class = parent_product.tax_class deleted_product.sales_unit = parent_product.sales_unit deleted_product.shipping_mode = parent_product.shipping_mode deleted_product.type = parent_product.type deleted_product.manufacturer = parent_product.manufacturer deleted_product.height = parent_product.height deleted_product.depth = parent_product.depth deleted_product.net_weight = parent_product.net_weight deleted_product.gross_weight = parent_product.gross_weight deleted_product.deleted = False deleted_product.save() deleted_product.link_to_parent(parent_product, combination_hash=combination_hash) return deleted_product
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