def get_price_breakdown(self):
        """
        Return a breakdown of line prices after discounts have been applied.

        Returns a list of (unit_price_incl_tax, unit_price_excl_tax, quantity)
        tuples.
        """
        if not self.is_tax_known:
            raise RuntimeError("A price breakdown can only be determined "
                               "when taxes are known")
        prices = []
        if not self.discount_value:
            prices.append((self.unit_price_incl_tax, self.unit_price_excl_tax,
                           self.quantity))
        else:
            # Need to split the discount among the affected quantity
            # of products.
            item_incl_tax_discount = (
                self.discount_value / int(self.consumer.consumed()))
            item_excl_tax_discount = item_incl_tax_discount * self._tax_ratio
            item_excl_tax_discount = round_half_up(item_excl_tax_discount)
            prices.append((self.unit_price_incl_tax - item_incl_tax_discount,
                           self.unit_price_excl_tax - item_excl_tax_discount,
                           self.consumer.consumed()))
            if self.quantity_without_discount:
                prices.append((self.unit_price_incl_tax,
                               self.unit_price_excl_tax,
                               self.quantity_without_discount))
        return prices
    def line_price_incl_tax_incl_discounts(self):
        # We use whichever discount value is set.  If the discount value was
        # calculated against the tax-exclusive prices, then the line price
        # including tax
        if self.line_price_incl_tax is not None and self._discount_incl_tax:
            return max(0, self.line_price_incl_tax - self._discount_incl_tax)
        elif self.line_price_excl_tax is not None and self._discount_excl_tax:
            return max(0, round_half_up((self.line_price_excl_tax - self._discount_excl_tax) / self._tax_ratio))

        return self.line_price_incl_tax
Esempio n. 3
0
    def line_price_incl_tax_incl_discounts(self):
        # We use whichever discount value is set.  If the discount value was
        # calculated against the tax-exclusive prices, then the line price
        # including tax
        if self.line_price_incl_tax is not None and self._discount_incl_tax:
            return self.line_price_incl_tax - self._discount_incl_tax
        elif self.line_price_excl_tax is not None and self._discount_excl_tax:
            return round_half_up(
                (self.line_price_excl_tax - self._discount_excl_tax) /
                self._tax_ratio)

        return self.line_price_incl_tax
Esempio n. 4
0
 def line_price_excl_tax_incl_discounts(self):
     if self._discount_excl_tax and self.line_price_excl_tax is not None:
         return max(0, self.line_price_excl_tax - self._discount_excl_tax)
     if self._discount_incl_tax and self.line_price_incl_tax is not None:
         # This is a tricky situation.  We know the discount as calculated
         # against tax inclusive prices but we need to guess how much of the
         # discount applies to tax-exclusive prices.  We do this by
         # assuming a linear tax and scaling down the original discount.
         return max(
             0, self.line_price_excl_tax -
             round_half_up(self._tax_ratio * self._discount_incl_tax))
     return self.line_price_excl_tax
 def line_price_excl_tax_incl_discounts(self):
     if self._discount_excl_tax and self.line_price_excl_tax is not None:
         return max(0, self.line_price_excl_tax - self._discount_excl_tax)
     if self._discount_incl_tax and self.line_price_incl_tax is not None:
         # This is a tricky situation.  We know the discount as calculated
         # against tax inclusive prices but we need to guess how much of the
         # discount applies to tax-exclusive prices.  We do this by
         # assuming a linear tax and scaling down the original discount.
         return max(0, self.line_price_excl_tax - round_half_up(
             self._tax_ratio * self._discount_incl_tax
         ))
     return self.line_price_excl_tax
Esempio n. 6
0
 def line_price_incl_tax_incl_discounts(self):
     if self.line_price_incl_tax is not None:
         return max(
             0,
             round_half_up(self.line_price_incl_tax - self.discount_value))
     return None