#NEWLINE# def generate( self ) : #NEWLINE# #INDENT# qs = OrderDiscount . _default_manager . all ( ) #NEWLINE# if self . start_date : #NEWLINE# #INDENT# qs = qs . filter ( order__date_placed__gte = self . start_date ) #NEWLINE# #UNINDENT# if self . end_date : #NEWLINE# #INDENT# qs = qs . filter ( order__date_placed__lt = ( self . end_date + datetime . timedelta ( days = 1 ) ) ) #NEWLINE# #UNINDENT# offer_discounts = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for discount in qs : #NEWLINE# #INDENT# if ( discount . offer_id not in offer_discounts ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# all_offers = ConditionalOffer . _default_manager #NEWLINE# offer = all_offers . get ( id = discount . offer_id ) #NEWLINE# #UNINDENT# except ConditionalOffer . DoesNotExist : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# offer_discounts [ discount . offer_id ] = { #NEWLINE# #INDENT# 'offer' : offer , #NEWLINE# 'total_discount' : D ( '0.00' ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# offer_discounts [ discount . offer_id ] [ 'total_discount' ] += discount . amount #NEWLINE# #UNINDENT# return self . formatter . generate_response ( offer_discounts . values ( ) )