SuperAPI AI 工具集

spree-taxes

通用与其它

查看项目

更新于 10-16 04:31

技能介绍

用途:在 Spree 6 中配置或扩展税费。税费由三部分决定:卖什么(产品/变体上的 Spree::TaxCategory,快照到行项目)、送到哪(购买的税地址,默认收货地址,否则账单地址)、谁来算(市场的税提供者,回退到 Spree.default_tax_provider,默认 Spree::TaxProvider::Internal,读取 Spree::TaxRate 记录)。输出统一为购物车/订单上的 Spree::TaxLine,由 RecalculateTotals 汇总为 included_tax_total 与 additional_tax_total。

主要能力:税类别为店铺级,含 name、is_default、tax_code(供外部引擎识别的代码);税率无 zone,用 ISO 国家/州代码定位,amount 为小数(0.2=20%),included_in_price 区分含税价与附加税,可按类别匹配。Internal 提供者声明不支持 us_local_tax、reverse_charge、oss_thresholds、proportional_delivery_tax,超出简单国家/州税率需外部引擎。税提供者需实现 estimate、commit、void、refund、service_tax_rate 及 unsupported_capabilities 等契约,无状态、每次调用新建,凭据放在 Spree::Integration。

使用方式:创建税率示例:Spree::TaxRate.create!(name: 'VAT', amount: 0.20, country_code: 'DE', tax_category: standard, included_in_price: true)。管理 API 为 /api/v3/admin/tax_categories 与 /api/v3/admin/tax_rates。自定义提供者继承 Spree::TaxProvider::Base,注册到 Spree.tax_providers,并可在市场设置 tax_provider。额外数据通过 set_tax_line_context 钩子以 context 传入。B2B 税号(Spree::TaxIdentifier)与免税证书(Spree::TaxExemptionCertificate)有独立解析流程。

限制:已下单订单金额冻结,不会重新估算;手工创建/编辑 TaxLine 会在下次估算被覆盖;commit 必须幂等,否则完成重放会产生重复单据;作业/控制台需设置 Spree::Current.store;内置 eu_vat 校验仅检查格式。Avalara 等引擎以提供者类接入,具体步骤需查阅对应版本文档。