def applyAndAllocate(self,allocatedPrices,tieredTuples,payAtDoor=False):
initial_net_price = sum([x for x in allocatedPrices])<EOL>if self.discountType == self.DiscountType.flatPrice:<EOL><INDENT>applicable_price = self.getFlatPrice(payAtDoor) or <NUM_LIT:0><EOL>this_price = applicable_price+ sum([x[<NUM_LIT:0>].event.getBasePrice(payAtDoor=payAtDoor) * x[<NUM_LIT:1>] if x[<NUM_LIT:1>] != <NUM_LIT:1> else x[<NUM_LIT:0>].price for x in tieredTuples])<EOL>this_allocated_prices = [x * (this_price / initial_net_price) for x in allocatedPrices]<EOL><DEDENT>elif self.discountType == self.DiscountType.dollarDiscount:<EOL><INDENT>this_price = initial_net_price - self.dollarDiscount<EOL>this_allocated_prices = [x * (this_price / initial_net_price) for x in allocatedPrices]<EOL><DEDENT>elif self.discountType == DiscountCombo.DiscountType.percentDiscount:<EOL><INDENT>if self.percentUniversallyApplied:<EOL><INDENT>this_price =initial_net_price * (<NUM_LIT:1> - (max(min(self.percentDiscount or <NUM_LIT:0>,<NUM_LIT:100>),<NUM_LIT:0>) / <NUM_LIT:100>))<EOL>this_allocated_prices = [x * (this_price / initial_net_price) for x in allocatedPrices]<EOL><DEDENT>else:<EOL><INDENT>this_price = <NUM_LIT:0><EOL>this_allocated_prices = []<EOL>for idx, val in enumerate(tieredTuples):<EOL><INDENT>this_val = (<EOL>allocatedPrices[idx] *<EOL>(<NUM_LIT:1> - val[<NUM_LIT:1>]) * (<NUM_LIT:1> - (max(min(self.percentDiscount or <NUM_LIT:0>,<NUM_LIT:100>),<NUM_LIT:0>) / <NUM_LIT:100>)) +<EOL>allocatedPrices[idx] * val[<NUM_LIT:1>]<EOL>)<EOL>this_allocated_prices.append(this_val)<EOL>this_price += this_val<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise KeyError(_('<STR_LIT>'))<EOL><DEDENT>if this_price < initial_net_price:<EOL><INDENT>this_price = max(this_price, <NUM_LIT:0>)<EOL>return self.DiscountInfo(self, this_price, initial_net_price - this_price, this_allocated_prices)<EOL><DEDENT>
This method takes an initial allocation of prices across events, and
an identical length list of allocation tuples.  It applies the rule
specified by this discount, allocates the discount across the listed
items, and returns both the price and the allocation