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
def _make_taxed(request, item, priceful, with_taxes): """ :type request: django.http.HttpRequest :type item: shoop.core.taxing.TaxableItem :type priceful: shoop.core.pricing.Priceful :rtype: shoop.core.pricing.Priceful|None """ try: tax_amount = getattr(priceful, 'tax_amount', None) except TypeError: # e.g. shoop.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)
def _make_taxed(request, item, priceful, with_taxes): """ :type request: django.http.HttpRequest :type item: shoop.core.taxing.TaxableItem :type priceful: shoop.core.pricing.Priceful :rtype: shoop.core.pricing.Priceful|None """ try: tax_amount = getattr(priceful, "tax_amount", None) except TypeError: # e.g. shoop.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 )
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()