#NEWLINE# def sync_invoice_items( invoice , items ) : #NEWLINE# #INDENT# '\n    Syncronizes all invoice line items for a particular invoice\n\n    This assumes line items from a Stripe invoice.lines property and not through\n    the invoicesitems resource calls. At least according to the documentation\n    the data for an invoice item is slightly different between the two calls.\n\n    For example, going through the invoiceitems resource you don\'t get a "type"\n    field on the object.\n\n    Args:\n        invoice_: the invoice objects to syncronize\n        items: the data from the Stripe API representing the line items\n    ' #NEWLINE# for item in items : #NEWLINE# #INDENT# period_end = utils . convert_tstamp ( item [ 'period' ] , 'end' ) #NEWLINE# period_start = utils . convert_tstamp ( item [ 'period' ] , 'start' ) #NEWLINE# if item . get ( 'plan' ) : #NEWLINE# #INDENT# plan = models . Plan . objects . get ( stripe_id = item [ 'plan' ] [ 'id' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# plan = None #NEWLINE# #UNINDENT# if ( item [ 'type' ] == 'subscription' ) : #NEWLINE# #INDENT# if ( invoice . subscription and ( invoice . subscription . stripe_id == item [ 'id' ] ) ) : #NEWLINE# #INDENT# item_subscription = invoice . subscription #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stripe_subscription = subscriptions . retrieve ( invoice . customer , item [ 'id' ] ) #NEWLINE# item_subscription = ( subscriptions . sync_subscription_from_stripe_data ( inv_item_created . customer , stripe_subscription ) if stripe_subscription else None ) #NEWLINE# #UNINDENT# plan = ( item_subscription . plan if ( ( item_subscription is not None ) and ( plan is None ) ) else None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# item_subscription = None #NEWLINE# #UNINDENT# defaults = dict ( amount = utils . convert_amount_for_db ( item [ 'amount' ] , item [ 'currency' ] ) , currency = item [ 'currency' ] , proration = item [ 'proration' ] , description = ( item . get ( 'description' ) or '' ) , line_type = item [ 'type' ] , plan = plan , period_start = period_start , period_end = period_end , quantity = item . get ( 'quantity' ) , subscription = item_subscription ) #NEWLINE# ( inv_item , inv_item_created ) = invoice . items . get_or_create ( stripe_id = item [ 'id' ] , defaults = defaults ) #NEWLINE# utils . update_with_defaults ( inv_item , defaults , inv_item_created )