def stacked_value_added_taxes(price, taxes):
 def money_sum(iterable):
  return sum(iterable, Money(0, price.currency))
 if (not taxes):
  return TaxedPrice(TaxfulPrice(price), TaxlessPrice(price), [])
 if price.includes_tax:
  taxful = price
  rate_sum = sum((tax.rate for tax in taxes if tax.rate))
  amount_sum = money_sum((tax.amount for tax in taxes if tax.amount))
  taxless = TaxlessPrice(((taxful.amount - amount_sum) / (1 + rate_sum)))
 else:
  taxful = None
  taxless = price
 line_taxes = [SourceLineTax.from_tax(tax=tax, base_amount=taxless.amount) for tax in taxes]
 if (taxful is None):
  total_tax_amount = money_sum((x.amount for x in line_taxes))
  taxful = TaxfulPrice((taxless.amount + total_tax_amount))
 return TaxedPrice(taxful, taxless, line_taxes)

def stacked_value_added_taxes ( price , taxes ) : def money_sum ( iterable ) : return sum ( iterable , Money ( 0 , price . currency ) ) if ( not taxes ) : return TaxedPrice ( TaxfulPrice ( price ) , TaxlessPrice ( price ) , [ ] ) if price . includes_tax : taxful = price rate_sum = sum ( ( tax . rate for tax in taxes if tax . rate ) ) amount_sum = money_sum ( ( tax . amount for tax in taxes if tax . amount ) ) taxless = TaxlessPrice ( ( ( taxful . amount - amount_sum ) / ( 1 + rate_sum ) ) ) else : taxful = None taxless = price line_taxes = [ SourceLineTax . from_tax ( tax = tax , base_amount = taxless . amount ) for tax in taxes ] if ( taxful is None ) : total_tax_amount = money_sum ( ( x . amount for x in line_taxes ) ) taxful = TaxfulPrice ( ( taxless . amount + total_tax_amount ) ) return TaxedPrice ( taxful , taxless , line_taxes )
stack added taxes on the given price without compounding .