def test_supplier_with_stock_counts_2(rf, admin_user, settings): with override_settings(SHUUP_HOME_CURRENCY="USD", SHUUP_ENABLE_MULTIPLE_SHOPS=False): supplier = get_simple_supplier() shop = get_default_shop() assert shop.prices_include_tax assert shop.currency != settings.SHUUP_HOME_CURRENCY 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 = apply_request_middleware(rf.get("/"), 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 == 405 # 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) # test price properties sa = StockAdjustment.objects.first() assert sa.purchase_price.currency == shop.currency assert sa.purchase_price.includes_tax sc = StockCount.objects.first() assert sc.stock_value.currency == shop.currency assert sc.stock_value.includes_tax assert sc.stock_unit_price.currency == shop.currency assert sc.stock_unit_price.includes_tax with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True): sa = StockAdjustment.objects.first() # refetch to invalidate cache assert sa.purchase_price.currency != shop.currency assert sa.purchase_price.currency == settings.SHUUP_HOME_CURRENCY assert not sa.purchase_price.includes_tax sc = StockCount.objects.first() assert sc.stock_value.currency == settings.SHUUP_HOME_CURRENCY assert not sc.stock_value.includes_tax assert sc.stock_unit_price.currency == settings.SHUUP_HOME_CURRENCY assert not sc.stock_unit_price.includes_tax
def test_supplier_with_stock_counts(rf, admin_user, settings): supplier = get_simple_supplier() shop = get_default_shop() settings.SHUUP_HOME_CURRENCY = "USD" assert shop.prices_include_tax assert shop.currency != settings.SHUUP_HOME_CURRENCY 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) # test price properties sa = StockAdjustment.objects.first() assert sa.purchase_price.currency == shop.currency assert sa.purchase_price.includes_tax sc = StockCount.objects.first() assert sc.stock_value.currency == shop.currency assert sc.stock_value.includes_tax assert sc.stock_unit_price.currency == shop.currency assert sc.stock_unit_price.includes_tax settings.SHUUP_ENABLE_MULTIPLE_SHOPS = True sa = StockAdjustment.objects.first() # refetch to invalidate cache assert sa.purchase_price.currency != shop.currency assert sa.purchase_price.currency == settings.SHUUP_HOME_CURRENCY assert not sa.purchase_price.includes_tax sc = StockCount.objects.first() assert sc.stock_value.currency == settings.SHUUP_HOME_CURRENCY assert not sc.stock_value.includes_tax assert sc.stock_unit_price.currency == settings.SHUUP_HOME_CURRENCY assert not sc.stock_unit_price.includes_tax
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)
def test_product_catalog_indexing(rf, admin_user, settings): shop = get_default_shop() supplier = get_simple_supplier(shop=shop) supplier.stock_managed = True supplier.save() product = create_product("simple-test-product", shop, supplier) ProductCatalog.index_product(product) # no purchasable products catalog = ProductCatalog( ProductCatalogContext(shop=shop, purchasable_only=True)) assert catalog.get_products_queryset().count() == 0 # add 10 items to the stock stock_qty = 10 request = apply_request_middleware(rf.post("/", data={ "purchase_price": decimal.Decimal(32.00), "delta": stock_qty }), user=admin_user) response = process_stock_adjustment(request, supplier.id, product.id) assert response.status_code == 200 pss = supplier.get_stock_status(product.pk) assert pss.logical_count == stock_qty # now there are purchasable products assert catalog.get_products_queryset().count() == 1 assert product in catalog.get_products_queryset() # create a random order with 10 units of the product source = OrderSource(shop) source.status = get_initial_order_status() source.add_line( type=OrderLineType.PRODUCT, supplier=supplier, product=product, base_unit_price=source.create_price(1), quantity=10, ) OrderCreator().create_order(source) pss = supplier.get_stock_status(product.pk) assert pss.logical_count == 0 # stocks are gone assert catalog.get_products_queryset().count() == 0