コード例 #1
0
    def get_final_lines(self, with_taxes=False):
        """
        Get lines with processed lines added.

        This implementation includes the all lines returned by
        `get_lines` and in addition, lines from shipping and payment
        methods, but these lines can be extended, deleted or replaced by
        a subclass (by overriding `_compute_processed_lines` method) and
        with the `post_compute_source_lines` signal.

        .. note::

           By default, taxes for the returned lines are not calculated
           when `self.calculate_taxes_automatically` is false.  Pass in
           ``True`` to `with_taxes` argument or use `calculate_taxes`
           method to force tax calculation.
        """

        lines = self._processed_lines_cache
        if lines is None:
            lines = self.__compute_lines()
            self._processed_lines_cache = lines
        if not self._taxes_calculated:
            if with_taxes or should_calculate_taxes_automatically():
                self._calculate_taxes(lines)
        for error_message in self.get_validation_errors():
            raise ValidationError(error_message.args[0],
                                  code="invalid_order_source")
        return lines
コード例 #2
0
ファイル: _source.py プロジェクト: suutari/shoop
    def get_final_lines(self, with_taxes=False):
        """
        Get lines with processed lines added.

        This implementation includes the all lines returned by
        `get_lines` and in addition, lines from shipping and payment
        methods, but these lines can be extended, deleted or replaced by
        a subclass (by overriding `_compute_processed_lines` method) and
        with the `post_compute_source_lines` signal.

        .. note::

           By default, taxes for the returned lines are not calculated
           when `self.calculate_taxes_automatically` is false.  Pass in
           ``True`` to `with_taxes` argument or use `calculate_taxes`
           method to force tax calculation.
        """

        lines = self._processed_lines_cache
        if lines is None:
            lines = self.__compute_lines()
            self._processed_lines_cache = lines
        if not self._taxes_calculated:
            if with_taxes or should_calculate_taxes_automatically():
                self._calculate_taxes(lines)
        for error_message in self.get_validation_errors():
            if hasattr(self, "request"):
                messages.error(self.request, error_message.args[0], extra_tags='danger')
            else:
                raise ValidationError(error_message.args[0], code="invalid_order_source")
        return lines
コード例 #3
0
ファイル: _source.py プロジェクト: gurch101/shuup
    def get_final_lines(self, with_taxes=False):
        """
        Get lines with processed lines added.

        This implementation includes the all lines returned by
        `get_lines` and in addition, lines from shipping and payment
        methods, but these lines can be extended, deleted or replaced by
        a subclass (by overriding `_compute_processed_lines` method) and
        with the `post_compute_source_lines` signal. Lines returned is not
        validated.

        .. note::

           By default, taxes for the returned lines are not calculated
           when `self.calculate_taxes_automatically` is false.  Pass in
           ``True`` to `with_taxes` argument or use `calculate_taxes`
           method to force tax calculation.
        """

        lines = self._processed_lines_cache
        if lines is None:
            lines = self.__compute_lines()
            self._processed_lines_cache = lines
        if not self._taxes_calculated:
            if with_taxes or should_calculate_taxes_automatically():
                self._calculate_taxes(lines)
        return lines
コード例 #4
0
def _make_taxed(request, item, priceful, with_taxes):
    """
    :type request: django.http.HttpRequest
    :type item: shuup.core.taxing.TaxableItem
    :type priceful: shuup.core.pricing.Priceful
    :rtype: shuup.core.pricing.Priceful|None
    """
    try:
        tax_amount = getattr(priceful, 'tax_amount', None)
    except TypeError:  # e.g. shuup.core.order_creator.TaxesNotCalculated
        tax_amount = None

    if tax_amount is not None:
        if with_taxes:
            return TaxedPriceInfo(priceful.taxful_price,
                                  priceful.taxful_base_price,
                                  quantity=priceful.quantity,
                                  tax_amount=tax_amount)
        else:
            return TaxedPriceInfo(priceful.taxless_price,
                                  priceful.taxless_base_price,
                                  quantity=priceful.quantity,
                                  tax_amount=tax_amount)

    if not should_calculate_taxes_automatically():
        return None

    taxmod = get_tax_module()
    taxctx = taxmod.get_context_from_request(request)
    price = taxmod.get_taxed_price_for(taxctx, item, priceful.price)
    base_price = taxmod.get_taxed_price_for(taxctx, item, priceful.base_price)

    if with_taxes:
        return TaxedPriceInfo(price.taxful,
                              base_price.taxful,
                              quantity=priceful.quantity,
                              tax_amount=price.tax_amount)
    else:
        return TaxedPriceInfo(price.taxless,
                              base_price.taxless,
                              quantity=priceful.quantity,
                              tax_amount=price.tax_amount)
コード例 #5
0
ファイル: prices.py プロジェクト: NamiStudio/shuup
def _make_taxed(request, item, priceful, with_taxes):
    """
    :type request: django.http.HttpRequest
    :type item: shuup.core.taxing.TaxableItem
    :type priceful: shuup.core.pricing.Priceful
    :rtype: shuup.core.pricing.Priceful|None
    """
    try:
        tax_amount = getattr(priceful, 'tax_amount', None)
    except TypeError:  # e.g. shuup.core.order_creator.TaxesNotCalculated
        tax_amount = None

    if tax_amount is not None:
        if with_taxes:
            return TaxedPriceInfo(
                priceful.taxful_price, priceful.taxful_base_price,
                quantity=priceful.quantity, tax_amount=tax_amount)
        else:
            return TaxedPriceInfo(
                priceful.taxless_price, priceful.taxless_base_price,
                quantity=priceful.quantity, tax_amount=tax_amount)

    if not should_calculate_taxes_automatically():
        return None

    taxmod = get_tax_module()
    taxctx = taxmod.get_context_from_request(request)
    price = taxmod.get_taxed_price_for(taxctx, item, priceful.price)
    base_price = taxmod.get_taxed_price_for(taxctx, item, priceful.base_price)

    if with_taxes:
        return TaxedPriceInfo(
            price.taxful, base_price.taxful,
            quantity=priceful.quantity, tax_amount=price.tax_amount)
    else:
        return TaxedPriceInfo(
            price.taxless, base_price.taxless,
            quantity=priceful.quantity, tax_amount=price.tax_amount)
コード例 #6
0
 def calculate_taxes_or_raise(self):
     if not self._taxes_calculated:
         if not should_calculate_taxes_automatically():
             raise TaxesNotCalculated('Taxes are not calculated')
         self.calculate_taxes()
コード例 #7
0
ファイル: _source.py プロジェクト: suutari/shoop
 def calculate_taxes_or_raise(self):
     if not self._taxes_calculated:
         if not should_calculate_taxes_automatically():
             raise TaxesNotCalculated('Taxes are not calculated')
         self.calculate_taxes()