fix: conversão de tipo no PostgreSQL e correção de erro 400 Bad Request ao importar peças em lote via XLS
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE FUNCTION "TS_ERP".sync_of_data()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
BEGIN
|
||||
-- Atualizar dados na tabela ordens_fabricacao quando ficha_tecnica_contratos for alterada
|
||||
IF TG_TABLE_NAME = 'ficha_tecnica_contratos' THEN
|
||||
UPDATE "TS_ERP".ordens_fabricacao
|
||||
SET
|
||||
gestor = NEW.gestor,
|
||||
data_termino_prev = NEW.data_termino_prev,
|
||||
peso_total = NEW.quantidade,
|
||||
descritivo = NEW.descricao_resumida
|
||||
WHERE num_of = NEW.of_number;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;
|
||||
@@ -488,7 +488,7 @@ const CadastroOF = () => {
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="quantidade" className="text-sm font-medium text-muted-foreground">Quantidade (t)</Label>
|
||||
<Label htmlFor="quantidade" className="text-sm font-medium text-muted-foreground">Quantidade (kg)</Label>
|
||||
<Input
|
||||
id="quantidade"
|
||||
type="number"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Change pecas.peso_unitario to numeric(10,3)
|
||||
ALTER TABLE "TS_ERP".pecas ALTER COLUMN peso_unitario TYPE numeric(10,3);
|
||||
|
||||
-- Fix the sync_of_data function to explicitly refer to TS_ERP.ordens_fabricacao
|
||||
CREATE OR REPLACE FUNCTION "TS_ERP".sync_of_data()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
BEGIN
|
||||
-- Atualizar dados na tabela ordens_fabricacao quando ficha_tecnica_contratos for alterada
|
||||
IF TG_TABLE_NAME = 'ficha_tecnica_contratos' THEN
|
||||
UPDATE "TS_ERP".ordens_fabricacao
|
||||
SET
|
||||
gestor = NEW.gestor,
|
||||
data_termino_prev = NEW.data_termino_prev,
|
||||
peso_total = NEW.quantidade,
|
||||
descritivo = NEW.descricao_resumida
|
||||
WHERE num_of = NEW.of_number;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;
|
||||
@@ -0,0 +1,32 @@
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const fs = require('fs');
|
||||
const envContent = fs.readFileSync('.env', 'utf8');
|
||||
const supabaseUrl = envContent.match(/VITE_SUPABASE_URL=\"(.*?)\"/)[1];
|
||||
const supabaseKey = envContent.match(/VITE_SUPABASE_PUBLISHABLE_KEY=\"(.*?)\"/)[1];
|
||||
const supabase = createClient(supabaseUrl, supabaseKey, { db: { schema: 'TS_ERP' } });
|
||||
|
||||
async function run() {
|
||||
const pecasParaInserir = [{
|
||||
of_number: 'B133',
|
||||
etapa_fase: '1',
|
||||
marca: 'M2',
|
||||
descricao: 'Desc M2',
|
||||
quantidade: 1,
|
||||
peso_unitario: 10.5,
|
||||
peso_total: 10.5,
|
||||
tratamento_superficial: 'pintura',
|
||||
material: 'A36',
|
||||
perfil_principal: 'C',
|
||||
tem_componentes: false,
|
||||
user_id: '00000000-0000-0000-0000-000000000000',
|
||||
prioridade: 'P4'
|
||||
}];
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('pecas')
|
||||
.insert(pecasParaInserir)
|
||||
.select('id, of_number, etapa_fase, marca');
|
||||
|
||||
console.log('Result:', JSON.stringify({ data, error }, null, 2));
|
||||
}
|
||||
run();
|
||||
@@ -0,0 +1,32 @@
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const fs = require('fs');
|
||||
const envContent = fs.readFileSync('.env', 'utf8');
|
||||
const supabaseUrl = envContent.match(/VITE_SUPABASE_URL=\"(.*?)\"/)[1];
|
||||
const supabaseKey = envContent.match(/VITE_SUPABASE_PUBLISHABLE_KEY=\"(.*?)\"/)[1];
|
||||
const supabase = createClient(supabaseUrl, supabaseKey, { db: { schema: 'TS_ERP' } });
|
||||
|
||||
async function run() {
|
||||
const pecasParaInserir = [{
|
||||
of_number: 'B133',
|
||||
etapa_fase: '1',
|
||||
marca: 'M1',
|
||||
descricao: 'Desc M1',
|
||||
quantidade: 1,
|
||||
peso_unitario: 10,
|
||||
peso_total: 10,
|
||||
tratamento_superficial: 'pintura',
|
||||
material: 'A36',
|
||||
perfil_principal: 'C',
|
||||
tem_componentes: false,
|
||||
user_id: '00000000-0000-0000-0000-000000000000', // invalid uuid? maybe this fails?
|
||||
prioridade: 'P4'
|
||||
}];
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('pecas')
|
||||
.insert(pecasParaInserir)
|
||||
.select('id, of_number, etapa_fase, marca');
|
||||
|
||||
console.log('Result:', JSON.stringify({ data, error }, null, 2));
|
||||
}
|
||||
run();
|
||||
@@ -0,0 +1,25 @@
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const fs = require('fs');
|
||||
const envContent = fs.readFileSync('.env', 'utf8');
|
||||
const supabaseUrl = envContent.match(/VITE_SUPABASE_URL=\"(.*?)\"/)[1];
|
||||
const supabaseKey = envContent.match(/VITE_SUPABASE_PUBLISHABLE_KEY=\"(.*?)\"/)[1];
|
||||
const supabase = createClient(supabaseUrl, supabaseKey, { db: { schema: 'TS_ERP' } });
|
||||
|
||||
async function run() {
|
||||
const { data: existingFicha } = await supabase
|
||||
.from('ficha_tecnica_contratos')
|
||||
.select('id')
|
||||
.eq('of_number', 'B133')
|
||||
.maybeSingle();
|
||||
|
||||
if (existingFicha) {
|
||||
const { data, error } = await supabase
|
||||
.from('ficha_tecnica_contratos')
|
||||
.update({ quantidade: 2 })
|
||||
.eq('id', existingFicha.id);
|
||||
console.log('Update result:', { data, error });
|
||||
} else {
|
||||
console.log('No ficha found for B133');
|
||||
}
|
||||
}
|
||||
run();
|
||||
Reference in New Issue
Block a user