• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_simple_supplier函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shuup_tests.simple_supplier.utils.get_simple_supplier函数的典型用法代码示例。如果您正苦于以下问题:Python get_simple_supplier函数的具体用法?Python get_simple_supplier怎么用?Python get_simple_supplier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_simple_supplier函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_refund_with_product_restock

def test_refund_with_product_restock():
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
        stock_behavior=StockBehavior.STOCKED
    )
    supplier.adjust_stock(product.id, 5)
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 5

    order = create_order_with_product(product, supplier, 2, 200, shop=shop)
    order.cache_prices()

    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 3

    # Create a refund with a parent line and quanity with `restock_products` set to False
    product_line = order.lines.first()
    order.create_refund([{"line": product_line, "quantity": 1, "restock_products": False}])

    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 3
    assert order.lines.last().taxful_price == -product_line.base_unit_price
    assert order.get_total_unrefunded_amount() == product_line.base_unit_price.amount

    # Create a refund with a parent line and quanity with `restock_products` set to True
    product_line = order.lines.first()
    order.create_refund([{"line": product_line, "quantity": 1, "restock_products": True}])

    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 4
    assert not order.taxful_total_price
开发者ID:millujye,项目名称:shuup,代码行数:31,代码来源:test_orders.py


示例2: test_supplier_with_stock_counts

def test_supplier_with_stock_counts(rf, stock_managed):
    supplier = get_simple_supplier(stock_managed=stock_managed)
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    quantity = random.randint(100, 600)

    if stock_managed:
        # Adjust
        supplier.adjust_stock(product.pk, quantity)
        # Check that count is adjusted
        assert supplier.get_stock_statuses([product.id])[product.id].logical_count == quantity
        # Since product is stocked with quantity we get no orderability error with quantity
        assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity, customer=None))
        # Since product is stocked with quantity we get orderability error with quantity + 1
        assert list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity+1, customer=None))
    else:
        # Check that count is not adjusted
        assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 0
        # No orderability errors since product is not stocked
        assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity, customer=None))
        # Turn it to stocked
        supplier.stock_managed = True
        supplier.save()
        supplier.adjust_stock(product.pk, quantity)
        # Check that count is adjusted
        assert supplier.get_stock_statuses([product.id])[product.id].logical_count == quantity
        # No orderability errors since product is stocked with quantity
        assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity, customer=None))
        # Since product is stocked with quantity we get orderability errors with quantity + 1
        assert list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity+1, customer=None))
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:test_simple_supplier.py


示例3: test_get_listed_products_orderable_only

def test_get_listed_products_orderable_only():
    context = get_jinja_context()
    shop = get_default_shop()
    simple_supplier = get_simple_supplier()
    n_products = 2

    # Create product without stock
    product = create_product(
        "test-sku",
        supplier=simple_supplier,
        shop=shop,
        stock_behavior=StockBehavior.STOCKED
    )
    assert len(general.get_listed_products(context, n_products, orderable_only=True)) == 0
    assert len(general.get_listed_products(context, n_products, orderable_only=False)) == 1

    # Increase stock on product
    quantity = product.get_shop_instance(shop).minimum_purchase_quantity
    simple_supplier.adjust_stock(product.id, quantity)
    assert len(general.get_listed_products(context, n_products, orderable_only=True)) == 1
    assert len(general.get_listed_products(context, n_products, orderable_only=False)) == 1

    # Decrease stock on product
    simple_supplier.adjust_stock(product.id, -quantity)
    assert len(general.get_listed_products(context, n_products, orderable_only=True)) == 0
    assert len(general.get_listed_products(context, n_products, orderable_only=False)) == 1
开发者ID:suutari,项目名称:shoop,代码行数:26,代码来源:test_general_template_helpers.py


示例4: test_simple_supplier

def test_simple_supplier(rf):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop)
    ss = supplier.get_stock_status(product.pk)
    assert ss.product == product
    assert ss.logical_count == 0
    num = random.randint(100, 500)
    supplier.adjust_stock(product.pk, +num)
    assert supplier.get_stock_status(product.pk).logical_count == num
    # Create order ...
    order = create_order_with_product(product, supplier, 10, 3, shop=shop)
    quantities = order.get_product_ids_and_quantities()
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == (num - quantities[product.pk])
    assert pss.physical_count == num
    # Create shipment ...
    shipment = order.create_shipment_of_all_products(supplier)
    pss = supplier.get_stock_status(product.pk)
    assert pss.physical_count == (num - quantities[product.pk])
    # Cancel order...
    order.set_canceled()
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == (num)
    # physical stock still the same until shipment exists
    assert pss.physical_count == (num - quantities[product.pk])

    shipment.soft_delete()
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == num
    assert pss.physical_count == num
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:test_simple_supplier.py


示例5: test_process_stock_managed

def test_process_stock_managed(rf, admin_user):
    supplier = get_simple_supplier(stock_managed=False)
    shop = get_default_shop()
    product = create_product("simple-test-product", shop)
    request = apply_request_middleware(rf.get("/", data={"stock_managed": True}), user=admin_user)

    with pytest.raises(Exception) as ex:
        # Should raise exception becasue only POST is allowed
        response = process_stock_managed(request, supplier.id, product.id)

    request = apply_request_middleware(rf.post("/", data={"stock_managed": True}), user=admin_user)
    response = process_stock_managed(request, supplier.id, product.id)
    assert response.status_code == 200

    # Check no stock count
    sc = StockCount.objects.filter(supplier=supplier, product=product).first()
    assert sc.logical_count == 0
    # Check stock count managed by default
    assert sc.stock_managed == True
    # Now test with stock managed turned off
    request = apply_request_middleware(rf.post("/", data={"stock_managed": False}), user=admin_user)
    response = process_stock_managed(request, supplier.id, product.id)
    assert response.status_code == 200
    # Check stock management is disabled for product
    sc = StockCount.objects.filter(
        supplier=supplier, product=product).first()
    assert sc.stock_managed == False
    # Now test with stock managed turned on
    request = apply_request_middleware(rf.post("/", data={"stock_managed": True}), user=admin_user)
    response = process_stock_managed(request, supplier.id, product.id)
    assert response.status_code == 200
    # Check stock management is enabled for product
    sc = StockCount.objects.filter(
        supplier=supplier, product=product).first()
    assert sc.stock_managed == True
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_simple_supplier.py


示例6: test_refund_entire_order

def test_refund_entire_order():
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
    )
    supplier.adjust_stock(product.id, 5)
    check_stock_counts(supplier, product, 5, 5)

    order = create_order_with_product(product, supplier, 2, 200, Decimal("0.24"), shop=shop)
    order.cache_prices()

    original_total_price = order.taxful_total_price
    check_stock_counts(supplier, product, 5, 3)

    # Create a full refund with `restock_products` set to False
    order.create_full_refund(restock_products=False)

    # Confirm the refund was created with correct amount
    assert order.taxless_total_price.amount.value == 0
    assert order.taxful_total_price.amount.value == 0
    refund_line = order.lines.order_by("ordering").last()
    assert refund_line.type == OrderLineType.REFUND
    assert refund_line.taxful_price == -original_total_price

    # Make sure logical count reflects refunded products
    check_stock_counts(supplier, product, 5, 3)
开发者ID:ruqaiya,项目名称:shuup,代码行数:29,代码来源:test_orders.py


示例7: test_refund_entire_order

def test_refund_entire_order():
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
        stock_behavior=StockBehavior.STOCKED
    )
    supplier.adjust_stock(product.id, 5)
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 5

    order = create_order_with_product(product, supplier, 2, 200, Decimal("0.1"), shop=shop)
    order.cache_prices()
    original_total_price = order.taxful_total_price
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 3

    # Create a full refund with `restock_products` set to False
    order.create_full_refund(restock_products=False)

    # Confirm the refund was created with correct amount
    assert order.taxless_total_price.amount.value == 0
    assert order.taxful_total_price.amount.value == 0
    refund_line = order.lines.order_by("ordering").last()
    assert refund_line.type == OrderLineType.REFUND
    assert refund_line.taxful_price == -original_total_price

    # Make sure stock status didn't change
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == 3
开发者ID:millujye,项目名称:shuup,代码行数:29,代码来源:test_orders.py


示例8: test_refund_entire_order_with_restock

def test_refund_entire_order_with_restock(admin_user):
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
    )
    supplier.adjust_stock(product.id, 5)
    _check_stock_counts(supplier, product, 5, 5)

    order = create_order_with_product(product, supplier, 2, 200, shop=shop)
    order.payment_status = PaymentStatus.DEFERRED
    order.cache_prices()
    order.save()

    _check_stock_counts(supplier, product, 5, 3)
    assert not StockAdjustment.objects.filter(created_by=admin_user).exists()

    client = _get_client(admin_user)
    refund_url = "/api/shuup/order/%s/create_full_refund/" % order.id
    data = {"restock_products": True}
    response = client.post(refund_url, data, format="json")
    assert response.status_code == status.HTTP_201_CREATED
    order.refresh_from_db()

    # restock logical count
    _check_stock_counts(supplier, product, 5, 5)
    assert StockAdjustment.objects.filter(created_by=admin_user).exists()
开发者ID:ruqaiya,项目名称:shuup,代码行数:29,代码来源:test_refunds.py


示例9: test_admin_form

def test_admin_form(rf, admin_user):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    request = rf.get("/")
    request.user = admin_user
    frm = SimpleSupplierForm(product=product, request=request)
    # Form contains 1 product even if the product is not stocked
    assert len(frm.products) == 1
    assert not frm.products[0].is_stocked()

    product.stock_behavior = StockBehavior.STOCKED  # Make product stocked
    product.save()

    # Now since product is stocked it should be in the form
    frm = SimpleSupplierForm(product=product, request=request)
    assert len(frm.products) == 1

    # Add stocked children for product
    child_product = create_product("child-test-product", shop, supplier)
    child_product.stock_behavior = StockBehavior.STOCKED
    child_product.save()
    child_product.link_to_parent(product)

    # Admin form should now contain only child products for product
    frm = SimpleSupplierForm(product=product, request=request)
    assert len(frm.products) == 1
    assert frm.products[0] == child_product
开发者ID:suutari,项目名称:shoop,代码行数:28,代码来源:test_simple_supplier.py


示例10: test_order_source

def test_order_source(rf, admin_user):
    """
    Test order source validation with stocked products.
    """
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product("simple-test-product", shop, supplier)
    product.stock_behavior = StockBehavior.STOCKED
    product.save()
    quantity = 345
    supplier.adjust_stock(product.pk, quantity)
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == quantity
    assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity, customer=None))
    assert list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity+1, customer=None))

    source = seed_source(admin_user, shop)
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product,
        supplier=supplier,
        quantity=quantity,
        base_unit_price=source.create_price(10),
    )
    assert not list(source.get_validation_errors())

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product,
        supplier=supplier,
        quantity=quantity,
        base_unit_price=source.create_price(10),
    )
    assert list(source.get_validation_errors())
开发者ID:gurch101,项目名称:shuup,代码行数:33,代码来源:test_order_source.py


示例11: test_refund_without_shipment

def test_refund_without_shipment(restock):
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
    )
    # Start out with a supplier with quantity of 10 of a product
    supplier.adjust_stock(product.id, 10)
    check_stock_counts(supplier, product, physical=10, logical=10)

    order = create_order_with_product(product, supplier, 2, 200, shop=shop)
    order.cache_prices()
    check_stock_counts(supplier, product, physical=10, logical=8)

    # Restock value shouldn't matter if we don't have any shipments
    product_line = order.lines.first()
    order.create_refund([
        {"line": product_line, "quantity": 2, "amount": Money(400, order.currency), "restock_products": restock}])

    if restock:
        check_stock_counts(supplier, product, physical=10, logical=10)
    else:
        check_stock_counts(supplier, product, physical=10, logical=8)
    assert product_line.refunded_quantity == 2
    assert order.get_total_tax_amount() == Money(
        order.taxful_total_price_value - order.taxless_total_price_value,
        order.currency)
开发者ID:ruqaiya,项目名称:shuup,代码行数:29,代码来源:test_orders.py


示例12: test_create_refund_amount

def test_create_refund_amount(prices_include_tax):
    supplier = get_simple_supplier()
    order = _get_order(prices_include_tax, True, True)

    original_order_total = order.taxful_total_price
    num_order_lines = order.lines.count()

    # refund the discount lines first
    for line in order.lines.discounts():
        order.create_refund([
            {"line": "amount", "quantity": line.quantity, "amount": line.taxful_price.amount}])

    # refund each line 1 by 1
    for line in order.lines.products():
        order.create_refund([
            {"line": "amount", "quantity": 1, "amount": line.taxful_price.amount, "restock_products": True}])

    assert order.has_refunds()
    #assert not order.can_create_refund()
    assert not order.taxful_total_price_value
    assert not order.taxless_total_price_value
    assert order.lines.refunds().count() == num_order_lines
    # we haven't refunded any quantity so the shipping status remains as-is
    assert order.shipping_status == ShippingStatus.NOT_SHIPPED
    assert order.payment_status == PaymentStatus.FULLY_PAID
    assert order.get_total_refunded_amount() == original_order_total.amount
    assert not order.get_total_unrefunded_amount().value

    for line in order.lines.products():
        order.create_refund([
            {"line": line, "quantity": line.quantity, "amount": Money(0, "EUR"), "restock_products": True}])

    assert order.shipping_status == ShippingStatus.FULLY_SHIPPED
开发者ID:ruqaiya,项目名称:shuup,代码行数:33,代码来源:test_refunds.py


示例13: test_quantity_has_to_be_in_stock

def test_quantity_has_to_be_in_stock(admin_user, settings):
    configure(settings)
    from shuup_tests.simple_supplier.utils import get_simple_supplier
    from shuup.core.models import StockBehavior
    shop = factories.get_default_shop()
    basket = factories.get_basket()

    supplier = get_simple_supplier()
    product = factories.create_product("simple-test-product", shop, supplier)
    quantity = 256
    supplier.adjust_stock(product.pk, quantity)
    product.stock_behavior = StockBehavior.STOCKED
    product.save()
    shop_product = product.shop_products.first()
    shop_product.suppliers.add(supplier)
    shop_product.save()

    client = _get_client(admin_user)
    payload = {
        'shop': shop.id,
        'product': shop_product.id,
        'quantity': 493020
    }
    response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_400_BAD_REQUEST
    assert '"Insufficient stock"' in str(response.content)
开发者ID:suutari-ai,项目名称:shuup,代码行数:26,代码来源:test_basket_api.py


示例14: test_create_refund_line_by_line

def test_create_refund_line_by_line(prices_include_tax):
    supplier = get_simple_supplier()
    order = _get_order(prices_include_tax, True, True)

    for line in order.lines.products():
        check_stock_counts(supplier, line.product, INITIAL_PRODUCT_QUANTITY, INITIAL_PRODUCT_QUANTITY - line.quantity)

    original_order_total = order.taxful_total_price
    num_order_lines = order.lines.count()

    # refund the discount lines first
    for line in order.lines.discounts():
        order.create_refund([
            {"line": line, "quantity": line.quantity, "amount": line.taxful_price.amount}])

    # refund each line 1 by 1
    for line in order.lines.products():
        order.create_refund([
            {"line": line, "quantity": line.quantity, "amount": line.taxful_price.amount, "restock_products": True}])

    for line in order.lines.products():
        check_stock_counts(supplier, line.product, INITIAL_PRODUCT_QUANTITY, INITIAL_PRODUCT_QUANTITY)

    assert order.has_refunds()
    assert not order.can_create_refund()
    assert not order.taxful_total_price_value
    assert not order.taxless_total_price_value
    assert order.lines.refunds().count() == num_order_lines
    assert order.shipping_status == ShippingStatus.FULLY_SHIPPED
    assert order.get_total_refunded_amount() == original_order_total.amount
    assert not order.get_total_unrefunded_amount().value
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:test_refunds.py


示例15: test_simple_supplier

def test_simple_supplier(rf):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop)
    ss = supplier.get_stock_status(product.pk)
    assert ss.product == product
    assert ss.logical_count == 0
    num = random.randint(100, 500)
    supplier.adjust_stock(product.pk, +num)
    assert supplier.get_stock_status(product.pk).logical_count == num

    # Create order
    order = create_order_with_product(product, supplier, 10, 3, shop=shop)
    quantities = order.get_product_ids_and_quantities()
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == (num - quantities[product.pk])
    assert pss.physical_count == num
    # Create shipment

    shipment = order.create_shipment_of_all_products(supplier)
    assert isinstance(shipment, Shipment)
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == (num - quantities[product.pk])
    assert pss.physical_count == (num - quantities[product.pk])

    # Delete shipment
    with pytest.raises(NotImplementedError):
        shipment.delete()
    shipment.soft_delete()
    assert shipment.is_deleted()
    pss = supplier.get_stock_status(product.pk)
    assert pss.logical_count == (num - quantities[product.pk])
    assert pss.physical_count == (num)
开发者ID:gurch101,项目名称:shuup,代码行数:33,代码来源:test_shipment_delete_with_simple_supplier.py


示例16: test_shipment_with_insufficient_stock

def test_shipment_with_insufficient_stock():
    if "shuup.simple_supplier" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.simple_supplier in INSTALLED_APPS")

    from shuup_tests.simple_supplier.utils import get_simple_supplier

    shop = get_default_shop()
    supplier = get_simple_supplier()
    order = _get_order(shop, supplier, stocked=True)
    product_line = order.lines.products().first()
    product = product_line.product
    assert product_line.quantity == 15

    supplier.adjust_stock(product.pk, delta=10)
    stock_status = supplier.get_stock_status(product.pk)
    assert stock_status.physical_count == 10

    order.create_shipment({product: 5}, supplier=supplier)
    assert order.shipping_status == ShippingStatus.PARTIALLY_SHIPPED
    assert order.shipments.all().count() == 1

    with pytest.raises(Problem):
        order.create_shipment({product: 10}, supplier=supplier)

    # Should be fine after adding more stock
    supplier.adjust_stock(product.pk, delta=5)
    order.create_shipment({product: 10}, supplier=supplier)
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:27,代码来源:test_shipments.py


示例17: test_refund_entire_order_without_restock

def test_refund_entire_order_without_restock(admin_user):
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product = create_product(
        "test-sku",
        shop=get_default_shop(),
        default_price=10,
    )
    supplier.adjust_stock(product.id, 5)
    _check_stock_counts(supplier, product, 5, 5)

    order = create_order_with_product(product, supplier, 2, 200, Decimal("0.24"), shop=shop)
    order.payment_status = PaymentStatus.DEFERRED
    order.cache_prices()
    order.save()

    original_total_price = order.taxful_total_price
    _check_stock_counts(supplier, product, 5, 3)

    client = _get_client(admin_user)
    refund_url = "/api/shuup/order/%s/create_full_refund/" % order.id
    data = {"restock_products": False}
    response = client.post(refund_url, data, format="json")
    assert response.status_code == status.HTTP_201_CREATED
    order.refresh_from_db()

    # Confirm the refund was created with correct amount
    assert order.taxless_total_price.amount.value == 0
    assert order.taxful_total_price.amount.value == 0
    refund_line = order.lines.order_by("ordering").last()
    assert refund_line.type == OrderLineType.REFUND
    assert refund_line.taxful_price == -original_total_price

    # Make sure logical count reflects refunded products
    _check_stock_counts(supplier, product, 5, 3)
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_refunds.py


示例18: test_order_creator_with_package_product

def test_order_creator_with_package_product(rf, admin_user):
    if "shuup.simple_supplier" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.simple_supplier in INSTALLED_APPS")
    from shuup_tests.simple_supplier.utils import get_simple_supplier

    shop = get_default_shop()
    supplier = get_simple_supplier()
    package_product = create_package_product("Package-Product-Test", shop=shop, supplier=supplier,
                                             children=2)
    shop_product =  package_product.get_shop_instance(shop)
    quantity_map = package_product.get_package_child_to_quantity_map()
    product_1, product_2 = quantity_map.keys()
    product_1.stock_behavior = StockBehavior.STOCKED
    product_1.save()
    product_2.stock_behavior = StockBehavior.STOCKED
    product_2.save()

    assert quantity_map[product_1] == 1
    assert quantity_map[product_2] == 2

    supplier.adjust_stock(product_1.pk, 1)
    supplier.adjust_stock(product_2.pk, 2)

    assert supplier.get_stock_status(product_1.pk).logical_count == 1
    assert supplier.get_stock_status(product_2.pk).logical_count == 2

    creator = OrderCreator()

    # There should be no exception when creating order with only package product
    source = seed_source(admin_user)
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=package_product,
        supplier=supplier,
        quantity=1,
        base_unit_price=source.create_price(10),
    )
    order = creator.create_order(source)

    # However, there should not be enough stock for both package and child products
    source = seed_source(admin_user)
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=package_product,
        supplier=supplier,
        quantity=1,
        base_unit_price=source.create_price(10),
    )
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product_1,
        supplier=supplier,
        quantity=1,
        base_unit_price=source.create_price(10),
    )

    # And a validation error should be raised
    with pytest.raises(ValidationError):
        order = creator.create_order(source)
开发者ID:suutari,项目名称:shoop,代码行数:59,代码来源:test_order_creator.py


示例19: test_sample_import_no_match

def test_sample_import_no_match(stock_managed):
    filename = "sample_import_nomatch.xlsx"
    if "shuup.simple_supplier" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.simple_supplier in INSTALLED_APPS")
    from shuup_tests.simple_supplier.utils import get_simple_supplier

    activate("en")
    shop = get_default_shop()
    tax_class = get_default_tax_class()
    product_type = get_default_product_type()
    supplier = get_simple_supplier(stock_managed)
    sales_unit = get_default_sales_unit()

    Manufacturer.objects.create(name="manufctr")
    path = os.path.join(os.path.dirname(__file__), "data", "product", filename)
    transformed_data = transform_file(filename.split(".")[1], path)

    importer = ProductImporter(transformed_data, shop, "en")
    importer.process_data()
    assert len(importer.unmatched_fields) == 1
    assert "gtiin" in importer.unmatched_fields
    importer.manually_match("gtiin", "shuup.core.models.Product:gtin")
    importer.do_remap()
    assert len(importer.unmatched_fields) == 0
    importer.do_import(ImportMode.CREATE_UPDATE)
    products = importer.new_objects
    assert len(products) == 2

    for product in products:
        assert product.gtin == "1280x720"
        shop_product = product.get_shop_instance(shop)
        assert shop_product.pk
        assert shop_product.default_price_value == 150
        assert shop_product.default_price == shop.create_price(150)
        assert product.type == product_type  # product type comes from importer defaults
        assert product.sales_unit == sales_unit
        if product.pk == 1:
            assert product.tax_class.pk == 2  # new was created
            assert product.name == "Product English"
            assert product.description == "Description English"
        else:
            assert product.tax_class.pk == tax_class.pk  # old was found as should
            assert product.name == "Product 2 English"
            assert product.description == "Description English 2"
        assert shop_product.primary_category.pk == 1
        assert [c.pk for c in shop_product.categories.all()] == [1,2]

    # stock was not managed since supplier doesn't like that
    for msg in importer.other_log_messages:
        assert "please set Stock Managed on" in msg

    supplier.stock_managed = True
    supplier.save()
    importer.do_import("create,update")

    assert len(importer.other_log_messages) == 0
    for sa in StockAdjustment.objects.all():
        assert sa.product.pk
        assert sa.delta == 20
开发者ID:ruqaiya,项目名称:shuup,代码行数:59,代码来源:test_product_import.py


示例20: test_basket_package_product_orderability_change

def test_basket_package_product_orderability_change(rf):
    if "shuup.simple_supplier" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.simple_supplier in INSTALLED_APPS")
    from shuup_tests.simple_supplier.utils import get_simple_supplier

    StoredBasket.objects.all().delete()
    shop = get_default_shop()
    supplier = get_simple_supplier()
    product, child = get_unstocked_package_product_and_stocked_child(shop, supplier, child_logical_quantity=2)
    request = rf.get("/")
    request.session = {}
    request.shop = shop
    apply_request_middleware(request)
    basket = get_basket(request)

    # Add the package parent
    basket.add_product(
        supplier=supplier,
        shop=shop,
        product=product,
        quantity=1,
        force_new_line=True,
        extra={"foo": "foo"}
    )

    # Also add the child product separately
    basket.add_product(
        supplier=supplier,
        shop=shop,
        product=child,
        quantity=1,
        force_new_line=True,
        extra={"foo": "foo"}
    )

    # Should be stock for both
    assert len(basket.get_lines()) == 2
    assert len(basket.get_unorderable_lines()) == 0

    supplier.adjust_stock(child.id, -1)

    # Orderability is already cached, we need to uncache to force recheck
    basket.uncache()

    # After reducing stock to 1, should only be stock for one
    assert len(basket.get_lines()) == 1
    assert len(basket.get_unorderable_lines()) == 1

    supplier.adjust_stock(child.id, -1)

    basket.uncache()

    # After reducing stock to 0, should be stock for neither
    assert len(basket.get_lines()) == 0
    assert len(basket.get_unorderable_lines()) == 2
开发者ID:ruqaiya,项目名称:shuup,代码行数:55,代码来源:test_basket.py



注:本文中的shuup_tests.simple_supplier.utils.get_simple_supplier函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.assert_contains函数代码示例发布时间:2022-05-27
下一篇:
Python fixtures.get_jinja_context函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap