@classmethod<EOL><INDENT>def create_from_registration(cls, reg, **kwargs):<DEDENT>
submissionUser = kwargs.pop('<STR_LIT>', None)<EOL>collectedByUser = kwargs.pop('<STR_LIT>', None)<EOL>status = kwargs.pop('<STR_LIT:status>',Invoice.PaymentStatus.unpaid)<EOL>new_invoice = cls(<EOL>firstName=reg.firstName,<EOL>lastName=reg.lastName,<EOL>email=reg.email,<EOL>grossTotal=reg.totalPrice,<EOL>total=reg.priceWithDiscount,<EOL>submissionUser=submissionUser,<EOL>collectedByUser=collectedByUser,<EOL>buyerPaysSalesTax=getConstant('<STR_LIT>'),<EOL>status=status,<EOL>data=kwargs,<EOL>)<EOL>if isinstance(reg, Registration):<EOL><INDENT>new_invoice.finalRegistration = reg<EOL>ter_set = reg.eventregistration_set.all()<EOL><DEDENT>elif isinstance(reg, TemporaryRegistration):<EOL><INDENT>new_invoice.temporaryRegistration = reg<EOL>ter_set = reg.temporaryeventregistration_set.all()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>new_invoice.calculateTaxes()<EOL>new_invoice.save()<EOL>for ter in ter_set:<EOL><INDENT>item_kwargs = {<EOL>'<STR_LIT>': new_invoice,<EOL>'<STR_LIT>': ter.price,<EOL>}<EOL>if new_invoice.grossTotal > <NUM_LIT:0>:<EOL><INDENT>item_kwargs.update({<EOL>'<STR_LIT>': ter.price * (new_invoice.total / new_invoice.grossTotal),<EOL>'<STR_LIT>': new_invoice.taxes * (ter.price / new_invoice.grossTotal),<EOL>'<STR_LIT>': new_invoice.fees * (ter.price / new_invoice.grossTotal),<EOL>})<EOL><DEDENT>else:<EOL><INDENT>item_kwargs.update({<EOL>'<STR_LIT>': ter.price,<EOL>'<STR_LIT>': new_invoice.taxes,<EOL>'<STR_LIT>': new_invoice.fees,<EOL>})<EOL><DEDENT>if isinstance(ter,TemporaryEventRegistration):<EOL><INDENT>item_kwargs['<STR_LIT>'] = ter<EOL><DEDENT>elif isinstance(ter,EventRegistration):<EOL><INDENT>item_kwargs['<STR_LIT>'] = ter<EOL><DEDENT>this_item = InvoiceItem(**item_kwargs)<EOL>this_item.save()<EOL><DEDENT>return new_invoice<EOL>
Handles the creation of an Invoice as well as one InvoiceItem per
assodciated TemporaryEventRegistration or registration.  Also handles taxes
appropriately.