Codex-generated pull request - #2
Conversation
✅ Deploy Preview for newwmss ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7b25e2ff9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { data: atual, error: fetchError } = await supabaseClient | ||
| .from('estoque_area') | ||
| .select('paletes') | ||
| .match({ area, sku, tipo }) | ||
| .maybeSingle(); |
There was a problem hiding this comment.
Make expedition update and log a single atomic operation
This expedition flow does a read (select), then a stock write (update/delete), then a movement insert as separate API calls, so it is not atomic. Under concurrent expeditions for the same area/sku/tipo, both requests can read the same starting balance and overwrite each other, and any failure after the stock write (for example, insert/RLS/network failure on movimentacoes) leaves stock changed without a matching log entry. This should be executed in one database transaction (e.g., via the existing fn_expedir_produto RPC).
Useful? React with 👍 / 👎.
|
|
||
| if (fetchError) throw fetchError; | ||
| if (!atual) throw new Error('Registro não encontrado no estoque.'); | ||
| if (atual.paletes < paletes) throw new Error('Quantidade para expedir maior que o estoque atual.'); |
There was a problem hiding this comment.
Validate expedition quantity as positive before applying stock math
The code only checks atual.paletes < paletes, so tampered inputs like negative quantities can pass this guard and increase stock (novoSaldo = atual - paletes). In that scenario, the subsequent insert can fail on movimentacoes_paletes_ck (paletes > 0), leaving inventory inflated while the UI reports an error. This occurs when client-side HTML min=1 is bypassed, so paletes > 0 must be enforced before any stock update/delete.
Useful? React with 👍 / 👎.
| .from('movimentacoes') | ||
| .select('id, sku, tipo, paletes, created_at') | ||
| .order('created_at', { ascending: false }) |
There was a problem hiding this comment.
Restrict movement history query to expedition operations
The query for the “Histórico de expedição” tab loads all rows from movimentacoes without filtering by operacao. Since the schema explicitly allows ENTRADA and AJUSTE, those records will be shown as expeditions and also included in exported “Totais_Expedido_SKU”, producing incorrect expedition reports whenever non-expedition movements exist.
Useful? React with 👍 / 👎.
Codex generated this pull request, but encountered an unexpected error after generation. This is a placeholder PR message.
Codex Task