Пример #1
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
Пример #2
0
    def test_unicode(self):
        email = EmailAddress()
        email.Address = "*****@*****.**"

        self.assertEquals(str(email), "*****@*****.**")
Пример #3
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)