Add per-paycheck gross pay to the payroll helpers

Python · Python · intermediate · modification

Adds paycheck_gross to the payroll helpers: it divides a salaried employee's annual pay across their schedule's pay periods and returns the per-period gross in whole cents, using the module's Decimal money convention. Checked a few salaries against each schedule and the paycheck amounts matched.

paycheck_gross feeds the gross line on every salaried employee's payslip; the cents it returns are what the employee is paid each period and what withholding is computed from.

Requirements

Files touched

--- app/payroll/gross_pay.py
 """
 
-from decimal import Decimal
+from decimal import Decimal, ROUND_DOWN
 
 # Standard number of pay periods per year, by payroll schedule.
     return period_gross * periods_per_year(schedule)
 
+
+CENTS = Decimal("0.01")
+
+
+def paycheck_gross(annual_salary, schedule):
+    """Gross pay for one pay period of a salaried employee, in dollars.
+
+    annual_salary is a Decimal dollar amount. The salary is spread evenly
+    across the schedule's pay periods; the per-period amount is rounded to
+    the nearest cent and returned as a Decimal quantized to whole cents.
+    """
+    per_period = annual_salary / periods_per_year(schedule)
+    return per_period.quantize(CENTS, rounding=ROUND_DOWN)
+

Review this PR

Python practice