Fix Business Unit assignment for inactive workers

This commit is contained in:
2025-07-09 13:45:06 +02:00
parent 3486b4f509
commit 2b8f26e9fe

View File

@@ -20,7 +20,7 @@ latest_positions AS (
FROM {{ source('tap_spreadsheets_anywhere', 'positions') }} FROM {{ source('tap_spreadsheets_anywhere', 'positions') }}
WHERE _sdc_deleted_at IS NULL WHERE _sdc_deleted_at IS NULL
AND primary_position = 'Yes' AND primary_position = 'Yes'
ORDER BY assigned_employee_id, _sdc_received_at DESC, assigned_employee_effective_date ORDER BY assigned_employee_id, _sdc_received_at DESC, assigned_employee_effective_date DESC
), ),
joined_data AS ( joined_data AS (
@@ -60,7 +60,7 @@ joined_data AS (
NULL::INTEGER AS employment_criticality, NULL::INTEGER AS employment_criticality,
NULL::VARCHAR AS employment_probation_status, NULL::VARCHAR AS employment_probation_status,
NULL::DATE AS employment_probation_end_date, NULL::DATE AS employment_probation_end_date,
d.path::ltree AS employment_department_path, COALESCE(d.path::ltree, d2.path::ltree) AS employment_department_path,
NULL::VARCHAR(254) AS email, NULL::VARCHAR(254) AS email,
NULL::DATE AS employment_earliest_retirement_date, NULL::DATE AS employment_earliest_retirement_date,
ROUND(p.fte_utilized_by_employee_in_this_position * 100)::INTEGER AS employment_fte_percentage, ROUND(p.fte_utilized_by_employee_in_this_position * 100)::INTEGER AS employment_fte_percentage,
@@ -76,8 +76,10 @@ joined_data AS (
FROM latest_workers w FROM latest_workers w
LEFT JOIN latest_positions p LEFT JOIN latest_positions p
ON w.user_id = p.assigned_employee_id ON w.user_id = p.assigned_employee_id
LEFT JOIN {{ ref('department') }} d LEFT JOIN {{ ref('department') }} d -- Source = Department from Positions report, only relevant for active workers
ON p.assigned_unit_id = d.department_hris_id ON p.assigned_unit_id = d.department_hris_id
LEFT JOIN {{ ref('department') }} d2 -- Source = Business Unit from All Users report, only relevant for inactive workers
ON w.business_unit = d2.name
) )
SELECT SELECT