def test_create(self): employee = Employee() employee.SSN = "444-55-6666" employee.GivenName = "John" employee.FamilyName = "Smith {0}".format( datetime.now().strftime('%d%H%M%S')) employee.PrimaryAddr = Address() employee.PrimaryAddr.Line1 = "45 N. Elm Street" employee.PrimaryAddr.City = "Middlefield" employee.PrimaryAddr.CountrySubDivisionCode = "CA" employee.PrimaryAddr.PostalCode = "93242" employee.PrimaryPhone = PhoneNumber() employee.PrimaryPhone.FreeFormNumber = "408-525-1234" employee.save(qb=self.qb_client) query_employee = Employee.get(employee.Id, qb=self.qb_client) self.assertEqual(query_employee.Id, employee.Id) self.assertEqual(query_employee.SSN, "XXX-XX-XXXX") self.assertEqual(query_employee.GivenName, employee.GivenName) self.assertEqual(query_employee.FamilyName, employee.FamilyName) self.assertEqual(query_employee.PrimaryAddr.Line1, employee.PrimaryAddr.Line1) self.assertEqual(query_employee.PrimaryAddr.City, employee.PrimaryAddr.City) self.assertEqual(query_employee.PrimaryAddr.CountrySubDivisionCode, employee.PrimaryAddr.CountrySubDivisionCode) self.assertEqual(query_employee.PrimaryAddr.PostalCode, employee.PrimaryAddr.PostalCode) self.assertEqual(query_employee.PrimaryPhone.FreeFormNumber, employee.PrimaryPhone.FreeFormNumber)
def test_create(self): vendor = Vendor() vendor.TaxIdentifier = '99-9999999' vendor.AcctNum = self.account_number vendor.Title = 'Ms.' vendor.GivenName = 'First' vendor.FamilyName = 'Last' vendor.Suffix = 'Sr.' vendor.CompanyName = self.name vendor.DisplayName = self.name vendor.PrintOnCheckName = self.name vendor.BillAddr = Address() vendor.BillAddr.Line1 = "123 Main" vendor.BillAddr.Line2 = "Apartment 1" vendor.BillAddr.City = "City" vendor.BillAddr.Country = "U.S.A" vendor.BillAddr.CountrySubDivisionCode = "CA" vendor.BillAddr.PostalCode = "94030" vendor.PrimaryPhone = PhoneNumber() vendor.PrimaryPhone.FreeFormNumber = '555-555-5555' vendor.PrimaryEmailAddr = EmailAddress() vendor.PrimaryEmailAddr.Address = '*****@*****.**' vendor.WebAddr = WebAddress() vendor.WebAddr.URI = 'http://testurl.com' vendor.save(qb=self.qb_client) query_vendor = Vendor.get(vendor.Id, qb=self.qb_client) self.assertEquals(query_vendor.Id, vendor.Id) self.assertEquals(query_vendor.AcctNum, self.account_number) self.assertEquals(query_vendor.Title, 'Ms.') self.assertEquals(query_vendor.GivenName, 'First') self.assertEquals(query_vendor.FamilyName, 'Last') self.assertEquals(query_vendor.Suffix, 'Sr.') self.assertEquals(query_vendor.CompanyName, self.name) self.assertEquals(query_vendor.DisplayName, self.name) self.assertEquals(query_vendor.PrintOnCheckName, self.name) self.assertEquals(query_vendor.BillAddr.Line1, "123 Main") self.assertEquals(query_vendor.BillAddr.Line2, "Apartment 1") self.assertEquals(query_vendor.BillAddr.City, "City") self.assertEquals(query_vendor.BillAddr.Country, "U.S.A") self.assertEquals(query_vendor.BillAddr.CountrySubDivisionCode, "CA") self.assertEquals(query_vendor.BillAddr.PostalCode, "94030") self.assertEquals(query_vendor.PrimaryPhone.FreeFormNumber, '555-555-5555') self.assertEquals(query_vendor.PrimaryEmailAddr.Address, '*****@*****.**') self.assertEquals(query_vendor.WebAddr.URI, 'http://testurl.com')
def test_create(self): customer = Customer() customer.Title = self.title customer.GivenName = self.given_name customer.MiddleName = self.middle_name customer.FamilyName = self.family_name customer.Suffix = self.suffix customer.FullyQualifiedName = self.fully_qualified_name customer.CompanyName = self.company_name customer.DisplayName = self.display_name customer.BillAddr = Address() customer.BillAddr.Line1 = "123 Main" customer.BillAddr.Line2 = "Apartment 1" customer.BillAddr.City = "City" customer.BillAddr.Country = "U.S.A" customer.BillAddr.CountrySubDivisionCode = "CA" customer.BillAddr.PostalCode = "94030" customer.PrimaryPhone = PhoneNumber() customer.PrimaryPhone.FreeFormNumber = '555-555-5555' customer.PrimaryEmailAddr = EmailAddress() customer.PrimaryEmailAddr.Address = '*****@*****.**' customer.save(qb=self.qb_client) query_customer = Customer.get(customer.Id, qb=self.qb_client) self.assertEquals(customer.Id, query_customer.Id) self.assertEqual(query_customer.Title, self.title) self.assertEqual(query_customer.GivenName, self.given_name) self.assertEqual(query_customer.MiddleName, self.middle_name) self.assertEqual(query_customer.FamilyName, self.family_name) self.assertEqual(query_customer.Suffix, self.suffix) self.assertEqual(query_customer.FullyQualifiedName, self.fully_qualified_name) self.assertEqual(query_customer.CompanyName, self.company_name) self.assertEqual(query_customer.DisplayName, self.display_name) self.assertEqual(query_customer.BillAddr.Line1, customer.BillAddr.Line1) self.assertEqual(query_customer.BillAddr.Line2, customer.BillAddr.Line2) self.assertEqual(query_customer.BillAddr.City, customer.BillAddr.City) self.assertEqual(query_customer.BillAddr.Country, customer.BillAddr.Country) self.assertEqual(query_customer.BillAddr.CountrySubDivisionCode, customer.BillAddr.CountrySubDivisionCode) self.assertEqual(query_customer.BillAddr.PostalCode, customer.BillAddr.PostalCode) self.assertEqual(query_customer.PrimaryPhone.FreeFormNumber, customer.PrimaryPhone.FreeFormNumber) self.assertEqual(query_customer.PrimaryEmailAddr.Address, customer.PrimaryEmailAddr.Address)
def qbo_create_customer(sc): client = create_qbc() customer = Customer() customer.GivenName = sc.first_name customer.FamilyName = sc.last_name customer.CompanyName = sc.company phone = PhoneNumber() phone.FreeFormNumber = sc.phone customer.PrimaryPhone = phone email = EmailAddress() email.Address = sc.email customer.PrimaryEmailAddr = email address = Address() address.Line1 = sc.address1 address.Line2 = sc.address2 address.City = sc.city address.PostalCode = sc.post_code customer.BillAddr = address customer.save(qb=client) return customer.Id
def test_unicode(self): address = Address() address.Line1 = "123 Main" address.City = "Joplin" address.CountrySubDivisionCode = "MO" address.PostalCode = "12345" self.assertEquals(str(address), "123 Main Joplin, MO 12345")
def test_create(self): self.customer = Customer.all(max_results=1, qb=self.qb_client)[0] estimate = Estimate() estimate.TotalAmt = 31.5 estimate.ApplyTaxAfterDiscount = False estimate.PrintStatus = "NeedToPrint" estimate.EmailStatus = "NotSet" estimate.BillAddr = Address() estimate.BillAddr.Line1 = "65 Ocean Dr." estimate.BillAddr.City = "Half Moon Bay" estimate.BillAddr.CountrySubDivisionCode = "CA" estimate.BillAddr.PostalCode = "94213" estimate.BillAddr.Lat = "37.4300318" estimate.BillAddr.Long = "-122.4336537" estimate.ShipAddr = Address() estimate.ShipAddr.Id = "2" + datetime.now().strftime('%d%H%M') estimate.ShipAddr.Line1 = "65 Ocean Dr." estimate.ShipAddr.City = "Half Moon Bay" estimate.ShipAddr.CountrySubDivisionCode = "CA" estimate.ShipAddr.PostalCode = "94213" estimate.ShipAddr.Lat = "37.4300318" estimate.ShipAddr.Long = "-122.4336537" estimate.BillEmail = EmailAddress() estimate.BillEmail.Address = "*****@*****.**" estimate.CustomerMemo = CustomerMemo() estimate.CustomerMemo.value = "Thank you for your business and have a great day!" estimate.CustomerRef = Ref() estimate.CustomerRef.value = self.customer.Id estimate.CustomerRef.name = self.customer.DisplayName estimate.TxnTaxDetail = TxnTaxDetail() estimate.TxnTaxDetail.TotalTax = 0 line = SalesItemLine() line.LineNum = 1 line.Description = "Pest Control Services" line.Amount = 35.0 line.SalesItemLineDetail = SalesItemLineDetail() line.SalesItemLineDetail.UnitPrice = 35 line.SalesItemLineDetail.Qty = 1 item_ref = Ref() item_ref.value = "10" item_ref.name = "Pest Control" line.SalesItemLineDetail.ItemRef = item_ref tax_code_ref = Ref() tax_code_ref.value = "NON" line.SalesItemLineDetail.TaxCodeRef = tax_code_ref estimate.Line.append(line) line2 = DiscountLine() line2.Amount = 3.5 line2.DiscountLineDetail = DiscountLineDetail() line2.DiscountLineDetail.PercentBased = True line2.DiscountLineDetail.DiscountPercent = 10 line2.DiscountLineDetail.DiscountAccountRef = Ref() line2.DiscountLineDetail.DiscountAccountRef.value = "86" line2.DiscountLineDetail.DiscountAccountRef.name = "Discounts given" line2.DetailType = "DiscountLineDetail" estimate.Line.append(line2) estimate.save(qb=self.qb_client) query_estimate = Estimate.get(estimate.Id, qb=self.qb_client) self.assertEqual(query_estimate.Id, estimate.Id) self.assertEqual(query_estimate.TotalAmt, estimate.TotalAmt) self.assertEqual(query_estimate.ApplyTaxAfterDiscount, estimate.ApplyTaxAfterDiscount) self.assertEqual(query_estimate.PrintStatus, estimate.PrintStatus) self.assertEqual(query_estimate.EmailStatus, estimate.EmailStatus) self.assertEqual(query_estimate.BillAddr.Line1, estimate.BillAddr.Line1) self.assertEqual(query_estimate.BillAddr.City, estimate.BillAddr.City) self.assertEqual(query_estimate.BillAddr.CountrySubDivisionCode, estimate.BillAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.BillAddr.PostalCode, estimate.BillAddr.PostalCode) self.assertEqual(query_estimate.ShipAddr.Line1, estimate.ShipAddr.Line1) self.assertEqual(query_estimate.ShipAddr.City, estimate.ShipAddr.City) self.assertEqual(query_estimate.ShipAddr.CountrySubDivisionCode, estimate.ShipAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.ShipAddr.PostalCode, estimate.ShipAddr.PostalCode) self.assertEqual(query_estimate.BillEmail.Address, estimate.BillEmail.Address) self.assertEqual(query_estimate.CustomerMemo.value, estimate.CustomerMemo.value) self.assertEqual(query_estimate.CustomerRef.value, estimate.CustomerRef.value) self.assertEqual(query_estimate.CustomerRef.name, estimate.CustomerRef.name) self.assertEqual(query_estimate.TxnTaxDetail.TotalTax, estimate.TxnTaxDetail.TotalTax) self.assertEqual(query_estimate.Line[0].LineNum, estimate.Line[0].LineNum) self.assertEqual(query_estimate.Line[0].Description, estimate.Line[0].Description) self.assertEqual(query_estimate.Line[0].Amount, estimate.Line[0].Amount) self.assertEqual(query_estimate.Line[0].SalesItemLineDetail.UnitPrice, estimate.Line[0].SalesItemLineDetail.UnitPrice) self.assertEqual(query_estimate.Line[0].SalesItemLineDetail.Qty, estimate.Line[0].SalesItemLineDetail.Qty) self.assertEqual(query_estimate.Line[2].Amount, estimate.Line[1].Amount) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.PercentBased, estimate.Line[1].DiscountLineDetail.PercentBased) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountPercent, estimate.Line[1].DiscountLineDetail.DiscountPercent) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountAccountRef.value, estimate.Line[1].DiscountLineDetail.DiscountAccountRef.value) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountAccountRef.name, estimate.Line[1].DiscountLineDetail.DiscountAccountRef.name)
def check_and_update_customer_information(cr, customer_id): # If the customer is found, then the tool will compare the address in the database by `<house number> <first token>` in the address. If this is a discrepancy, it prompts the user to make the change or not. # If the phone number is a mismatch and there is a new one, it just replaces it and moves the old one to the 2nd phone field in the customer record. # If the email is a mismatch and there is a new one, then it just replaces it wihtout prompting and moves it to the 2nd email field in the customer record. customer = Customer.get(customer_id, qb=qb_client) #phone number update phone_new = cr.customer_phone primary_phone_obj = customer.PrimaryPhone #print(type(customer.PrimaryPhone)) if phone_new is not None and primary_phone_obj is not None: phone_orig = customer.PrimaryPhone.FreeFormNumber formatted_new = phonenumbers.format_number( phonenumbers.parse(phone_new, "US"), phonenumbers.PhoneNumberFormat.NATIONAL) formatted_orig = phonenumbers.format_number( phonenumbers.parse(phone_orig, "US"), phonenumbers.PhoneNumberFormat.NATIONAL) if formatted_new != formatted_orig: #update the phone field in the customer logging.warning( "The database customer phone number:[{}] is different from the order: [{}]. Updating..." .format(formatted_orig, formatted_new)) orig_phone_struct = PhoneNumber() orig_phone_struct.FreeFormNumber = formatted_orig customer.AlternatePhone = orig_phone_struct customer.PrimaryPhone.FreeFormNumber = formatted_new customer.save(qb_client) else: if phone_new is not None: formatted_new = phonenumbers.format_number( phonenumbers.parse(phone_new, "US"), phonenumbers.PhoneNumberFormat.NATIONAL) logging.warning( "The database customer phone number is empty from the order: [{}]. Updating..." .format(formatted_new)) new_phone_struct = PhoneNumber() new_phone_struct.FreeFormNumber = formatted_new customer.PrimaryPhone = new_phone_struct customer.save(qb_client) #Customer email update customer = Customer.get(customer_id, qb=qb_client) email_new = cr.customer_email email_orig_obj = customer.PrimaryEmailAddr if email_new is not None and email_orig_obj is not None: email_orig = customer.PrimaryEmailAddr.Address if email_orig != email_new: #update the phone field in the customer logging.warning( "The database customer email:[{}] is different from the order: [{}]. Updating..." .format(email_orig, email_new)) customer.PrimaryEmailAddr.Address = email_new customer.save(qb_client) else: if email_new is not None: logging.warning( "The database customer email address is empty from the order: [{}]. Updating..." .format(email_new)) new_email_struct = EmailAddress() new_email_struct.Address = email_new customer.PrimaryEmailAddr = new_email_struct customer.save(qb_client) #Customer address update customer = Customer.get(customer_id, qb=qb_client) address_line1_new = cr.customer_street address_line1_old_obj = customer.BillAddr if address_line1_new is not None and address_line1_old_obj is not None: address_line1_old = customer.BillAddr.Line1 if address_line1_new != address_line1_old: #update the phone field in the customer logging.warning( "The database billing address:[{}] is different from the order: [{}]. Updating..." .format(address_line1_old, address_line1_new)) answer = yesno( "Update the address from [{}] to [{}] for customer: [{}]". format(address_line1_old, address_line1_new, customer.DisplayName)) if answer: customer.BillAddr.Line1 = address_line1_new customer.BillAddr.City = cr.customer_city customer.BillAddr.CountrySubDivisionCode = cr.customer_state customer.BillAddr.PostalCode = cr.customer_zip customer.ShipAddr = customer.BillAddr try: customer.save(qb_client) except ValidationException as ve: print(ve.detail) else: if address_line1_new is not None: logging.warning( "The database customer billing address is empty from the order: [{}]. Updating..." .format(address_line1_new)) new_address_struct = Address() new_address_struct.Line1 = address_line1_new new_address_struct.City = cr.customer_city new_address_struct.CountrySubDivisionCode = cr.customer_state new_address_struct.PostalCode = cr.customer_zip customer.BillAddr = customer.ShipAddr = new_address_struct customer.save(qb_client)