Closed pikender closed 7 years ago
Taxjar Api allows shipping to be passed for order and not shipments.
Also, I see no provision to add shipping as line_items like Avalara does.
As per my understanding, shipping tax should be stored as shipment adjustments with shipments storing additional_tax_total as value.
The deadlock happens between Taxjar Api and how Spree supports shipping taxes, as we get a consolidated shipping tax value, if applicable, from taxjar api so no easy/direct way to assign to shipments.
It looks from outside that creating a tax adjustment for shipping at order level might solve the issue and better managed as per Spree ecosystem.
Please guide me on better implementation in this regard.
@pikender - We need to add a new adjustment here - https://github.com/spree/spree/blob/master/core/app/models/spree/order.rb#L311 for Order.
Then, We need to modify https://github.com/vinsol-spree-contrib/spree_taxjar/blob/master/app/models/spree/calculator/taxjar_calculator.rb#L18 accordingly.
It's solved by making a Standard Tier Taxjar API request per shipment when compute_shipment
hook for Taxjar Calculator
is called.
So for a Order with N Shipments, N + 1 API calls are made to calculate correct sales tax.
N Standard Tier Taxjar Api Calls for calculating shipment tax and 1 Advanced Tier Taxjar Api Call for calculating line_items tax
Prerequisite
Setup spree_taxjar as instructed in README
Zone Setup
Create a Zone with:
Tax Category Setup
Create a tax category with:
Tax Rate Setup
Create a tax rate with:
Shipping Category Setup
Create a shipping category with:
Shipping Method Setup
Create a shipping category with:
Product Setup
Create or Update an existing product with:
Follow the Checkout with Product having Tax Category as TaxJar
Expected
On Checkout -> Payment Step, Tax calculated should take shipping in account when needed but missing now (Texas is a state which levy tax on shipping)
Analysis
It's found that we are creating tax adjustments for line_items by introspecting
taxjar_response.breakdown.line_items
which is rightly calculating tax on line_item cost and storing in line_item.additional_tax but missing tax applied on shipping which can be further verified based onfreight_taxable
is true/false.Probable Solution
We can create an order adjustment for the shipping tax difference and add and show in Order additional_tax_total.
Though, I will leave the best implementation to the owners as Spree ecosystem should behave well for all cases with the fix 😊
Sample Api Response
Note: Shipping Cost as 0 and 0.2 in below requests