Skip to Content
Menu
This question has been flagged
1 Reply
1048 Views

Odoo online Version 18, does not yet serve the State of Utah locality. Can anyone verify this Python code is correct?

# Utah State Income Tax Withholding Calculation


# Get basic parameters

gross_income = categories.GROSS

pay_periods = payslip.dict.get('pay_periods', 24)  # Default to semi-monthly if not specified

allowances = contract.ut_allowances if hasattr(contract, 'ut_allowances') else 0

filing_status = contract.ut_filing_status if hasattr(contract, 'ut_filing_status') else 'single'


# Calculate annual income estimate

annual_income = gross_income * pay_periods


# Personal exemption and deduction calculation

standard_deduction = 0

if filing_status == 'single' or filing_status == 'married_separate':

    standard_deduction = 14600  # 2025 standard deduction for single filers

elif filing_status == 'married_joint' or filing_status == 'head_household':

    standard_deduction = 29200  # 2025 standard deduction for married filing jointly


# Calculate taxable income

taxable_income = max(0, annual_income - standard_deduction - (allowances * 4590))


# Utah uses a flat tax rate of 4.65% (as of 2025)

annual_tax = taxable_income * 0.0465


# Convert annual tax to per-paycheck withholding

result = annual_tax / pay_periods


# Ensure the result is not negative

result = max(0, result)

Avatar
Discard
Author Best Answer

The above code is wrong and generates errors. The fix I found to work is to 1.) Ensure Utah WIthholding Salary Rule follows sequentially the Gross Salary calculation, then 2.) Insert the following python script (check for correct indentation, etc.):

# Get basic parameters
gross_income = categories['GROSS']

# Determine pay frequency from the payslip structure
if payslip.struct_id.schedule_pay == 'monthly':
    pay_periods = 12
elif payslip.struct_id.schedule_pay == 'semi-monthly':
    pay_periods = 24
elif payslip.struct_id.schedule_pay == 'bi-weekly':
    pay_periods = 26
elif payslip.struct_id.schedule_pay == 'weekly':
    pay_periods = 52
else:
    pay_periods = 24  # Default to semi-monthly

# Try to get the values, default if not available
try:
    allowances = contract.ut_allowances
except:
    allowances = 0

try:
    filing_status = contract.ut_filing_status
except:
    filing_status = 'single'

# Calculate annual income estimate
annual_income = gross_income * pay_periods

# Personal exemption and deduction calculation
standard_deduction = 0
if filing_status == 'single' or filing_status == 'married_separate':
    standard_deduction = 14600  # 2025 standard deduction for single filers
elif filing_status == 'married_joint' or filing_status == 'head_household':
    standard_deduction = 29200  # 2025 standard deduction for married filing jointly

# Calculate taxable income
taxable_income = max(0, annual_income - standard_deduction - (allowances * 4590))

# Utah uses a flat tax rate of 4.65% (as of 2025)
annual_tax = taxable_income * 0.0465

# Convert annual tax to per-paycheck withholding
result = annual_tax / pay_periods

# Ensure the result is not negative
result = max(0, result)

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
860
0
Feb 25
1228
1
Dec 24
1754
0
Nov 24
108
1
Jul 24
5208