#NEWLINE# @ permission_required ( 'core.manage_shop' ) #NEWLINE# def add_vouchers( request , group_id ) : #NEWLINE# #INDENT# '\n    ' #NEWLINE# voucher_group = VoucherGroup . objects . get ( pk = group_id ) #NEWLINE# form = VoucherForm ( data = request . POST ) #NEWLINE# msg = '' #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# amount = int ( request . POST . get ( 'amount' , 0 ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# amount = 0 #NEWLINE# #UNINDENT# for i in range ( 0 , amount ) : #NEWLINE# #INDENT# number = lfs . voucher . utils . create_voucher_number ( ) #NEWLINE# counter = 0 #NEWLINE# while ( Voucher . objects . filter ( number = number ) . exists ( ) and ( counter < 100 ) ) : #NEWLINE# #INDENT# number = lfs . voucher . utils . create_voucher_number ( ) #NEWLINE# counter += 1 #NEWLINE# #UNINDENT# if ( counter == 100 ) : #NEWLINE# #INDENT# msg = _ ( 'Unable to create unique Vouchers for the options specified.' ) #NEWLINE# break #NEWLINE# #UNINDENT# Voucher . objects . create ( number = number , group = group_id , creator = request . user , kind_of = request . POST . get ( 'kind_of' , 0 ) , value = request . POST . get ( 'value' , 0.0 ) , start_date = request . POST . get ( 'start_date' ) , end_date = request . POST . get ( 'end_date' ) , effective_from = request . POST . get ( 'effective_from' ) , tax_id = request . POST . get ( 'tax' ) , limit = request . POST . get ( 'limit' ) ) #NEWLINE# msg = _ ( 'Vouchers have been created.' ) #NEWLINE# #UNINDENT# #UNINDENT# return render_to_ajax_response ( ( ( '#vouchers' , vouchers_tab ( request , voucher_group ) ) , ) , msg )