Logo
Section 1 / 4

交易创建与生命周期

学习如何使用AvaTax API创建税务交易,并理解不同的交易状态。

导入

交易创建与生命周期

学习如何使用AvaTax API创建税务交易,并理解不同的交易状态。

...

代码示例

1https://sandbox-rest.avatax.com/api/v2/transactions/create

请求参数

参数名类型参数类型分类说明
$includestring查询可选此参数指定我们希望 API 在交易创建请求的响应中包含的对象。
codestring正文可选此参数指定交易的唯一代码,便于快速引用、更新或对账。
linesitem对象数组正文必需此参数列出交易中的明细项目。
typestring正文可选此参数指定交易类型。发票为永久性交易,订单为用于估算的临时交易。支持的值包括:SalesOrder、SalesInvoice、PurchaseOrder、PurchaseInvoice、ReturnOrder、ReturnInvoice、InventoryTransferOrder、InventoryTransferInvoice、ReverseChargeOrder、ReverseChargeInvoice、CustomsInvoice、CustomsOrder 和 Any。
datestring正文必需此参数定义交易日期。
customerCodestring正文必需此参数指定与交易关联的客户代码。
companyCodestring正文可选此参数指定与交易关联的公司代码。
currencyCodestring正文可选此参数指定与交易关联的货币的三位ISO 4217代码。
commitboolean正文可选此参数指定交易是否应提交。
singleLocation地址对象正文必需此地址指定公司销售发生的位置,以及交易所属的税务管辖区域。如果此地址与公司地址不同,计算出的税额将为零。
1# 账户ID和许可证密钥 2account_id = "{{ACCOUNT_ID}}" 3license_key = "{{LICENSE_KEY}}" 4 5# 接口地址 6endpoint_url = "https://sandbox-rest.avatax.com/api/v2/transactions/create" 7 8# 使用账户ID和许可证密钥创建基础认证令牌 9auth_token = requests.auth.HTTPBasicAuth(account_id, license_key) 10 11# 定义交易详情 12data_obj = { 13 "lines": [ 14 { 15 "number": "1", 16 "quantity": 1, 17 "amount": 1049.99, 18 "taxCode": "PC070110", 19 "itemCode": "{{ITEM_CODE}}", 20 "description": "笔记本电脑" 21 } 22 ], 23 "type": "SalesInvoice", 24 "date": datetime.now().strftime("%Y-%m-%d"), 25 "customerCode": "SampleCustomerCode", 26 "companyCode": "{{COMPANY_CODE}}", 27 "currencyCode": "USD", 28 "commit": True, 29 "addresses": { 30 "singleLocation": { 31 "line1": line1_from_ADDRESS, 32 "city": city_from_ADDRESS, 33 "region": region_from_ADDRESS, 34 "country": country_from_ADDRESS, 35 "postalCode": postalCode_from_ADDRESS 36 } 37 } 38} 39 40# 向AvaTax API发送POST请求 41response = requests.post(url=endpoint_url, auth=auth_token, 42 json=data_obj) 43 44# 打印响应结果 45print_response(response)

响应字段

字段名类型说明
idinteger该字段指定交易的唯一标识ID。
codestring该字段指定交易的唯一代码。
companyIdinteger该字段指定我们Avalara账户的账户ID。
statusstring该字段指定交易的状态。
reconciledboolean该字段指定交易是否已完成对账。
totalAmountfloat该字段指定交易记录的总金额。
totalTaxfloat该字段指定交易记录的总税额。
totalTaxablefloat该字段指定交易总金额中属于应税部分的金额。
totalTaxCalculatedfloat该字段指定交易计算出的总税额。

代码示例

1# 调整交易 2https://sandbox-rest.avatax.com/api/v2/companies/{{companyCode}}/transactions/{{transactionCode}}/adjust 3 4# 创建或调整交易 5https://sandbox-rest.avatax.com/api/v2/transactions/createoradjust

请求参数

参数名类型参数类型分类说明
companyCodestring路径必需此参数指定与交易关联的公司代码。
transactionCodestring路径必需此参数指定交易的唯一代码,便于快速引用和调整。
adjustmentReasonstring正文必需此参数指定调整的原因,用于记录存档。支持的值包括:NotAdjusted、SourcingIssue、ReconciledWithGeneralLedger、ExemptCertApplied、PriceAdjusted、ProductReturned、ProductExchanged、BadDebt、Other 和 Offline。
adjustmentDescriptionstring正文可选此参数指定调整原因的描述信息。
newTransaction交易对象正文必需此参数指定新的调整后交易内容。
1# 账户ID和许可证密钥 2account_id = "{{ACCOUNT_ID}}" 3license_key = "{{LICENSE_KEY}}" 4 5# 交易代码和公司代码 6transaction_code = "{{TRANSACTION_CODE}}" 7company_code = "{{COMPANY_CODE}}" 8 9# 接口地址 10endpoint_url = f"https://sandbox-rest.avatax.com/api/v2/companies/{company_code}/transactions/{transaction_code}/adjust" 11 12# 使用账户ID和许可证密钥创建基础认证令牌 13auth_token = requests.auth.HTTPBasicAuth(account_id, license_key) 14 15# 定义交易详情 16data_obj = { 17 "adjustmentReason": "Other", 18 "adjustmentDescription": "价格录入错误(数字顺序颠倒)", 19 "newTransaction": { 20 "lines": [ 21 { 22 "number": "1", 23 "quantity": 1, 24 "amount": 1199.99, 25 "taxCode": "PC070110", 26 "itemCode": "{{ITEM_CODE}}", 27 "description": "笔记本电脑" 28 } 29 ], 30 "type": "SalesInvoice", 31 "date": datetime.now().strftime("%Y-%m-%d"), 32 "customerCode": "SampleCustomerCode", 33 "companyCode": "{{COMPANY_CODE}}", 34 "currencyCode": "USD", 35 "commit": True, 36 "addresses": { 37 "singleLocation": { 38 "line1": line1_from_ADDRESS, 39 "city": city_from_ADDRESS, 40 "region": region_from_ADDRESS, 41 "country": country_from_ADDRESS, 42 "postalCode": postalCode_from_ADDRESS 43 } 44 } 45 } 46} 47 48# 向AvaTax API发送POST请求 49response = requests.post(url=endpoint_url, auth=auth_token, 50 json=data_obj) 51 52# 打印响应结果 53print_response(response)
...
交易状态图

管理公司和产品信息

结算交易