Beispiel #1
0
    def test_object_list_mixin_with_qb_objects(self):

        pn1, pn2, pn3, pn4, pn5 = PhoneNumber(), PhoneNumber(), PhoneNumber(
        ), PhoneNumber(), PhoneNumber()
        test_object_list = [pn1, pn2, pn3]
        test_subclass_object_obj = self.TestSubclass(test_object_list)
        self.assertEquals(test_object_list, test_subclass_object_obj[:])

        for index in range(0, len(test_subclass_object_obj)):
            self.assertEquals(test_object_list[index],
                              test_subclass_object_obj[index])

        for obj in test_subclass_object_obj:
            self.assertEquals(True, obj in test_subclass_object_obj)

        self.assertEquals(pn3, test_subclass_object_obj.pop())
        test_subclass_object_obj.append(pn4)
        self.assertEquals([pn1, pn2, pn4], test_subclass_object_obj[:])

        test_subclass_object_obj[0] = pn5
        self.assertEquals([pn5, pn2, pn4], test_subclass_object_obj[:])

        del test_subclass_object_obj[0]
        self.assertEquals([pn2, pn4], test_subclass_object_obj[:])

        self.assertEquals([pn4, pn2], list(reversed(test_subclass_object_obj)))
    def test_to_json(self):
        phone = PhoneNumber()
        phone.FreeFormNumber = "555-555-5555"

        json = phone.to_json()

        self.assertEquals(json, '{\n    "FreeFormNumber": "555-555-5555"\n}')
Beispiel #3
0
    def test_to_json(self):
        phone = PhoneNumber()
        phone.FreeFormNumber = "555-555-5555"

        json = phone.to_json()

        self.assertEquals(json, '{\n    "FreeFormNumber": "555-555-5555"\n}')
Beispiel #4
0
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
Beispiel #5
0
    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')
Beispiel #7
0
    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)
Beispiel #8
0
    def test_unicode(self):
        number = PhoneNumber()
        number.FreeFormNumber = "555-555-5555"

        self.assertEquals(str(number), "555-555-5555")
Beispiel #9
0
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)