I have a Function that receives a json dataset and creates Sales Orders. One of the steps is to calculate Tax via Avalara, which is done by toggling the ReadyToCalc field and calling a MasterUpdate:
Basically this is the same thing we do in the UI… Checking the box and saving automatically calculates tax; we don’t have to go to Actions → Calculate Tax (although we can).
The code works to set the field to true, but oddly it is only actually calculating Tax on the Sales Order if this chunk of code to add a Misc Charge fires beforehand:
In other words, my code is not currently working if there is no freight charge on the order… Something about that OHOrderMsc MasterUpdate call seems to make it work.
I’ve seen some weird stuff developing in Epicor over the years, but this one has me stumped. I can probably throw in an extra GetByID and/or MasterUpdate to get it working, but am trying to understand the why or if I’m doing something wrong here… I welcome any advice!
You are setting ReadyToCalc == true but your OrderRel table doesn’t have any updated rows (Taxes are added to order releases)
You aren’t calling SalesOrderSvc.SetReadyToCalc(iOrderNum, ref ts), which adds and updated row to the TsSalesOrder.TaxConnectStatus table.
If you had an updated row in your releases (or apparently your OHOrderMsc), it will add the TaxConnectStatus row with RowMod=="U" automatically. Since that isn’t the case, it appears to be skipping that bit.
Lol I can’t believe I forgot the golden rule… when in doubt use BufferCopy. Are you guys just BufferCopy’ing everything by default these days? I feel like I should just start doing that.
Here is the working snippet for anyone interested:
I had tried that too but got the same behavior before fixing issue with BufferCopy. I may still throw that method call in for good measure though.
Still weird that the original code worked if a freight misc charge was added to the order… I’m guessing that MasterUpdate jiggled the dataset in a way that didn’t need BufferCopy to resolve.