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
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())
Exemple #3
0
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
def test_get_visible_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_visible_products(context, n_products, orderable_only=True)) == 0
    assert len(general.get_visible_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_visible_products(context, n_products, orderable_only=True)) == 1
    assert len(general.get_visible_products(context, n_products, orderable_only=False)) == 1

    # Decrease stock on product
    simple_supplier.adjust_stock(product.id, -quantity)
    assert len(general.get_visible_products(context, n_products, orderable_only=True)) == 0
    assert len(general.get_visible_products(context, n_products, orderable_only=False)) == 1
def test_supplier_with_stock_counts(rf):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    quantity = random.randint(100, 600)
    supplier.adjust_stock(product.pk, quantity)
    assert supplier.get_stock_statuses([product.id])[product.id].logical_count == quantity
    # No orderability errors since product is not stocked
    assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity + 1, customer=None))

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

    assert not list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity, customer=None))
    # Now since product is stocked we get orderability error with quantity + 1
    assert list(supplier.get_orderability_errors(product.get_shop_instance(shop), quantity + 1, customer=None))
def test_supplier_with_stock_counts(rf, admin_user):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    quantity = random.randint(100, 600)
    supplier.adjust_stock(product.pk, quantity)
    adjust_quantity = random.randint(100, 600)
    request = rf.get("/")
    request.user = admin_user
    request.POST = {"purchase_price": decimal.Decimal(32.00), "delta": adjust_quantity}
    response = process_stock_adjustment(request, supplier.id, product.id)
    assert response.status_code == 400  # Only POST is allowed
    request.method = "POST"
    response = process_stock_adjustment(request, supplier.id, product.id)
    assert response.status_code == 200
    pss = supplier.get_stock_status(product.pk)
    # Product stock values should be adjusted
    assert pss.logical_count == (quantity + adjust_quantity)
Exemple #7
0
def test_supplier_with_stock_counts(rf, admin_user):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    quantity = random.randint(100, 600)
    supplier.adjust_stock(product.pk, quantity)
    adjust_quantity = random.randint(100, 600)
    request = rf.get("/")
    request.user = admin_user
    request.POST = {
        "purchase_price": decimal.Decimal(32.00),
        "delta": adjust_quantity
    }
    response = process_stock_adjustment(request, supplier.id, product.id)
    assert response.status_code == 400  # Only POST is allowed
    request.method = "POST"
    response = process_stock_adjustment(request, supplier.id, product.id)
    assert response.status_code == 200
    pss = supplier.get_stock_status(product.pk)
    # Product stock values should be adjusted
    assert pss.logical_count == (quantity + adjust_quantity)
Exemple #8
0
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())
Exemple #9
0
def test_new_product_admin_form_renders(rf, client, admin_user):
    """
    Make sure that no exceptions are raised when creating a new product
    with simple supplier enabled
    """
    request = rf.get("/")
    request.user = admin_user
    request.session = client.session
    view = ProductEditView.as_view()
    shop = get_default_shop()
    supplier = get_simple_supplier()
    supplier.stock_managed = True
    supplier.save()

    # This should not raise an exception
    view(request).render()

    supplier.stock_managed = False
    supplier.save()

    # Nor should this
    view(request).render()
def test_new_product_admin_form_renders(rf, client, admin_user):
    """
    Make sure that no exceptions are raised when creating a new product
    with simple supplier enabled
    """
    request = rf.get("/")
    request.user = admin_user
    request.session = client.session
    view = ProductEditView.as_view()
    shop = get_default_shop()
    supplier = get_simple_supplier()
    supplier.stock_managed = True
    supplier.save()

    # This should not raise an exception
    view(request).render()

    supplier.stock_managed = False
    supplier.save()

    # Nor should this
    view(request).render()
def test_get_visible_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_visible_products(context, n_products,
                                     orderable_only=True)) == 0
    assert len(
        general.get_visible_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_visible_products(context, n_products,
                                     orderable_only=True)) == 1
    assert len(
        general.get_visible_products(context, n_products,
                                     orderable_only=False)) == 1

    # Decrease stock on product
    simple_supplier.adjust_stock(product.id, -quantity)
    assert len(
        general.get_visible_products(context, n_products,
                                     orderable_only=True)) == 0
    assert len(
        general.get_visible_products(context, n_products,
                                     orderable_only=False)) == 1
Exemple #12
0
def test_supplier_with_stock_counts(rf):
    supplier = get_simple_supplier()
    shop = get_default_shop()
    product = create_product("simple-test-product", shop, supplier)
    quantity = random.randint(100, 600)
    supplier.adjust_stock(product.pk, quantity)
    assert supplier.get_stock_statuses(
        [product.id])[product.id].logical_count == quantity
    # No orderability errors since product is not stocked
    assert not list(
        supplier.get_orderability_errors(
            product.get_shop_instance(shop), quantity + 1, customer=None))

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

    assert not list(
        supplier.get_orderability_errors(
            product.get_shop_instance(shop), quantity, customer=None))
    # Now since product is stocked we get orderability error with quantity + 1
    assert list(
        supplier.get_orderability_errors(product.get_shop_instance(shop),
                                         quantity + 1,
                                         customer=None))
Exemple #13
0
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 ...
    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)
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 ...
    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)