Ejemplo n.º 1
0
def test_price_infos_are_discounted(rf):
    request = initialize_test(rf, True)

    price = request.shop.create_price

    product_one = create_product("Product_1", request.shop, default_price=150)
    product_two = create_product("Product_2", request.shop, default_price=250)

    spp = DiscountedProductPrice(product=product_one, shop=request.shop, price_value=100)
    spp.save()

    spp = DiscountedProductPrice(product=product_two, shop=request.shop, price_value=200)
    spp.save()

    product_ids = [product_one.pk, product_two.pk]

    dpm = get_pricing_module()
    pricing_context = dpm.get_context_from_request(request)
    price_infos = dpm.get_price_infos(pricing_context, product_ids)

    assert len(price_infos) == 2
    assert product_one.pk in price_infos
    assert product_two.pk in price_infos

    first_price_info = price_infos[product_one.pk]
    second_price_info = price_infos[product_two.pk]

    assert first_price_info.price == price(100)
    assert first_price_info.base_price == price(150)
    assert first_price_info.is_discounted

    assert second_price_info.price == price(200)
    assert second_price_info.base_price == price(250)
    assert second_price_info.is_discounted
Ejemplo n.º 2
0
def test_price_infos(rf):
    request, shop, group = initialize_test(rf, True)
    price = shop.create_price

    product_one = create_product("Product_1", shop, default_price=150)
    product_two = create_product("Product_2", shop, default_price=250)

    spp = SimpleProductPrice(product=product_one, shop=shop, group=group, price_value=100)
    spp.save()

    spp = SimpleProductPrice(product=product_two, shop=shop, group=group, price_value=200)
    spp.save()

    product_ids = [product_one.pk, product_two.pk]

    spm = get_pricing_module()
    assert isinstance(spm, SimplePricingModule)
    pricing_context = spm.get_context_from_request(request)
    price_infos = spm.get_price_infos(pricing_context, product_ids)

    assert len(price_infos) == 2
    assert product_one.pk in price_infos
    assert product_two.pk in price_infos

    assert price_infos[product_one.pk].price == price(100)
    assert price_infos[product_two.pk].price == price(200)

    assert price_infos[product_one.pk].base_price == price(100)
    assert price_infos[product_two.pk].base_price == price(200)
Ejemplo n.º 3
0
 def handle_product_data(self, request):
     product_id = request.GET["id"]
     shop_id = request.GET["shop_id"]
     customer_id = request.GET.get("customer_id")
     product = Product.objects.get(pk=product_id)
     shop = Shop.objects.get(pk=shop_id)
     ctx_request = RequestFactory().get("/")
     ctx_request.shop = shop
     ctx_request.customer = Contact.objects.filter(pk=customer_id).first()
     ctx_request.user = AnonymousUser()
     context = get_pricing_module().get_context_from_request(ctx_request)
     price_info = product.get_price_info(context, quantity=1)
     return {
         "id": product.id,
         "sku": product.sku,
         "name": product.name,
         "taxClass": {
             "id": product.tax_class.id,
             "name": force_text(product.tax_class),
         },
         "unitPrice": {
             "value": price_info.price.value,  # TODO: This is always zero?!
             "includesTax": price_info.price.includes_tax
         }
     }
Ejemplo n.º 4
0
def get_price_info(shop, customer, product, quantity):
    ctx_request = RequestFactory().get("/")
    ctx_request.shop = shop
    if customer:
        ctx_request.customer = customer
    ctx_request.user = AnonymousUser()
    context = get_pricing_module().get_context_from_request(ctx_request)
    return product.get_price_info(context, quantity=quantity)
Ejemplo n.º 5
0
 def get_price(self, context, quantity=1):
     """
     :type context: shoop.core.contexts.PriceTaxContext
     :rtype: shoop.core.pricing.Price
     """
     from shoop.core.pricing import get_pricing_module
     module = get_pricing_module()
     pricing_context = module.get_context(context)
     return module.get_price(pricing_context, product_id=self.pk, quantity=quantity)
Ejemplo n.º 6
0
    def get_price_info(self, context, quantity=1):
        """
        returns a `PriceInfo` object for product

        Returned `PriceInfo` object contains calculated `price` and `base_price`.
        The calculation of prices is handled in the current pricing module.

        :type context: shoop.core.contexts.PriceTaxContext
        :rtype: shoop.core.pricing.PriceInfo
        """
        from shoop.core.pricing import get_pricing_module
        module = get_pricing_module()
        pricing_context = module.get_context(context)
        return module.get_price_info(pricing_context, product=self, quantity=quantity)
Ejemplo n.º 7
0
def get_price_info(shop, customer, product, quantity):
    """
    Get price info of given product for given context parameters.

    :type shop: shoop.core.models.Shop
    :type customer: shoop.core.models.Contact
    :type product: shoop.core.models.Product
    :type quantity: numbers.Number
    """
    pricing_mod = get_pricing_module()
    pricing_ctx = pricing_mod.get_context_from_data(
        shop=shop,
        customer=(customer or AnonymousContact()),
    )
    return pricing_mod.get_price_info(pricing_ctx, product, quantity=quantity)
Ejemplo n.º 8
0
def test_pricing_module_is_active():
    """
    Make sure that our custom pricing module is active.
    """
    shop = Shop(currency='USD', prices_include_tax=False)
    customer = AnonymousContact()
    product = Product(sku='6.0745')

    pricing_mod = get_pricing_module()
    pricing_ctx = pricing_mod.get_context_from_data(shop, customer)

    pi = product.get_price_info(pricing_ctx, quantity=2)

    price = shop.create_price
    assert pi.price == price('12.149')
    assert pi.base_price == price('48.596')
    assert pi.quantity == 2
    assert pi.discounted_unit_price == price('6.0745')
    assert pi.base_unit_price == price('24.298')
    assert pi.discount_rate == Decimal('0.75')
Ejemplo n.º 9
0
def test_module_is_active():  # this test is because we want to make sure `SimplePricing` is active
    module = get_pricing_module()
    assert isinstance(module, DefaultPricingModule)
Ejemplo n.º 10
0
def test_module_is_active():
    """
    Check that DiscountPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, DiscountPricingModule)
Ejemplo n.º 11
0
def test_module_is_active():
    """
    Check that SimplePricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, SimplePricingModule)
def test_module_is_active():
    """
    Check that CustomerGroupPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, CustomerGroupPricingModule)
Ejemplo n.º 13
0
def _get_pricing_context(shop, customer=None):
    return get_pricing_module().get_context_from_data(
        shop=shop,
        customer=(customer or AnonymousContact()),
    )
Ejemplo n.º 14
0
 def from_request(cls, request):
     return cls(
         pricing_context=get_pricing_module().get_context_from_request(request),
         taxing_context=get_tax_module().get_context_from_request(request),
     )
Ejemplo n.º 15
0
def get_price_info(shop, customer, product, quantity):
    ctx_request = RequestFactory().get("/")
    ctx_request.shop = shop
    ctx_request.customer = (customer or AnonymousContact())
    context = get_pricing_module().get_context_from_request(ctx_request)
    return product.get_price_info(context, quantity=quantity)
Ejemplo n.º 16
0
    def get_base_price(self):
        from shoop.core.pricing import get_pricing_module

        module = get_pricing_module()
        return module.get_base_price(product_id=self.pk)