#NEWLINE# def _generate_number( self , default_starting_number = 1 ) : #NEWLINE# #INDENT# 'Generates the number for a proforma/invoice.' #NEWLINE# default_starting_number = max ( default_starting_number , 1 ) #NEWLINE# documents = self . __class__ . _default_manager . filter ( provider = self . provider , series = self . series ) #NEWLINE# if ( not documents . exists ( ) ) : #NEWLINE# #INDENT# if ( self . series == self . default_series ) : #NEWLINE# #INDENT# return self . _starting_number #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return default_starting_number #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# max_existing_number = documents . aggregate ( Max ( 'number' ) ) [ 'number__max' ] #NEWLINE# if max_existing_number : #NEWLINE# #INDENT# if ( self . _starting_number and ( documents . series == self . default_series ) ) : #NEWLINE# #INDENT# return max ( ( max_existing_number + 1 ) , self . _starting_number ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( max_existing_number + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return default_starting_number