API Object

class pyavatax.api.API(account_number, license_key, company_code, live=False, logger=None, recorder=None, **kwargs)
DEVELOPMENT_HOST = 'development.avalara.net'
PRODUCTION_HOST = 'rest.avalara.net'
VERSION = '1.0'
cancel_tax(doc, reason=None, doc_id=None)

Performs a HTTP POST to tax/cancel/

get_tax(lat, lng, doc, sale_amount=None)

Performs a HTTP GET to tax/get/

post_tax(doc, commit=False)

Performs a HTTP POST to tax/get/ If commit=True we will update the document’s Commit flag to True, and we will check the document type to make sure it is capable of being Commited. XXXXXOrder is not capable of being commited. We will change it to XXXXXXXInvoice, which is capable of being committed

validate_address(address)

Performs a HTTP GET to address/validate/

Avalara Objects

Avalara Document

class pyavatax.base.Document(logger=None, *args, **kwargs)

Represents the Avalara Document

CANCEL_ADJUSTMENT_CANCELED = 'AdjustmentCanceled'
CANCEL_CODES = ('PostFailed', 'DocDeleted', 'DocVoided', 'AdjustmentCanceled')
CANCEL_DOC_DELETED = 'DocDeleted'
CANCEL_DOC_VOIDED = 'DocVoided'
CANCEL_POST_FAILED = 'PostFailed'
DOC_TYPES = ('SalesOrder', 'SalesInvoice', 'ReturnOrder', 'ReturnInvoice', 'PurchaseOrder', 'PurchaseInvoice', 'InventoryTransferOrder', 'InventoryTransferInvoice')
DOC_TYPE_INVENTORY_INVOICE = 'InventoryTransferInvoice'
DOC_TYPE_INVENTORY_ORDER = 'InventoryTransferOrder'
DOC_TYPE_PURCHASE_INVOICE = 'PurchaseInvoice'
DOC_TYPE_PURCHASE_ORDER = 'PurchaseOrder'
DOC_TYPE_RETURN_INVOICE = 'ReturnInvoice'
DOC_TYPE_RETURN_ORDER = 'ReturnOrder'
DOC_TYPE_SALE_INVOICE = 'SalesInvoice'
DOC_TYPE_SALE_ORDER = 'SalesOrder'
static _clean_date(date)
static _clean_float(f)
static _clean_int(i)
_contains = ['Lines', 'Addresses']
_fields = ['DocType', 'DocId', 'DocCode', 'DocDate', 'CompanyCode', 'CustomerCode', 'Discount', 'Commit', 'CustomerUsageType', 'PurchaseOrderNo', 'ExemptionNo', 'PaymentDate', 'ReferenceCode', 'PosLaneCode', 'Client']
_has = ['DetailLevel', 'TaxOverride']
add_address(address=None, **kwargs)

Adds an Address instance to this document. Nothing about the address will be changed, you are entirely responsible for it

add_from_address(address=None, **kwargs)

Only use this function when performing a simple shipping operation. The default from address code will be used for this address

add_line(line=None, **kwargs)

Adds a Line instance to this document. Will provide a LineNo if you do not

add_override(override=None, **kwargs)

Adds a tax override instance to this document

add_to_address(address=None, **kwargs)

Only use this function when performing a simple shipping operation. The default to address code will be used for this address

clean_Commit()
clean_Discount()
clean_DocDate()
clean_DocType()
clean_PaymentDate()
static from_data(data)
static new_inventory_invoice(*args, **kwargs)
static new_inventory_order(*args, **kwargs)
static new_purchase_invoice(*args, **kwargs)
static new_purchase_order(*args, **kwargs)
static new_return_invoice(*args, **kwargs)
static new_return_order(*args, **kwargs)
static new_sales_invoice(*args, **kwargs)
static new_sales_order(*args, **kwargs)
set_detail_level(detail_level=None, **kwargs)

Add a DetailLevel instance to this Avalara document

total

Helper representing the line items total amount for tax. Used in GetTax call

update_doc_code_from_response(post_tax_response)

Sets the DocCode on the Document based on the response if Document does not have a DocCode

validate()

Ensures we have addresses and line items. Then calls validate_codes

validate_codes()

Look through line items making sure that origin and destination codes are set set defaults if they exist, raise exception if we are missing something

Document static factory methods

The new_xxxxx_order and new_xxxxx_invoice calls are static factory functions on the Document class to create a corresponding Document with the intended DocType

Avalara Line

class pyavatax.base.Line(*args, **kwargs)

Represents an Avalara Line

_fields = ['LineNo', 'DestinationCode', 'OriginCode', 'Qty', 'Amount', 'ItemCode', 'TaxCode', 'CustomerUsageType', 'Description', 'Discounted', 'TaxIncluded', 'Ref1', 'Ref2']
clean_Amount()
clean_ItemCode()
clean_Qty()
static from_data(data)

Avalara Address

class pyavatax.base.Address(allow_new_fields=False, *args, **kwargs)

Represents an Avalara Address

DEFAULT_FROM_ADDRESS_CODE = '1'
DEFAULT_TO_ADDRESS_CODE = '2'
_fields = ['AddressCode', 'Line1', 'Line2', 'Line3', 'PostalCode', 'Region', 'City', 'TaxRegionId', 'Country', 'AddressType', 'County', 'FipsCode', 'CarrierRoute', 'TaxRegionId', 'PostNet']
describe_address_type

Returns human-readable description

describe_carrier_route

Returns human-readable description

describe_fips_code

Returns human-readable description

describe_post_net

Returns human-readable description

static from_data(data)

Avalara TaxOverride

class pyavatax.base.TaxOverride(allow_new_fields=False, *args, **kwargs)

Represents an Avalara TaxOverride

OVERRIDE_AMOUNT = 'TaxAmount'
OVERRIDE_DATE = 'TaxDate'
OVERRIDE_EXEMPT = 'Exemption'
OVERRIDE_NONE = 'None'
OVERRIDE_TYPES = ('None', 'TaxAmount', 'TaxDate', 'Exemption')
_fields = ['TaxOverrideType', 'TaxAmount', 'TaxDate', 'Reason']
clean_Reason()
clean_TaxAmount()
clean_TaxDate()
clean_TaxOverrideType()
clean_me()
static from_data(data)

Avalara Response Representations

class pyavatax.base.BaseResponse(response, *args, **kwargs)

Common functionality for handling Avalara server responses

error

Returns a list of tuples. The first position in the tuple is either the offending field that threw an error, or the class in the Avalara system that threw it. The second position is a human-readable message from Avalara

is_success

Returns whether or not the response was successful

class pyavatax.base.ErrorResponse(response, *args, **kwargs)

Common error case functionality from a 500 error

error

Returns a list of tuples. The first position in the tuple is either the offending field that threw an error, or the class in the Avalara system that threw it. The second position is a human-readable message from Avalara

is_success

Returns whether or not the response was successful

GetTax Response

class pyavatax.api.GetTaxResponse(response, *args, **kwargs)
_contains = ['TaxDetails']
_fields = ['Rate', 'Tax', 'ResultCode']
total_tax
class pyavatax.base.TaxDetails(allow_new_fields=False, *args, **kwargs)

Represents TaxDetails response from Avalara

_fields = ['Country', 'Region', 'JurisType', 'JurisCode', 'Taxable', 'Rate', 'Tax', 'JurisName', 'TaxName']

PostTax Response

class pyavatax.api.PostTaxResponse(response, *args, **kwargs)
_contains = ['TaxLines', 'TaxDetails', 'TaxAddresses']
_fields = ['DocCode', 'DocId', 'DocDate', 'Timestamp', 'TotalAmount', 'TotalDiscount', 'TotalExemption', 'TotalTaxable', 'TotalTax', 'TotalTaxCalculated', 'TaxDate', 'ResultCode']
total_tax
class pyavatax.base.TaxLines(allow_new_fields=False, *args, **kwargs)

Represents TaxLines response from Avalara

_contains = ['TaxDetails']
_fields = ['LineNo', 'TaxCode', 'BoundaryLevel', 'Taxability', 'Taxable', 'Rate', 'Tax', 'Discount', 'TaxCalculated', 'Exemption']
class pyavatax.base.TaxDetails(allow_new_fields=False, *args, **kwargs)

Represents TaxDetails response from Avalara

_fields = ['Country', 'Region', 'JurisType', 'JurisCode', 'Taxable', 'Rate', 'Tax', 'JurisName', 'TaxName']
class pyavatax.base.TaxAddresses(allow_new_fields=False, *args, **kwargs)

Represents TaxAddress response from Avalara

_contains = ['TaxDetails']
_fields = ['Address', 'AddressCode', 'Latitude', 'Longitude', 'City', 'Country', 'PostalCode', 'Region', 'TaxRegionId', 'JurisCode']

CancelTax Response

class pyavatax.api.CancelTaxResponse(response, *args, **kwargs)
_details
_has = ['CancelTaxResult']
error

Returns a list of tuples. The first position in the tuple is either the offending field that threw an error, or the class in the Avalara system that threw it. The second position is a human-readable message from Avalara. Avalara bungled this response, it is formatted differently than every other response

is_success

Returns whether or not the response was successful. Avalara bungled this response, it is formatted differently than every other response

class pyavatax.base.CancelTaxResult(allow_new_fields=False, *args, **kwargs)

Represents CancelTaxResult response from Avalara

_contains = ['Messages']
_fields = ['DocId', 'TransactionId', 'ResultCode']

ValidateAddress Response

class pyavatax.api.ValidateAddressResponse(response, *args, **kwargs)
_fields = ['ResultCode']
_has = ['Address']
class pyavatax.base.Address(allow_new_fields=False, *args, **kwargs)

Represents an Avalara Address

DEFAULT_FROM_ADDRESS_CODE = '1'
DEFAULT_TO_ADDRESS_CODE = '2'
_fields = ['AddressCode', 'Line1', 'Line2', 'Line3', 'PostalCode', 'Region', 'City', 'TaxRegionId', 'Country', 'AddressType', 'County', 'FipsCode', 'CarrierRoute', 'TaxRegionId', 'PostNet']
describe_address_type

Returns human-readable description

describe_carrier_route

Returns human-readable description

describe_fips_code

Returns human-readable description

describe_post_net

Returns human-readable description

static from_data(data)

Exceptions

exception pyavatax.base.AvalaraException(*args, **kwargs)

Raised when operating unsuccessfully with document, address, line, etc objects

CODE_BAD_ADDRESS = 201
CODE_BAD_ARGS = 100
CODE_BAD_BOOL = 305
CODE_BAD_CANCEL = 103
CODE_BAD_DATE = 303
CODE_BAD_DEST = 307
CODE_BAD_DETAIL = 202
CODE_BAD_DOC = 101
CODE_BAD_DOCTYPE = 302
CODE_BAD_FLOAT = 304
CODE_BAD_LATLNG = 102
CODE_BAD_LINE = 203
CODE_BAD_ORIGIN = 306
CODE_BAD_OTYPE = 309
CODE_BAD_OVERRIDE = 204
CODE_HAS_FROM = 104
CODE_HAS_TO = 105
CODE_INVALID_FIELD = 301
CODE_REQD = 50
CODE_TOO_LONG = 308
exception pyavatax.base.AvalaraTypeException(*args, **kwargs)

Raised when passed wrongly typed data, or a non-Avalara object when one is expected

exception pyavatax.base.AvalaraValidationException(*args, **kwargs)

Raised when object data does not pass validation

exception pyavatax.base.AvalaraServerException(response, *args, **kwargs)

Used internally to handle 500 and other server error responses

errors

Will return an ErrorResponse details property, or the raw text server response

full_request_as_string

Returns all the info we have about the request and response

exception pyavatax.base.AvalaraServerDetailException(response, *args, **kwargs)

Useful for seeing more detail through the tester and logs We always throw this exception, though you may catch AvalaraServerException if you don’t care to see the details in the __str__

exception pyavatax.base.AvalaraServerNotReachableException(request_exception, *args, **kwargs)

Raised when the AvaTax service is unreachable for any reason and no response is received