new customer wizard works
authorKonrad Rosenbaum <konrad@silmor.de>
Fri, 13 Jul 2012 07:57:09 +0000 (09:57 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Fri, 13 Jul 2012 07:57:09 +0000 (09:57 +0200)
src/dialogs/customerdlg.cpp

index 74d011c..f4587f1 100644 (file)
@@ -1021,16 +1021,31 @@ void MNewCustomerWizard::save()
        MOAddress adr;
        adr.setaddr1(m_addr1->text());
        adr.setcity(m_city->currentText());
-       adr.setstate(m_state->currentText());
+       if(!m_state->currentText().trimmed().isEmpty())
+               adr.setstate(m_state->currentText());
        adr.setzipcode(m_zipcode->text());
-       //handle country
-       qDebug()<<"Country Idx"<<m_country->currentIndex()<<"Name"<<m_country->currentText()<<"ID"<<m_country->itemData(m_country->currentIndex()).toString();
-       return;
-//     adr.setcountryid(m_country->);
+       adr.setcountryid(m_country->itemData(m_country->currentIndex()).toString());
        //complete addr
        inp.addaddresses(adr);
+       //contacts
+       for(int i=0;i<m_typelist.size() && i<m_contact.size();i++){
+               const MOContactType&ct=m_typelist[i];
+               if(ct.contacttypeid().isNull())continue;
+               QLineEdit*le=m_contact[i];
+               if(le==nullptr)continue;
+               if(le->text().trimmed().isEmpty())continue;
+               MOContact con;
+               con.setcontacttypeid(ct.contacttypeid());
+               con.setcontact(le->text());
+               inp.addcontacts(con);
+       }
        //create customer
        MTCreateCustomer cc=req->queryCreateCustomer(inp);
+       if(!cc.hasError()){
+               m_cust=cc.getcustomer();
+               accept();
+               return;
+       }
        if(QMessageBox::warning(this,tr("Warning"),tr("There was an error while creating the customer: %1").arg(cc.errorString()),QMessageBox::Abort|QMessageBox::Retry)==QMessageBox::Retry)return;
        //close dialog
        accept();