~edwinvandeven/openstudio/2.01

« back to all changes in this revision

Viewing changes to web2py/applications/OpenStudio/controllers/customers.py

  • Committer: Edwin van de Ven
  • Date: 2013-11-14 06:57:25 UTC
  • Revision ID: edwinvandeven@home.nl-20131114065725-olzcpwykhjntfxbc
Fixed bug 1232972
Now a list of errors is exported if there are any when exporting a csv file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
            msyear = today.year # set the default value for the year
141
141
    elif session.cu_name != '' or session.cu_active != '' or (session.cu_msyear != None and session.cu_msmonth != None and session.cu_mstype != None):
142
142
        print "Showing persistent results"
 
143
        print session.cu_name
 
144
        print session.cu_active
143
145
        # persistent search until cleared manually
144
146
        response.subtitle = T("Showing search results")
145
147
        if session.cu_name != '':
148
150
        if session.cu_active != '':
149
151
            active = session.cu_active # has to be set to be used as a default value for the widgets
150
152
            query = list_get_active_query(query, active)
151
 
        else:
 
153
        if session.cu_year != None and session.cu_month != None and session.cu_mstype != None:
152
154
            msmonth = session.cu_msmonth # has to be set to be used as a default value for the widgets
153
155
            msyear = session.cu_msyear # has to be set to be used as a default value for the widgets
154
156
            mstype = session.cu_mstype # has to be set to be used as a default value for the widgets
617
619
                if row.bankdetails.AccountNumber == None or row.bankdetails.AccountNumber == "":
618
620
                    error = True
619
621
                    message += T("Please add a bank account number for") + " " + row.customers.FirstName + " " + row.customers.LastName + "\n"
 
622
                elif row.bankdetails.AccountHolder == None or row.bankdetails.AccountHolder == "":
 
623
                    error = True
 
624
                    message += T("Please add a bank account holder for") + " " + row.customers.FirstName + " " + row.customers.LastName + "\n"
620
625
                else:
621
626
                    holder = row.bankdetails.AccountHolder
622
627
                    banklocation = row.bankdetails.BankLocation
692
697
            if row.bankdetails.AccountNumber == None or row.bankdetails.AccountNumber == "":
693
698
                error = True
694
699
                message += T("Please add a bank account number for") + " " + row.customers.Firstname + " " + row.customers.LastName + "\n"
 
700
            elif row.bankdetails.AccountHolder == None or row.bankdetails.AccountHolder == "":
 
701
                error = True
 
702
                message += T("Please add a bank account holder for") + " " + row.customers.FirstName + " " + row.customers.LastName + "\n"
695
703
            else:
696
704
                writer.writerow([holder] + [banklocation] + [currency] + [row.alternativepayments.Amount] + [accountnr] + \
697
705
                    [bic] + [row.alternativepayments.Description])
698
706
    
699
707
    #print "Buffer end: \n"
700
708
    #print stream.getvalue()
701
 
    response.headers['Content-Type']='application/vnd.ms-excel'
 
709
    if error == True:
 
710
        stream.truncate(0) # empty all written rows
 
711
        stream.write("Errors were encountered while exporting:\n\n")
 
712
        stream.write(message) # write errors instead
 
713
        fname = 'export_errors.txt'
 
714
        response.headers['Content-Type']='text;charset=utf-8'
 
715
    else:
 
716
        response.headers['Content-Type']='application/vnd.ms-excel'
 
717
        
702
718
    response.headers['Content-disposition']='attachment; filename=' + fname
703
719
    return stream.getvalue()
704
720