feat(ucepsa): add validated canonical context arbitration shadow

This commit is contained in:
Victor Fraile Garcia 2026-07-20 13:58:01 +02:00
parent f9095e6a7b
commit 2efcb750a3

View File

@ -170,9 +170,10 @@ shopfloor AS (
p.productive_context, p.productive_context,
'mv_loss_intelligence.odoo_shopfloor_sessions'::text 'mv_loss_intelligence.odoo_shopfloor_sessions'::text
AS source_table, AS source_table,
s.shopfloor_session_id::text s.context_session_id::text
AS source_native_id, AS source_native_id,
s.shopfloor_session_id, s.context_session_id
AS shopfloor_session_id,
NULL::bigint NULL::bigint
AS production_context_session_id, AS production_context_session_id,
s.effective_from s.effective_from
@ -600,13 +601,10 @@ segments AS (
), ),
candidate_matches AS ( candidate_matches AS (
SELECT SELECT
s.tenant, c.*,
s.site,
s.machine_id,
s.activity_island_id, s.activity_island_id,
s.segment_from, s.segment_from,
s.segment_to, s.segment_to
c.*
FROM segments s FROM segments s
JOIN candidates c JOIN candidates c
ON c.tenant = s.tenant ON c.tenant = s.tenant
@ -1281,13 +1279,20 @@ enriched AS (
AS canonical_product_id, AS canonical_product_id,
p.product_name p.product_name
AS canonical_product_name, AS canonical_product_name,
p.operator_employee_id, p.operator_employee_id
p.operator_name, AS canonical_operator_employee_id,
p.operator_candidate_employee_id, p.operator_name
p.operator_candidate_name, AS canonical_operator_name,
p.operator_confirmation_status, p.operator_candidate_employee_id
p.quantity_confirmation_status, AS canonical_operator_candidate_employee_id,
p.operator_candidate_name
AS canonical_operator_candidate_name,
p.operator_confirmation_status
AS canonical_operator_confirmation_status,
p.quantity_confirmation_status
AS canonical_quantity_confirmation_status,
p.individual_attribution_eligible p.individual_attribution_eligible
AS canonical_individual_attribution_eligible
FROM machines m FROM machines m
LEFT JOIN active_summary s LEFT JOIN active_summary s
ON s.tenant = m.tenant ON s.tenant = m.tenant
@ -1459,38 +1464,38 @@ SELECT
END AS canonical_product_name, END AS canonical_product_name,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.operator_employee_id THEN a.canonical_operator_employee_id
ELSE NULL::bigint ELSE NULL::bigint
END AS operator_employee_id, END AS operator_employee_id,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.operator_name THEN a.canonical_operator_name
ELSE NULL::text ELSE NULL::text
END AS operator_name, END AS operator_name,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.operator_candidate_employee_id THEN a.canonical_operator_candidate_employee_id
ELSE NULL::bigint ELSE NULL::bigint
END AS operator_candidate_employee_id, END AS operator_candidate_employee_id,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.operator_candidate_name THEN a.canonical_operator_candidate_name
ELSE NULL::text ELSE NULL::text
END AS operator_candidate_name, END AS operator_candidate_name,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.operator_confirmation_status THEN a.canonical_operator_confirmation_status
ELSE NULL::text ELSE NULL::text
END AS operator_confirmation_status, END AS operator_confirmation_status,
CASE CASE
WHEN a.authoritative_candidate_count = 1 WHEN a.authoritative_candidate_count = 1
THEN a.quantity_confirmation_status THEN a.canonical_quantity_confirmation_status
ELSE NULL::text ELSE NULL::text
END AS quantity_confirmation_status, END AS quantity_confirmation_status,
( (
a.authoritative_candidate_count = 1 a.authoritative_candidate_count = 1
AND COALESCE( AND COALESCE(
a.individual_attribution_eligible, a.canonical_individual_attribution_eligible,
false false
) )
) AS individual_attribution_eligible, ) AS individual_attribution_eligible,