Exemplo n.º 1
0
def test_price_display_options_more():
    options = PriceDisplayOptions(show_prices=False)
    assert options.show_prices is False
    assert options.hide_prices is True
    assert options.include_taxes is None

    options = PriceDisplayOptions(include_taxes=True)
    assert options.show_prices is True
    assert options.include_taxes is True

    options = PriceDisplayOptions(include_taxes=False)
    assert options.show_prices is True
    assert options.include_taxes is False
Exemplo n.º 2
0
    def get_price_display_options(self):
        """
        Get price display options of the contact.

        If the default group (`get_default_group`) defines price display
        options and the contact is member of it, return it.

        If contact is not (anymore) member of the default group or the
        default group does not define options, return one of the groups
        which defines options.  If there is more than one such groups,
        it is undefined which options will be used.

        If contact is not a member of any group that defines price
        display options, return default constructed
        `PriceDisplayOptions`.

        Subclasses may still override this default behavior.

        :rtype: PriceDisplayOptions
        """
        groups_with_options = self.groups.with_price_display_options()
        if groups_with_options:
            default_group = self.get_default_group()
            if groups_with_options.filter(pk=default_group.pk).exists():
                group_with_options = default_group
            else:
                # Contact was removed from the default group.
                group_with_options = groups_with_options.first()
            return group_with_options.get_price_display_options()
        return PriceDisplayOptions()
Exemplo n.º 3
0
 def __call__(self, context, item, quantity=1):
     options = PriceDisplayOptions.from_context(context)
     if options.hide_prices:
         return ""
     request = context.get('request')
     orig_priceful = _get_priceful(request, item, quantity)
     if not orig_priceful:
         return ""
     priceful = convert_taxness(
         request, item, orig_priceful, options.include_taxes)
     price_value = getattr(priceful, self.property_name)
     return money(price_value)
Exemplo n.º 4
0
def render_price_property(request, item, priceful, property_name='price'):
    """
    Render price property of a Priceful object.

    :type request: django.http.HttpRequest
    :type item: shoop.core.taxing.TaxableItem
    :type priceful: shoop.core.pricing.Priceful
    :type propert_name: str
    :rtype: str
    """
    options = PriceDisplayOptions.from_context({'request': request})
    if options.hide_prices:
        return ""
    new_priceful = convert_taxness(
        request, item, priceful, options.include_taxes)
    price_value = getattr(new_priceful, property_name)
    return money(price_value)
Exemplo n.º 5
0
 def __call__(self, context, source):
     """
     :type source: shoop.core.order_creator.OrderSource|
                   shoop.core.models.Order
     """
     options = PriceDisplayOptions.from_context(context)
     if options.hide_prices:
         return ""
     try:
         if options.include_taxes is None:
             total = source.total_price
         elif options.include_taxes:
             total = source.taxful_total_price
         else:
             total = source.taxless_total_price
     except TypeError:
         total = source.total_price
     return money(total)
Exemplo n.º 6
0
    def __call__(self, context, product, quantity=1):
        """
        :type product: shoop.core.models.Product
        """
        options = PriceDisplayOptions.from_context(context)
        if options.hide_prices:
            return ("", "")
        request = context.get('request')
        priced_children = product.get_priced_children(request, quantity)
        priced_products = priced_children if priced_children else [
            (product, _get_priceful(request, product, quantity))]

        def get_formatted_price(priced_product):
            (prod, price_info) = priced_product
            if not price_info:
                return ""
            pf = convert_taxness(
                request, prod, price_info, options.include_taxes)
            return money(pf.price)

        min_max = (priced_products[0], priced_products[-1])
        return tuple(get_formatted_price(x) for x in min_max)
Exemplo n.º 7
0
def test_price_display_options_default():
    options = PriceDisplayOptions()
    assert options.show_prices is True
    assert options.hide_prices is False
    assert options.include_taxes is None
Exemplo n.º 8
0
 def get_price_display_options(self):
     return PriceDisplayOptions(
         include_taxes=self.show_prices_including_taxes,
         show_prices=(not self.hide_prices),
     )