导入
交易创建与生命周期
学习如何使用AvaTax API创建税务交易,并理解不同的交易状态。
...
代码示例
1https://sandbox-rest.avatax.com/api/v2/transactions/create
请求参数
| 参数名 | 类型 | 参数类型 | 分类 | 说明 |
|---|---|---|---|---|
| $include | string | 查询 | 可选 | 此参数指定我们希望 API 在交易创建请求的响应中包含的对象。 |
| code | string | 正文 | 可选 | 此参数指定交易的唯一代码,便于快速引用、更新或对账。 |
| lines | item对象数组 | 正文 | 必需 | 此参数列出交易中的明细项目。 |
| type | string | 正文 | 可选 | 此参数指定交易类型。发票为永久性交易,订单为用于估算的临时交易。支持的值包括:SalesOrder、SalesInvoice、PurchaseOrder、PurchaseInvoice、ReturnOrder、ReturnInvoice、InventoryTransferOrder、InventoryTransferInvoice、ReverseChargeOrder、ReverseChargeInvoice、CustomsInvoice、CustomsOrder 和 Any。 |
| date | string | 正文 | 必需 | 此参数定义交易日期。 |
| customerCode | string | 正文 | 必需 | 此参数指定与交易关联的客户代码。 |
| companyCode | string | 正文 | 可选 | 此参数指定与交易关联的公司代码。 |
| currencyCode | string | 正文 | 可选 | 此参数指定与交易关联的货币的三位ISO 4217代码。 |
| commit | boolean | 正文 | 可选 | 此参数指定交易是否应提交。 |
| 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)
响应字段
| 字段名 | 类型 | 说明 |
|---|---|---|
| id | integer | 该字段指定交易的唯一标识ID。 |
| code | string | 该字段指定交易的唯一代码。 |
| companyId | integer | 该字段指定我们Avalara账户的账户ID。 |
| status | string | 该字段指定交易的状态。 |
| reconciled | boolean | 该字段指定交易是否已完成对账。 |
| totalAmount | float | 该字段指定交易记录的总金额。 |
| totalTax | float | 该字段指定交易记录的总税额。 |
| totalTaxable | float | 该字段指定交易总金额中属于应税部分的金额。 |
| totalTaxCalculated | float | 该字段指定交易计算出的总税额。 |
代码示例
1# 调整交易 2https://sandbox-rest.avatax.com/api/v2/companies/{{companyCode}}/transactions/{{transactionCode}}/adjust 3 4# 创建或调整交易 5https://sandbox-rest.avatax.com/api/v2/transactions/createoradjust
请求参数
| 参数名 | 类型 | 参数类型 | 分类 | 说明 |
|---|---|---|---|---|
| companyCode | string | 路径 | 必需 | 此参数指定与交易关联的公司代码。 |
| transactionCode | string | 路径 | 必需 | 此参数指定交易的唯一代码,便于快速引用和调整。 |
| adjustmentReason | string | 正文 | 必需 | 此参数指定调整的原因,用于记录存档。支持的值包括:NotAdjusted、SourcingIssue、ReconciledWithGeneralLedger、ExemptCertApplied、PriceAdjusted、ProductReturned、ProductExchanged、BadDebt、Other 和 Offline。 |
| adjustmentDescription | string | 正文 | 可选 | 此参数指定调整原因的描述信息。 |
| 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)
...
交易状态图