Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HR data ingest #593

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

HR data ingest #593

wants to merge 5 commits into from

Conversation

SamDudley
Copy link
Contributor

No description provided.

Comment on lines 75 to 81
def hr_row_to_employee(hr_row: HrRow) -> Employee:
employee = Employee()
employee_fields = vars(employee)
matching_fields = [field for field in hr_row._fields if field in employee_fields]
for field in matching_fields:
setattr(employee, field, getattr(hr_row, field))
return employee
Copy link
Contributor Author

@SamDudley SamDudley Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vars is the wrong approach as it returns all the underlying class attributes and we wouldn't want a field to match on accident.

in django you can get the fields of a model through the Model._meta.get_fields() API
https://docs.djangoproject.com/en/5.1/ref/models/meta/#retrieving-all-field-instances-of-a-model

however, in this case I think we should avoid iteration for the following reasons:

  • binds the HrRow field names closely to the Employee fieldnames (this isn't that bad)
  • no opportunity to validate/parse/convert the values
  • all fields will be attempted where an explicit list of which to update is safer if the csv data/model changes

i think the better approach would be to build up the Employee model in a procedural way and validate data as we go along

emp = Employee()
# no need to worry about the field names not matching
emp.cost_centre_id = row.cost_centre_code
# now we can validate the data
emp.fte = float(row.fte)
...

payroll/services/ingest.py Outdated Show resolved Hide resolved
payroll/services/ingest.py Show resolved Hide resolved
payroll/services/ingest.py Outdated Show resolved Hide resolved
payroll/services/ingest.py Show resolved Hide resolved
payroll/services/ingest.py Outdated Show resolved Hide resolved
payroll/services/ingest.py Outdated Show resolved Hide resolved
payroll/services/ingest.py Show resolved Hide resolved
@SamDudley
Copy link
Contributor Author

Great work on this! Let's chat about my comments offline :)

sam has made a mess of the code, sorry! haha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants