Set Sales Tax Value

Questions about and code samples for custom order rules and validation within Select.
Post Reply
Posts: 2
Joined: Thu May 03, 2018 8:44 am

Set Sales Tax Value

Post by swallis » Mon Oct 12, 2020 3:51 pm

In some very specific instances, our company needs to use the property address (not the settlement location or a contact's location) to calculate the sales tax.
I can manually set the value to a fixed number (I have tried this example and it works):

Code: Select all

def SalesTaxInfo_Rate_Value(args):
	info = args.Context
	order = args.Context.Root
	#several conditions to evaluate to determine if the default rule needs an over-write
	args.Value(.07) #example of setting a fixed value
Ideally, I would like to be able to use the city and/or county of the property to pull the correct sales tax percentage from our sales tax table. My question(s) are:
1. Is something like this even possible?
2. Which service(s) (ISalesTax, ISalesTaxEntry, ISalesTaxManager, ISalesTaxInfo) would I need to reference?
3. Is there any sample code that another developer has that can get me going in the right direction?

Thank you in advance for any help!

Posts: 1006
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC

Re: Set Sales Tax Value

Post by BobRichards » Tue Oct 13, 2020 11:52 am

This should get you started. You got the context and property correct for the rule so we will flesh it out a bit.

(1) In this example, we only set sales tax rates for the Settlement Agent contact - we want to make sure other order model locations that use the SalesTaxInfo object are not modified.
(2) Once we determine the contact is OK, we get the city and state for the first property.
(3) Then we get the rate table for the state and (4) filter it for the city.
(4) If the next() function doesn't find the city, then it will set the rate to None and (5) exit without setting the rate.
(6) If it found an entry, it sets the tax rate.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.OrderTracking.Client.SalesTax import *

def SalesTaxInfo_Rate_Value(args):
    context = args.Context
    order = context.Root
    # (1) Exit if not a Settlement Agent contact.
    if (not IOrderItem.HasProperty(context.Parent, 'Code')
        or context.Parent.ContactType != ContactType.SettlementAgent):      
        # Different contact or Settlement Location - ignore it.
    # (2) Base the tax on the first property.
    state = order.Properties[0].Address.State
    city = order.Properties[0].Address.City
    # (3) Get the tax table for our state from ProForm/SalesTax table in SPAdmin.
    salesTaxMgr = args.GetService(ISalesTaxManager)
    rateTable = ISalesTaxManager.GetSalesTax(salesTaxMgr, state)
    rates = rateTable.Rates
    # (4) Search table for city 
    rate = next((t for t in rates 
        if t.Name == city and t.RateType == SalesTaxRateType.City),
    # (5) Rate not found for city. Don't set it.
    if not rate:
    # (6) Set the rate per the table.
    args.Value = rate.Rate
Bob Richards, Software Developer, SoftPro

Posts: 2
Joined: Thu May 03, 2018 8:44 am

Re: Set Sales Tax Value

Post by swallis » Tue Oct 13, 2020 12:12 pm

This is the start that I needed to point me in the right direction. Thank you Bob! :D

Post Reply