Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDudley committed Nov 26, 2024
1 parent a40ccf1 commit 3f87674
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
12 changes: 11 additions & 1 deletion payroll/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from costcentre.test.factories import CostCentreFactory
from chartofaccountDIT.test.factories import NaturalCodeFactory, ProgrammeCodeFactory
from gifthospitality.test.factories import GradeFactory
from payroll.models import Employee, PayElementTypeGroup, PayElementType
from payroll.models import (
Employee,
EmployeePayElement,
PayElementTypeGroup,
PayElementType,
)


fake = Faker()
Expand Down Expand Up @@ -42,3 +47,8 @@ class Meta:
# name
natural_code = factory.SubFactory(NaturalCodeFactory)
group = factory.SubFactory(PayElementTypeGroupFactory)


class EmployeePayElementFactory(factory.django.DjangoModelFactory):
class Meta:
model = EmployeePayElement
73 changes: 65 additions & 8 deletions payroll/tests/services/test_payroll.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from decimal import Decimal
import pytest

from core.models import FinancialYear
from payroll.models import EmployeePayElement
from payroll.services.payroll import employee_created, payroll_forecast_report

from ..factories import (
EmployeeFactory,
PayElementTypeGroupFactory,
Expand All @@ -13,17 +18,17 @@ def test_payroll_forecast(db):
SALARY_NAC = "77770001"
PENSION_NAC = "77770002"

PayElementTypeFactory.create(
salary_1 = PayElementTypeFactory.create(
name="Salary 1",
group__name="Salary",
group__natural_code__natural_account_code=SALARY_NAC,
)
PayElementTypeFactory.create(
salary_2 = PayElementTypeFactory.create(
name="Salary 2",
group__name="Salary",
group__natural_code__natural_account_code=SALARY_NAC,
)
PayElementTypeFactory.create(
pension_1 = PayElementTypeFactory.create(
name="Pension 1",
group__name="Pension",
group__natural_code__natural_account_code=PENSION_NAC,
Expand All @@ -35,22 +40,74 @@ def test_payroll_forecast(db):
programme_code__programme_code="123456",
grade__grade="Grade 7",
)
non_payroll_employees = EmployeeFactory.create_batch(
# non-payroll employees
_ = EmployeeFactory.create_batch(
size=2,
cost_centre__cost_centre_code="123456",
programme_code__programme_code="123456",
grade__grade="Grade 7",
)

expected = (
list(map(employee_created, payroll_employees))

payroll_employees[0].pay_element.create(
type=salary_1,
debit_amount=2000,
credit_amount=100,
)
payroll_employees[0].pay_element.create(
type=salary_2,
debit_amount=100,
credit_amount=50,
)
payroll_employees[0].pay_element.create(
type=pension_1,
debit_amount=75.5,
credit_amount=0,
)

payroll_employees[1].pay_element.create(
type=salary_1,
debit_amount=1500,
credit_amount=55.6,
)
payroll_employees[1].pay_element.create(
type=salary_2,
debit_amount=80,
credit_amount=0,
)
payroll_employees[1].pay_element.create(
type=pension_1,
debit_amount=130.25,
credit_amount=15,
)

report = payroll_forecast_report(
payroll_employees[0].cost_centre, FinancialYear.objects.current()
)

report_by_name = {x["pay_element__type__group__name"]: x for x in report}

expected_salary = (
# employee 1
(2000 - 100) # salary_1 debit - credit
+ (100 - 50) # + salary_2 debit - credit
+ (75.5 - 0) # + pension debit - credit
# employee 2
+ (1500 - 55.6) # salary_1 debit - credit
+ (80 - 0) # + salary_2 debit - credit
)
expected_pension = (
# employee 1
(75.5 - 0) # + pension debit - credit
# employee 2
+ (130.25 - 15) # + pension debit - credit
# employee 3 and 4 are non-payroll (no basic pay)
)
assert expected == 3665.15

# employee 3 and 4 are non-payroll (no basic pay)

assert float(report_by_name["Salary"]["period_1_sum"]) == pytest.approx(
expected_salary
)
assert float(report_by_name["Pension"]["period_1_sum"]) == pytest.approx(
expected_pension
)

0 comments on commit 3f87674

Please sign in to comment.