Exemplo n.º 1
0
    def get_discount_effect(self, instance):
        if not (instance.discount_amount_value or instance.discounted_price_value or instance.discount_percentage):
            return "-"

        effects = []
        shop = get_shop(self.request)
        if instance.discount_amount_value:
            effects.append(
                "- %s" % format_money(shop.create_price(instance.discount_amount_value))
                if shop else format_number(instance.discount_amount_value))

        if instance.discounted_price_value:
            effects.append(
                format_money(shop.create_price(instance.discounted_price_value))
                if shop else format_number(instance.discounted_price_value))

        if instance.discount_percentage:
            effects.append(format_percent(instance.discount_percentage))

        return ','.join(effects)
Exemplo n.º 2
0
    def get_discount_effect(self, instance):
        if not (instance.discount_amount_value
                or instance.discounted_price_value
                or instance.discount_percentage):
            return "-"

        effects = []
        shop = get_shop(self.request)
        if instance.discount_amount_value:
            effects.append(
                "- %s" %
                format_money(shop.create_price(instance.discount_amount_value))
                if shop else format_number(instance.discount_amount_value))

        if instance.discounted_price_value:
            effects.append(
                format_money(shop.create_price(instance.discounted_price_value)
                             )
                if shop else format_number(instance.discounted_price_value))

        if instance.discount_percentage:
            effects.append(format_percent(instance.discount_percentage))

        return ','.join(effects)
Exemplo n.º 3
0
    def render_quantity_internal(self, quantity, force_symbol=False):
        """
        Render quantity in the internal unit.

        The value is rounded, localized and the internal unit symbol is
        added if needed.

        :type quantity: Decimal
        :param quantity: Quantity to render, in internal unit.
        :type force_symbol: bool
        :param force_symbol: Make sure that the symbol is rendered.
        :rtype: str
        :return: Rendered quantity in internal unit.
        """
        rounded = _round_to_digits(Decimal(quantity), self.internal_unit.decimals, ROUND_HALF_UP)
        value = format_number(rounded, self.internal_unit.decimals)
        if not force_symbol and self.allow_bare_number:
            return value
        symbol = self.internal_unit.symbol
        return _get_value_symbol_template().format(value=value, symbol=symbol)
Exemplo n.º 4
0
    def render_quantity(self, quantity, force_symbol=False):
        """
        Render (internal unit) quantity in the display unit.

        The value is converted from the internal unit to the display
        unit and then localized. The display unit symbol is added if
        needed.

        :type quantity: Decimal
        :param quantity: Quantity to render, in internal unit.
        :type force_symbol: bool
        :param force_symbol: Make sure that the symbol is rendered.
        :rtype: str
        :return: Rendered quantity in display unit.
        """
        display_quantity = self.to_display(quantity)
        value = format_number(display_quantity, self.display_unit.decimals)
        symbol = self.get_symbol(allow_empty=(not force_symbol))
        if not symbol:
            return value
        return _get_value_symbol_template().format(value=value, symbol=symbol)
Exemplo n.º 5
0
    def render_quantity_internal(self, quantity, force_symbol=False):
        """
        Render quantity (in internal unit) in the internal unit.

        The value is rounded, localized and the internal unit symbol is
        added if needed.

        :type quantity: Decimal
        :param quantity: Quantity to render, in internal unit
        :type force_symbol: bool
        :param force_symbol: Make sure that the symbol is rendered
        :rtype: str
        :return: Rendered quantity in internal unit.
        """
        rounded = _round_to_digits(
            Decimal(quantity), self.internal_unit.decimals, ROUND_HALF_UP)
        value = format_number(rounded, self.internal_unit.decimals)
        if not force_symbol and self.allow_bare_number:
            return value
        symbol = self.internal_unit.symbol
        return _get_value_symbol_template().format(value=value, symbol=symbol)
Exemplo n.º 6
0
    def render_quantity(self, quantity, force_symbol=False):
        """
        Render (internal unit) quantity in the display unit.

        The value is converted from the internal unit to the display
        unit and then localized.  The display unit symbol is added if
        needed.

        :type quantity: Decimal
        :param quantity: Quantity to render, in internal unit
        :type force_symbol: bool
        :param force_symbol: Make sure that the symbol is rendered
        :rtype: str
        :return: Rendered quantity in display unit.
        """
        display_quantity = self.to_display(quantity)
        value = format_number(display_quantity, self.display_unit.decimals)
        symbol = self.get_symbol(allow_empty=(not force_symbol))
        if not symbol:
            return value
        return _get_value_symbol_template().format(value=value, symbol=symbol)