예제 #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_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)
예제 #3
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)
예제 #4
0
파일: models.py 프로젝트: ocwc/ocwc-members
    def sync_quickbooks_customer(self, qb_client):
        if settings.QB_ACTIVE and qb_client:
            if not self.qbo_id:
                customer = Customer()
            else:
                customer = Customer.get(self.qbo_id, qb=qb_client)

            customer.CompanyName = self.display_name
            customer.DisplayName = self.display_name
            customer.PrintOnCheckName = self.display_name

            billing_address = self.get_billing_address()
            if billing_address:
                customer.BillAddr = QuickBooksAddress()
                customer.BillAddr.Line1 = billing_address.street_address
                customer.BillAddr.Line2 = billing_address.supplemental_address_1
                customer.BillAddr.Line3 = billing_address.supplemental_address_2

                customer.BillAddr.City = billing_address.city
                customer.BillAddr.Country = billing_address.country.name
                customer.BillAddr.CountrySubDivisionCode = (
                    billing_address.state_province_abbr)
                customer.BillAddr.PostalCode = "{} {}".format(
                    billing_address.postal_code,
                    billing_address.postal_code_suffix).strip()

            primary_contact = self.contact_set.filter(contact_type=6)[0]
            accounting_contacts = self.contact_set.filter(contact_type=13)
            if accounting_contacts:
                accounting_emails = [
                    accounting_contact.email
                    for accounting_contact in accounting_contacts
                ]
            else:
                accounting_emails = [primary_contact.email]

            customer.PrimaryEmailAddr = EmailAddress()
            customer.PrimaryEmailAddr.Address = ", ".join(accounting_emails)

            customer.GivenName = primary_contact.first_name
            customer.FamilyName = primary_contact.last_name

            customer.save(qb=qb_client)

            self.qbo_id = customer.Id
            self.save()