agenda: normalizeForMelissa expoe owner_id/tenant_id/contract_id
Bug introduzido pelo watch sync do popover (commit b5e00a7).
Apos o sync com eventos computed, eventoSelecionado.value ficava
com apenas os campos do normalizeForMelissa return. owner_id,
tenant_id, terapeuta_id, billing_contract_id NAO estavam expostos
no normalize -> sumiam apos refresh. onAnteciparPagamento entao
mandava owner_id=null pro RPC create_financial_record_for_session
-> "null value in column owner_id violates not-null constraint".
Fix:
- normalizeForMelissa agora expoe owner_id, tenant_id,
terapeuta_id, billing_contract_id explicitos no return
- onAnteciparPagamento ganhou fallback robusto: ev.owner_id ||
ev._raw?.owner_id || M.ownerId.value, com throw explicito se
nada disponivel (em vez de mandar null pro RPC)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -778,7 +778,13 @@ async function confirmAnteciparPagamento() {
|
||||
anteciparBusy.value = true;
|
||||
try {
|
||||
const tenantId = tenantStore.activeTenantId || tenantStore.tenantId || tenantStore.tenant?.id || null;
|
||||
const ownerId = ev.owner_id || ev.terapeuta_id || null;
|
||||
// ownerId: ev.owner_id é prioridade. Fallback pra M.ownerId (composable
|
||||
// que conhece o user logado). Pra virtuais ou snapshots stale, ev pode
|
||||
// não trazer owner_id; M.ownerId é fonte autoritativa.
|
||||
const ownerId = ev.owner_id || ev.terapeuta_id || ev._raw?.owner_id || M?.ownerId?.value || null;
|
||||
if (!ownerId) {
|
||||
throw new Error('Não foi possível identificar o terapeuta da sessão.');
|
||||
}
|
||||
const settlement = anteciparMethod.value;
|
||||
const amount = Number(ev.price) || 0;
|
||||
const dueIso = ev.inicio_em ? new Date(ev.inicio_em).toISOString().slice(0, 10) : new Date().toISOString().slice(0, 10);
|
||||
|
||||
@@ -145,6 +145,10 @@ function normalizeForMelissa(r, paymentStateMap = null, paymentAmountMap = null,
|
||||
tipo,
|
||||
status: r.status || (isOccurrence ? 'agendado' : ''),
|
||||
titulo: r.titulo || r.titulo_custom || '',
|
||||
owner_id: r.owner_id ?? null,
|
||||
tenant_id: r.tenant_id ?? null,
|
||||
terapeuta_id: r.terapeuta_id ?? null,
|
||||
billing_contract_id: r.billing_contract_id ?? null,
|
||||
patient_id: r.patient_id ?? r.paciente_id ?? null,
|
||||
pacienteNome: pacNome,
|
||||
modalidade: r.modalidade || '',
|
||||
|
||||
Reference in New Issue
Block a user