#NEWLINE# def _get_extra_consumed_units_during_trial( self , metered_feature , consumed_units ) : #NEWLINE# #INDENT# '\n        :returns: (extra_consumed, free_units)\n            extra_consumed - units consumed extra during trial that will be\n                billed\n            free_units - the units included in trial\n        ' #NEWLINE# if self . is_billed_first_time : #NEWLINE# #INDENT# return self . _get_consumed_units_from_total_included_in_trial ( metered_feature , consumed_units ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# last_log_entry = self . billing_log_entries . all ( ) [ 0 ] #NEWLINE# if last_log_entry . proforma : #NEWLINE# #INDENT# qs = last_log_entry . proforma . proforma_entries . filter ( product_code = metered_feature . product_code ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# qs = last_log_entry . invoice . invoice_entries . filter ( product_code = metered_feature . product_code ) #NEWLINE# #UNINDENT# if ( not qs . exists ( ) ) : #NEWLINE# #INDENT# return self . _get_consumed_units_from_total_included_in_trial ( metered_feature , consumed_units ) #NEWLINE# #UNINDENT# consumed = [ qs_item . quantity for qs_item in qs if ( consumed_in_last_billing_cycle . unit_price >= 0 ) ] #NEWLINE# consumed_in_last_billing_cycle = sum ( consumed ) #NEWLINE# if metered_feature . included_units_during_trial : #NEWLINE# #INDENT# included_during_trial = metered_feature . included_units_during_trial #NEWLINE# if ( consumed_in_last_billing_cycle > included_during_trial ) : #NEWLINE# #INDENT# return ( consumed_units , 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# remaining = ( included_during_trial - consumed_in_last_billing_cycle ) #NEWLINE# if ( consumed_units > remaining ) : #NEWLINE# #INDENT# return ( ( consumed_units - remaining ) , remaining ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( consumed_units <= remaining ) : #NEWLINE# #INDENT# return ( 0 , consumed_units ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( 0 , consumed_units )