Closed mildlygeeky closed 5 years ago
Hi @mildlygeeky - I guess I thought that discounts needed their own discount-specific code but that test case you sent over definitely shows line item discounts need to be handled differently especially when tax exemptions are in the mix.
Let me do some testing and maybe verify with Avalara the right way to send those line item discounts.
thanks for looking @imagehat — taking a look at https://developer.avalara.com/avatax/dev-guide/discounts-and-overrides/discounts/ and looking at "Negative Amount Line Items" (the way you are sending them over), you can see that the Expected API Call shows that the Tax Codes are expected to match between a taxable line item and its discount adjustment.
From their instructions (emphasis mine):
With this, exercise, you will simply add an additional line that contains the discounted amount as a negative extended amount. Please ensure to use the same taxCode on the discount line as the item being discounted. This will ensure that any taxability rules applied to the product/service are also applied to the discount.
Without the tax codes matching, Avalara just assumes that any/all tax code line items are subject to the discount, and can result in some pretty odd results (for us, we had negative sales tax being calculated for a low-priced item that was in the same order as a discounted high-price item that was sales tax exempt).
I would even say that their note on how they think about discounts should probably negate the need for the defaultDiscountCode
setting — rather, discounts should default to the defaultTaxCode
, and then use the new code in this PR to override on a per-lineItem basis as needed.
Hey @imagehat / @siffring — any ETA on when this fix could be integrated? I don't mean to be a pest, only that we have a site going live with this plugin on May 15, and just want to figure out if I will be able to use this fix as part of your plugin, or if I should do a fork.
@mildlygeeky - No worries. I'm just checking with Avalara since we specifically went over discounts as part of their certification process. Their main stipulation was that a store owner could set their own discount code, but I think the way you're seeing as just matching either the default or line item tax codes makes more sense.
I'd say we're aiming to get an answer and test your patch early next week at the latest.
Hey @imagehat - any chance this could be pushed to a dev branch while it goes through internal testing? That way I could point to it with composer while it goes through validation with Avalara. Thanks!
@mildlygeeky - For now I've pushed this pr into a new dev-discounts branch. I think you should be able to grab it with composer require surprisehighway/craft-avatax:dev-discounts
.
The Avalara folks laid out several discount scenarios I'm hoping to get to spend some time digesting and getting implemented in the next few days (along with a couple other bugfixes).
Would appreciate you checking to make sure that my logic is sound, but we were running into an issue where discounts for a specific line item were being applied always with the default discount code, though our line items were using the Avatax Tax Code override field.
This checks a discount adjustment to see if it applies to a specific line item, and if so checks that Product to see if there is an Avatax tax code override — if so, then that will be the discountCode used.