File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -126,23 +126,29 @@ create table item_venda(
126126CREATE OR REPLACE FUNCTION diminui_estoque_func ()
127127RETURNS trigger AS $$
128128BEGIN
129- update produto set estoque = estoque - new .quant where produto .id = new .produto_id ;
129+ update estoque set quant = quant - new .quant
130+ where produto_id = new .produto_id
131+ and estoque .loja_id = (select v .loja_id from venda v where v .id = new .venda_id );
130132 RETURN NEW;
131133END;
132134$$ LANGUAGE ' plpgsql' ;
133135
134136CREATE OR REPLACE FUNCTION devolve_estoque_func ()
135137RETURNS trigger AS $$
136138BEGIN
137- update produto set estoque = estoque + old .quant where produto .id = old .produto_id ;
139+ update estoque set quant = quant + old .quant
140+ where produto_id = old .produto_id
141+ and estoque .loja_id = (select v .loja_id from venda v where v .id = old .venda_id );
138142 RETURN NEW;
139143END;
140144$$ LANGUAGE ' plpgsql' ;
141145
142146CREATE OR REPLACE FUNCTION atualiza_estoque_func ()
143147RETURNS trigger AS $$
144148BEGIN
145- update produto set estoque = estoque + old .quant - new .quant where produto .id = new .produto_id ;
149+ update estoque set quant = quant + old .quant - new .quant
150+ where produto_id = new .produto_id
151+ and loja_id = (select v .loja_id from venda v where v .id = new .venda_id );
146152 RETURN NEW;
147153END;
148154$$ LANGUAGE ' plpgsql' ;
You can’t perform that action at this time.
0 commit comments