@flowselections/floriday-voorraad 1.0.105 → 1.0.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/voorraad/ArtikelWizard.d.ts.map +1 -1
- package/dist-lib/components/voorraad/ArtikelWizard.js +3 -2
- package/dist-lib/components/voorraad/FloridayLoadCarriers.d.ts +9 -0
- package/dist-lib/components/voorraad/FloridayLoadCarriers.d.ts.map +1 -0
- package/dist-lib/components/voorraad/FloridayLoadCarriers.js +60 -0
- package/dist-lib/components/voorraad/FustenPage.d.ts.map +1 -1
- package/dist-lib/components/voorraad/FustenPage.js +14 -6
- package/dist-lib/components/voorraad/NieuwArtikelPage.d.ts.map +1 -1
- package/dist-lib/components/voorraad/NieuwArtikelPage.js +7 -6
- package/dist-lib/components/voorraad/StockBulkButtons.d.ts.map +1 -1
- package/dist-lib/components/voorraad/StockBulkButtons.js +3 -6
- package/dist-lib/components/voorraad/StockSyncStatus.d.ts.map +1 -1
- package/dist-lib/components/voorraad/StockSyncStatus.js +10 -2
- package/dist-lib/components/voorraad/VoorraadStockCard.d.ts.map +1 -1
- package/dist-lib/components/voorraad/VoorraadStockCard.js +6 -4
- package/dist-lib/components/voorraad/VoorraadTable.d.ts.map +1 -1
- package/dist-lib/components/voorraad/VoorraadTable.js +6 -1
- package/dist-lib/hooks/useFloridayWriteMode.d.ts +7 -0
- package/dist-lib/hooks/useFloridayWriteMode.d.ts.map +1 -0
- package/dist-lib/hooks/useFloridayWriteMode.js +21 -0
- package/dist-lib/hooks/useStockSyncHealth.d.ts +9 -0
- package/dist-lib/hooks/useStockSyncHealth.d.ts.map +1 -1
- package/dist-lib/hooks/useStockSyncHealth.js +23 -0
- package/dist-lib/hooks/useTradeItemStock.d.ts.map +1 -1
- package/dist-lib/hooks/useTradeItemStock.js +19 -9
- package/dist-lib/integrations/supabase/types.d.ts +1495 -179
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/__tests__/floriday-write-mode.test.d.ts +2 -0
- package/dist-lib/lib/__tests__/floriday-write-mode.test.d.ts.map +1 -0
- package/dist-lib/lib/__tests__/floriday-write-mode.test.js +40 -0
- package/dist-lib/lib/floriday-write-mode.d.ts +21 -0
- package/dist-lib/lib/floriday-write-mode.d.ts.map +1 -0
- package/dist-lib/lib/floriday-write-mode.js +40 -0
- package/dist-lib/lib/fusten.d.ts +20 -0
- package/dist-lib/lib/fusten.d.ts.map +1 -1
- package/dist-lib/lib/fusten.js +48 -41
- package/dist-lib/lib/stock-scope.d.ts +3 -1
- package/dist-lib/lib/stock-scope.d.ts.map +1 -1
- package/dist-lib/lib/stock-scope.js +3 -1
- package/package.json +1 -1
- package/sql/AGENTS.md +2 -8
- package/sql/floriday-voorraad-schema.sql +190 -68
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
-- @flowselections/floriday-voorraad 1.0.
|
|
1
|
+
-- @flowselections/floriday-voorraad 1.0.107 – volledig schema (idempotent, geen gegevens).
|
|
2
2
|
-- Gegenereerd uit de database met scripts/generate-voorraad-schema.py. Niet met de hand wijzigen.
|
|
3
3
|
-- Volgorde 20. Ontbrekende tabellen van andere modules worden overgeslagen met een NOTICE; draai opnieuw na die module.
|
|
4
4
|
-- De statuscontrole van floriday_continuous_stock_queue is van Voorraad en wordt hier opnieuw gemaakt.
|
|
@@ -526,6 +526,13 @@ ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS sort_order in
|
|
|
526
526
|
ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL;
|
|
527
527
|
ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL;
|
|
528
528
|
|
|
529
|
+
-- voorraad_local_context
|
|
530
|
+
CREATE TABLE IF NOT EXISTS public.voorraad_local_context ();
|
|
531
|
+
ALTER TABLE public.voorraad_local_context ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL;
|
|
532
|
+
ALTER TABLE public.voorraad_local_context ADD COLUMN IF NOT EXISTS singleton boolean DEFAULT true NOT NULL;
|
|
533
|
+
ALTER TABLE public.voorraad_local_context ADD COLUMN IF NOT EXISTS created_by uuid;
|
|
534
|
+
ALTER TABLE public.voorraad_local_context ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL;
|
|
535
|
+
|
|
529
536
|
-- voorraad_logistics_event_log
|
|
530
537
|
CREATE TABLE IF NOT EXISTS public.voorraad_logistics_event_log ();
|
|
531
538
|
ALTER TABLE public.voorraad_logistics_event_log ADD COLUMN IF NOT EXISTS event_id uuid NOT NULL;
|
|
@@ -751,7 +758,7 @@ DECLARE
|
|
|
751
758
|
BEGIN
|
|
752
759
|
PERFORM public.voorraad_vereis('ingelogd', 'apply_stock_consumption');
|
|
753
760
|
IF p_trade_item_key IS NULL OR COALESCE(p_qty,0) <= 0 THEN RETURN; END IF;
|
|
754
|
-
SELECT * INTO v_ctx FROM public.
|
|
761
|
+
SELECT * INTO v_ctx FROM public.get_stock_context(true);
|
|
755
762
|
v_key := public.ensure_trade_item_stock_row_key(p_trade_item_key);
|
|
756
763
|
IF v_ctx.connection_id IS NULL OR v_key IS NULL THEN
|
|
757
764
|
INSERT INTO public.stock_mutation_log(trade_item_key, order_id, order_item_id, order_source, mutation_type, qty_delta, reason, created_by)
|
|
@@ -2478,7 +2485,7 @@ BEGIN
|
|
|
2478
2485
|
END IF;
|
|
2479
2486
|
|
|
2480
2487
|
-- Alleen voor het aanmaken van een nieuwe rij is een actieve koppeling vereist.
|
|
2481
|
-
SELECT * INTO v_ctx FROM public.
|
|
2488
|
+
SELECT * INTO v_ctx FROM public.get_stock_context(true);
|
|
2482
2489
|
IF v_ctx.connection_id IS NULL OR v_ctx.user_id IS NULL THEN
|
|
2483
2490
|
RETURN NULL;
|
|
2484
2491
|
END IF;
|
|
@@ -2498,6 +2505,28 @@ $function$
|
|
|
2498
2505
|
REVOKE ALL ON FUNCTION ensure_trade_item_stock_row_key(text) FROM PUBLIC;
|
|
2499
2506
|
REVOKE ALL ON FUNCTION ensure_trade_item_stock_row_key(text) FROM anon;
|
|
2500
2507
|
GRANT EXECUTE ON FUNCTION ensure_trade_item_stock_row_key(text) TO service_role;
|
|
2508
|
+
CREATE OR REPLACE FUNCTION public.ensure_voorraad_local_context()
|
|
2509
|
+
RETURNS uuid
|
|
2510
|
+
LANGUAGE plpgsql
|
|
2511
|
+
SECURITY DEFINER
|
|
2512
|
+
SET search_path TO 'public'
|
|
2513
|
+
AS $function$
|
|
2514
|
+
DECLARE v_id uuid;
|
|
2515
|
+
BEGIN
|
|
2516
|
+
PERFORM public.voorraad_vereis('ingelogd', 'ensure_voorraad_local_context');
|
|
2517
|
+
INSERT INTO public.voorraad_local_context(singleton, created_by) VALUES (true, auth.uid())
|
|
2518
|
+
ON CONFLICT (singleton) DO NOTHING;
|
|
2519
|
+
SELECT id INTO v_id FROM public.voorraad_local_context WHERE singleton;
|
|
2520
|
+
IF EXISTS (SELECT 1 FROM public.floriday_connections c WHERE c.id = v_id) THEN
|
|
2521
|
+
RAISE EXCEPTION 'De lokale voorraadcontext botst met een Floriday-koppeling' USING ERRCODE = 'VR003';
|
|
2522
|
+
END IF;
|
|
2523
|
+
RETURN v_id;
|
|
2524
|
+
END $function$
|
|
2525
|
+
;
|
|
2526
|
+
REVOKE ALL ON FUNCTION ensure_voorraad_local_context() FROM PUBLIC;
|
|
2527
|
+
REVOKE ALL ON FUNCTION ensure_voorraad_local_context() FROM anon;
|
|
2528
|
+
GRANT EXECUTE ON FUNCTION ensure_voorraad_local_context() TO authenticated;
|
|
2529
|
+
GRANT EXECUTE ON FUNCTION ensure_voorraad_local_context() TO service_role;
|
|
2501
2530
|
CREATE OR REPLACE FUNCTION public.fcsq_block_disabled()
|
|
2502
2531
|
RETURNS trigger
|
|
2503
2532
|
LANGUAGE plpgsql
|
|
@@ -4150,22 +4179,15 @@ CREATE OR REPLACE FUNCTION public.get_product_stock(p_product_id uuid)
|
|
|
4150
4179
|
AS $function$
|
|
4151
4180
|
#variable_conflict use_column
|
|
4152
4181
|
DECLARE
|
|
4153
|
-
v_connection_id uuid; v_key text; v_product_key text; v_floriday_key text;
|
|
4182
|
+
v_ctx record; v_connection_id uuid; v_key text; v_product_key text; v_floriday_key text;
|
|
4154
4183
|
BEGIN
|
|
4155
4184
|
PERFORM public.voorraad_vereis('ingelogd', 'get_product_stock');
|
|
4156
4185
|
IF auth.uid() IS NULL AND NOT public.voorraad_is_server() THEN RAISE EXCEPTION 'Niet ingelogd' USING ERRCODE = '42501'; END IF;
|
|
4157
4186
|
SELECT NULLIF(trim(COALESCE(p.floriday_trade_item_id, '')), ''), NULLIF(trim(COALESCE(p.trade_item_key, '')), '')
|
|
4158
4187
|
INTO v_floriday_key, v_product_key FROM public.products p WHERE p.id = p_product_id;
|
|
4159
4188
|
v_key := COALESCE(v_floriday_key, v_product_key, 'product:' || p_product_id::text);
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
WHERE s.trade_item_key IN (v_key, v_floriday_key, v_product_key, 'product:' || p_product_id::text, p_product_id::text)
|
|
4163
|
-
ORDER BY CASE WHEN s.trade_item_key = v_key THEN 0 ELSE 1 END, s.updated_at DESC NULLS LAST LIMIT 1;
|
|
4164
|
-
IF v_connection_id IS NULL THEN
|
|
4165
|
-
SELECT c.id INTO v_connection_id FROM public.floriday_connections c
|
|
4166
|
-
WHERE COALESCE(c.is_active, true) = true
|
|
4167
|
-
ORDER BY c.updated_at DESC NULLS LAST, c.created_at DESC NULLS LAST LIMIT 1;
|
|
4168
|
-
END IF;
|
|
4189
|
+
SELECT * INTO v_ctx FROM public.get_stock_context();
|
|
4190
|
+
v_connection_id := v_ctx.connection_id;
|
|
4169
4191
|
|
|
4170
4192
|
RETURN QUERY
|
|
4171
4193
|
SELECT p_product_id, v_connection_id, COALESCE(s.trade_item_key, v_key),
|
|
@@ -4190,7 +4212,7 @@ AS $function$
|
|
|
4190
4212
|
DECLARE v_ctx record;
|
|
4191
4213
|
BEGIN
|
|
4192
4214
|
PERFORM public.voorraad_vereis('ingelogd', 'get_product_structure_totals');
|
|
4193
|
-
SELECT * INTO v_ctx FROM public.
|
|
4215
|
+
SELECT * INTO v_ctx FROM public.get_stock_context();
|
|
4194
4216
|
IF v_ctx.connection_id IS NULL THEN
|
|
4195
4217
|
RETURN jsonb_build_object('product_id',p_product_id,'type',public.product_type(p_product_id),'reason','NO_ACTIVE_CONNECTION');
|
|
4196
4218
|
END IF;
|
|
@@ -4219,6 +4241,51 @@ REVOKE ALL ON FUNCTION get_product_structure_totals_batch(uuid[]) FROM PUBLIC;
|
|
|
4219
4241
|
REVOKE ALL ON FUNCTION get_product_structure_totals_batch(uuid[]) FROM anon;
|
|
4220
4242
|
GRANT EXECUTE ON FUNCTION get_product_structure_totals_batch(uuid[]) TO authenticated;
|
|
4221
4243
|
GRANT EXECUTE ON FUNCTION get_product_structure_totals_batch(uuid[]) TO service_role;
|
|
4244
|
+
CREATE OR REPLACE FUNCTION public.get_stock_context(p_ensure boolean DEFAULT false)
|
|
4245
|
+
RETURNS TABLE(context_id uuid, context_kind text, connection_id uuid, user_id uuid)
|
|
4246
|
+
LANGUAGE plpgsql
|
|
4247
|
+
SECURITY DEFINER
|
|
4248
|
+
SET search_path TO 'public'
|
|
4249
|
+
AS $function$
|
|
4250
|
+
#variable_conflict use_column
|
|
4251
|
+
DECLARE v_env text; v_n int; v_id uuid; v_local uuid; v_user uuid;
|
|
4252
|
+
BEGIN
|
|
4253
|
+
PERFORM public.voorraad_vereis('ingelogd', 'get_stock_context');
|
|
4254
|
+
SELECT NULLIF(btrim(s.active_environment), '') INTO v_env FROM public.floriday_settings s ORDER BY s.id LIMIT 1;
|
|
4255
|
+
IF v_env IS NOT NULL THEN
|
|
4256
|
+
SELECT count(*), (array_agg(c.id))[1] INTO v_n, v_id FROM public.floriday_connections c
|
|
4257
|
+
WHERE c.is_active AND c.environment = v_env;
|
|
4258
|
+
IF v_n > 1 THEN
|
|
4259
|
+
RAISE EXCEPTION 'Er zijn % actieve Floriday-koppelingen voor omgeving %. Zet er één uit voordat je voorraad wijzigt.', v_n, v_env USING ERRCODE = 'VR001';
|
|
4260
|
+
END IF;
|
|
4261
|
+
IF v_n = 0 AND EXISTS (SELECT 1 FROM public.floriday_connections c WHERE c.is_active) THEN
|
|
4262
|
+
RAISE EXCEPTION 'De gekozen Floriday-omgeving (%) heeft geen actieve koppeling, maar een andere omgeving wel. Kies de juiste omgeving in de instellingen.', v_env USING ERRCODE = 'VR002';
|
|
4263
|
+
END IF;
|
|
4264
|
+
ELSE
|
|
4265
|
+
SELECT count(*), (array_agg(c.id))[1] INTO v_n, v_id FROM public.floriday_connections c WHERE c.is_active;
|
|
4266
|
+
IF v_n > 1 THEN
|
|
4267
|
+
RAISE EXCEPTION 'Er zijn % actieve Floriday-koppelingen en er is geen omgeving gekozen. Kies een omgeving in de instellingen.', v_n USING ERRCODE = 'VR001';
|
|
4268
|
+
END IF;
|
|
4269
|
+
END IF;
|
|
4270
|
+
IF v_n = 1 THEN
|
|
4271
|
+
SELECT t.user_id INTO v_user FROM public.trade_item_stock t WHERE t.connection_id = v_id ORDER BY t.created_at LIMIT 1;
|
|
4272
|
+
RETURN QUERY SELECT v_id, 'floriday'::text, v_id, COALESCE(v_user, auth.uid());
|
|
4273
|
+
RETURN;
|
|
4274
|
+
END IF;
|
|
4275
|
+
-- Geen koppeling: lokale context.
|
|
4276
|
+
SELECT l.id, l.created_by INTO v_local, v_user FROM public.voorraad_local_context l WHERE l.singleton;
|
|
4277
|
+
IF v_local IS NULL AND p_ensure THEN
|
|
4278
|
+
v_local := public.ensure_voorraad_local_context();
|
|
4279
|
+
SELECT l.created_by INTO v_user FROM public.voorraad_local_context l WHERE l.id = v_local;
|
|
4280
|
+
END IF;
|
|
4281
|
+
RETURN QUERY SELECT v_local, 'lokaal'::text, v_local,
|
|
4282
|
+
COALESCE((SELECT t.user_id FROM public.trade_item_stock t WHERE t.connection_id = v_local ORDER BY t.created_at LIMIT 1), auth.uid(), v_user);
|
|
4283
|
+
END $function$
|
|
4284
|
+
;
|
|
4285
|
+
REVOKE ALL ON FUNCTION get_stock_context(boolean) FROM PUBLIC;
|
|
4286
|
+
REVOKE ALL ON FUNCTION get_stock_context(boolean) FROM anon;
|
|
4287
|
+
GRANT EXECUTE ON FUNCTION get_stock_context(boolean) TO authenticated;
|
|
4288
|
+
GRANT EXECUTE ON FUNCTION get_stock_context(boolean) TO service_role;
|
|
4222
4289
|
CREATE OR REPLACE FUNCTION public.inventory_inline_budget_ok()
|
|
4223
4290
|
RETURNS boolean
|
|
4224
4291
|
LANGUAGE plpgsql
|
|
@@ -5871,43 +5938,10 @@ CREATE OR REPLACE FUNCTION public.set_product_stock(p_product_id uuid, p_physica
|
|
|
5871
5938
|
SECURITY DEFINER
|
|
5872
5939
|
SET search_path TO 'public'
|
|
5873
5940
|
AS $function$
|
|
5874
|
-
#variable_conflict use_column
|
|
5875
|
-
DECLARE
|
|
5876
|
-
v_user_id uuid := auth.uid(); v_connection_id uuid; v_key text; v_row_key text; v_product_key text; v_floriday_key text;
|
|
5877
5941
|
BEGIN
|
|
5878
5942
|
PERFORM public.voorraad_vereis('ingelogd', 'set_product_stock');
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
IF p_physical_stock < 0 OR p_minimum_stock < 0 OR p_incoming_stock < 0 THEN
|
|
5882
|
-
RAISE EXCEPTION 'Voorraadaantallen mogen niet negatief zijn'; END IF;
|
|
5883
|
-
SELECT NULLIF(trim(COALESCE(p.floriday_trade_item_id, '')), ''), NULLIF(trim(COALESCE(p.trade_item_key, '')), '')
|
|
5884
|
-
INTO v_floriday_key, v_product_key FROM public.products p WHERE p.id = p_product_id;
|
|
5885
|
-
IF NOT FOUND THEN RAISE EXCEPTION 'Product niet gevonden'; END IF;
|
|
5886
|
-
v_key := COALESCE(v_floriday_key, v_product_key, 'product:' || p_product_id::text);
|
|
5887
|
-
|
|
5888
|
-
SELECT s.connection_id, s.trade_item_key INTO v_connection_id, v_row_key FROM public.trade_item_stock s
|
|
5889
|
-
WHERE s.trade_item_key IN (v_key, v_floriday_key, v_product_key, 'product:' || p_product_id::text, p_product_id::text)
|
|
5890
|
-
ORDER BY CASE WHEN s.trade_item_key = v_key THEN 0 ELSE 1 END, s.updated_at DESC NULLS LAST LIMIT 1;
|
|
5891
|
-
IF v_connection_id IS NULL THEN
|
|
5892
|
-
SELECT c.id INTO v_connection_id FROM public.floriday_connections c
|
|
5893
|
-
WHERE COALESCE(c.is_active, true) = true
|
|
5894
|
-
ORDER BY c.updated_at DESC NULLS LAST, c.created_at DESC NULLS LAST LIMIT 1;
|
|
5895
|
-
END IF;
|
|
5896
|
-
IF v_connection_id IS NULL THEN RAISE EXCEPTION 'Geen actieve Floriday-connectie gevonden'; END IF;
|
|
5897
|
-
v_row_key := COALESCE(v_row_key, v_key);
|
|
5898
|
-
|
|
5899
|
-
INSERT INTO public.trade_item_stock AS t (user_id, connection_id, trade_item_key, physical_stock, minimum_stock, reserved_stock, incoming_stock, notes)
|
|
5900
|
-
VALUES (v_user_id, v_connection_id, v_row_key, p_physical_stock, COALESCE(p_minimum_stock, 0), 0, COALESCE(p_incoming_stock, 0), p_notes)
|
|
5901
|
-
ON CONFLICT (connection_id, trade_item_key) DO UPDATE
|
|
5902
|
-
SET physical_stock = EXCLUDED.physical_stock,
|
|
5903
|
-
minimum_stock = COALESCE(p_minimum_stock, t.minimum_stock, 0),
|
|
5904
|
-
incoming_stock = COALESCE(p_incoming_stock, t.incoming_stock, 0),
|
|
5905
|
-
notes = EXCLUDED.notes, updated_at = now();
|
|
5906
|
-
|
|
5907
|
-
RETURN QUERY
|
|
5908
|
-
SELECT p_product_id, s.connection_id, s.trade_item_key, s.physical_stock::numeric, s.minimum_stock::numeric,
|
|
5909
|
-
s.reserved_stock::numeric, s.incoming_stock::numeric, s.notes, s.updated_at
|
|
5910
|
-
FROM public.trade_item_stock s WHERE s.connection_id = v_connection_id AND s.trade_item_key = v_row_key LIMIT 1;
|
|
5943
|
+
RETURN QUERY SELECT * FROM public.set_product_stock(p_product_id => p_product_id, p_physical_stock => p_physical_stock,
|
|
5944
|
+
p_minimum_stock => p_minimum_stock, p_incoming_stock => p_incoming_stock, p_notes => p_notes, p_change_source => NULL::text);
|
|
5911
5945
|
END; $function$
|
|
5912
5946
|
;
|
|
5913
5947
|
REVOKE ALL ON FUNCTION set_product_stock(uuid,numeric,numeric,numeric,text) FROM PUBLIC;
|
|
@@ -5922,7 +5956,7 @@ CREATE OR REPLACE FUNCTION public.set_product_stock(p_product_id uuid, p_physica
|
|
|
5922
5956
|
AS $function$
|
|
5923
5957
|
#variable_conflict use_column
|
|
5924
5958
|
DECLARE
|
|
5925
|
-
v_user_id uuid := auth.uid(); v_connection_id uuid; v_key text; v_row_key text; v_product_key text; v_floriday_key text; v_source text;
|
|
5959
|
+
v_user_id uuid := auth.uid(); v_ctx record; v_connection_id uuid; v_key text; v_row_key text; v_product_key text; v_floriday_key text; v_source text;
|
|
5926
5960
|
BEGIN
|
|
5927
5961
|
PERFORM public.voorraad_vereis('ingelogd', 'set_product_stock');
|
|
5928
5962
|
IF v_user_id IS NULL THEN RAISE EXCEPTION 'Niet ingelogd' USING ERRCODE = '42501'; END IF;
|
|
@@ -5940,20 +5974,17 @@ BEGIN
|
|
|
5940
5974
|
IF NOT FOUND THEN RAISE EXCEPTION 'Product niet gevonden'; END IF;
|
|
5941
5975
|
v_key := COALESCE(v_floriday_key, v_product_key, 'product:' || p_product_id::text);
|
|
5942
5976
|
|
|
5943
|
-
|
|
5944
|
-
|
|
5977
|
+
-- Context: Floriday-koppeling (omgeving, anders de enige actieve) of de lokale context.
|
|
5978
|
+
SELECT * INTO v_ctx FROM public.get_stock_context(true);
|
|
5979
|
+
v_connection_id := v_ctx.connection_id;
|
|
5980
|
+
IF v_connection_id IS NULL THEN RAISE EXCEPTION 'Geen voorraadcontext beschikbaar' USING ERRCODE = 'VR004'; END IF;
|
|
5981
|
+
|
|
5982
|
+
SELECT s.trade_item_key INTO v_row_key FROM public.trade_item_stock s
|
|
5983
|
+
WHERE s.connection_id = v_connection_id
|
|
5984
|
+
AND s.trade_item_key IN (v_key, v_floriday_key, v_product_key, 'product:' || p_product_id::text, p_product_id::text)
|
|
5945
5985
|
ORDER BY CASE WHEN s.trade_item_key = v_key THEN 0 ELSE 1 END, s.updated_at DESC NULLS LAST LIMIT 1;
|
|
5946
|
-
IF v_connection_id IS NULL THEN
|
|
5947
|
-
SELECT c.id INTO v_connection_id FROM public.floriday_connections c
|
|
5948
|
-
WHERE COALESCE(c.is_active, true) = true
|
|
5949
|
-
ORDER BY c.updated_at DESC NULLS LAST, c.created_at DESC NULLS LAST LIMIT 1;
|
|
5950
|
-
END IF;
|
|
5951
|
-
IF v_connection_id IS NULL THEN RAISE EXCEPTION 'Geen actieve Floriday-connectie gevonden'; END IF;
|
|
5952
5986
|
v_row_key := COALESCE(v_row_key, v_key);
|
|
5953
5987
|
|
|
5954
|
-
-- De bron wordt op de rij zelf gezet: de logtrigger geeft een gewijzigde
|
|
5955
|
-
-- change_source voorrang boven de transactie-instelling, en de kolom heeft
|
|
5956
|
-
-- anders de standaardwaarde MANUAL_STOCK.
|
|
5957
5988
|
INSERT INTO public.trade_item_stock AS t (user_id, connection_id, trade_item_key, physical_stock, minimum_stock, reserved_stock, incoming_stock, notes, change_source)
|
|
5958
5989
|
VALUES (v_user_id, v_connection_id, v_row_key, p_physical_stock, COALESCE(p_minimum_stock, 0), 0, COALESCE(p_incoming_stock, 0), p_notes, COALESCE(v_source, 'MANUAL_STOCK'))
|
|
5959
5990
|
ON CONFLICT (connection_id, trade_item_key) DO UPDATE
|
|
@@ -6032,7 +6063,7 @@ BEGIN
|
|
|
6032
6063
|
PERFORM public.voorraad_vereis('ingelogd', 'stock_import_create');
|
|
6033
6064
|
IF v_uid IS NULL AND COALESCE(auth.role(),'') <> 'service_role' THEN RAISE EXCEPTION 'Niet ingelogd' USING ERRCODE = '42501'; END IF;
|
|
6034
6065
|
IF NOT public.voorraad_can_write() THEN RETURN jsonb_build_object('ok', false, 'code', 'NO_WRITE_ROLE', 'message', 'Je hebt geen rechten om voorraad te importeren. Vraag een beheerder om een schrijfrol.'); END IF;
|
|
6035
|
-
SELECT * INTO v_ctx FROM public.
|
|
6066
|
+
SELECT * INTO v_ctx FROM public.get_stock_context(true);
|
|
6036
6067
|
v_conn := COALESCE(p_connection_id, v_ctx.connection_id);
|
|
6037
6068
|
v_user := COALESCE(v_uid, v_ctx.user_id);
|
|
6038
6069
|
SELECT import_chunk_size, import_new_chunk_size, import_max_rows, import_max_bytes INTO l FROM public.inventory_recompute_limits WHERE id;
|
|
@@ -6124,7 +6155,7 @@ BEGIN
|
|
|
6124
6155
|
RAISE EXCEPTION 'Deze import is (deels) ongedaan gemaakt en kan niet verder.';
|
|
6125
6156
|
END IF;
|
|
6126
6157
|
|
|
6127
|
-
SELECT * INTO v_ctx FROM public.
|
|
6158
|
+
SELECT * INTO v_ctx FROM public.get_stock_context(true);
|
|
6128
6159
|
PERFORM set_config('stock.change_source', 'IMPORT', true);
|
|
6129
6160
|
|
|
6130
6161
|
FOR r IN SELECT * FROM public.stock_import_rows WHERE run_id = p_run_id AND chunk_no = p_chunk_no AND status = 'wacht' ORDER BY row_no LOOP
|
|
@@ -7083,8 +7114,8 @@ BEGIN
|
|
|
7083
7114
|
CREATE TEMP TABLE IF NOT EXISTS _link_enq (product_id uuid, fid uuid, connection_id uuid, user_id uuid, pieces int) ON COMMIT DROP;
|
|
7084
7115
|
DELETE FROM _link_enq WHERE product_id IS NOT NULL OR product_id IS NULL;
|
|
7085
7116
|
|
|
7086
|
-
SELECT * INTO v_ctx FROM public.
|
|
7087
|
-
IF v_ctx.connection_id IS NULL THEN RETURN NULL; END IF;
|
|
7117
|
+
SELECT * INTO v_ctx FROM public.get_stock_context();
|
|
7118
|
+
IF v_ctx.connection_id IS NULL OR v_ctx.context_kind <> 'floriday' THEN RETURN NULL; END IF;
|
|
7088
7119
|
|
|
7089
7120
|
INSERT INTO _link_enq (product_id, fid, connection_id, user_id, pieces)
|
|
7090
7121
|
SELECT n.id, n.floriday_trade_item_id::uuid, v_ctx.connection_id, v_ctx.user_id,
|
|
@@ -7985,6 +8016,24 @@ GRANT EXECUTE ON FUNCTION voorraad_external_fulfilled_ids(jsonb) TO service_role
|
|
|
7985
8016
|
REVOKE EXECUTE ON FUNCTION voorraad_external_fulfilled_ids(jsonb) FROM anon;
|
|
7986
8017
|
GRANT EXECUTE ON FUNCTION voorraad_external_fulfilled_ids(jsonb) TO authenticated;
|
|
7987
8018
|
GRANT EXECUTE ON FUNCTION voorraad_external_fulfilled_ids(jsonb) TO service_role;
|
|
8019
|
+
CREATE OR REPLACE FUNCTION public.voorraad_fcsq_local_guard()
|
|
8020
|
+
RETURNS trigger
|
|
8021
|
+
LANGUAGE plpgsql
|
|
8022
|
+
SECURITY DEFINER
|
|
8023
|
+
SET search_path TO 'public'
|
|
8024
|
+
AS $function$
|
|
8025
|
+
BEGIN
|
|
8026
|
+
PERFORM public.voorraad_vereis('ingelogd', 'voorraad_fcsq_local_guard');
|
|
8027
|
+
IF EXISTS (SELECT 1 FROM public.voorraad_local_context l WHERE l.id = NEW.connection_id) THEN
|
|
8028
|
+
RETURN NULL;
|
|
8029
|
+
END IF;
|
|
8030
|
+
RETURN NEW;
|
|
8031
|
+
END $function$
|
|
8032
|
+
;
|
|
8033
|
+
REVOKE ALL ON FUNCTION voorraad_fcsq_local_guard() FROM PUBLIC;
|
|
8034
|
+
REVOKE ALL ON FUNCTION voorraad_fcsq_local_guard() FROM anon;
|
|
8035
|
+
GRANT EXECUTE ON FUNCTION voorraad_fcsq_local_guard() TO authenticated;
|
|
8036
|
+
GRANT EXECUTE ON FUNCTION voorraad_fcsq_local_guard() TO service_role;
|
|
7988
8037
|
CREATE OR REPLACE FUNCTION public.voorraad_floriday_leads_key(p_key text)
|
|
7989
8038
|
RETURNS boolean
|
|
7990
8039
|
LANGUAGE sql
|
|
@@ -8003,6 +8052,45 @@ $function$
|
|
|
8003
8052
|
REVOKE ALL ON FUNCTION voorraad_floriday_leads_key(text) FROM PUBLIC;
|
|
8004
8053
|
REVOKE ALL ON FUNCTION voorraad_floriday_leads_key(text) FROM anon;
|
|
8005
8054
|
GRANT EXECUTE ON FUNCTION voorraad_floriday_leads_key(text) TO service_role;
|
|
8055
|
+
CREATE OR REPLACE FUNCTION public.voorraad_fust_dimensions()
|
|
8056
|
+
RETURNS TABLE(fust_type_id uuid, fust_key text, vbn_code integer, name text, floricode_name text, length_mm numeric, width_mm numeric, height_mm numeric, dimension_source text)
|
|
8057
|
+
LANGUAGE plpgsql
|
|
8058
|
+
STABLE SECURITY DEFINER
|
|
8059
|
+
SET search_path TO 'public'
|
|
8060
|
+
AS $function$
|
|
8061
|
+
-- Leesfunctie voor de Engine: fustcode en maten per fusttype.
|
|
8062
|
+
-- Maten: eerst Floricode (floricode_packaging_types, eigenaar Floriday-auth), anders handmatig ingevoerd, anders leeg (nooit standaardwaarden).
|
|
8063
|
+
DECLARE v_fc boolean := to_regprocedure('public.floricode_packaging_types()') IS NOT NULL;
|
|
8064
|
+
BEGIN
|
|
8065
|
+
PERFORM public.voorraad_vereis('ingelogd', 'voorraad_fust_dimensions');
|
|
8066
|
+
IF v_fc THEN
|
|
8067
|
+
RETURN QUERY
|
|
8068
|
+
WITH fc AS (SELECT DISTINCT ON (c.code) c.code, c.name, c.length_mm, c.width_mm, c.height_mm
|
|
8069
|
+
FROM public.floricode_packaging_types() c ORDER BY c.code, c.expiry_date DESC NULLS FIRST)
|
|
8070
|
+
SELECT f.id, f.fust_key, f.vbn_code, f.name, fc.name,
|
|
8071
|
+
COALESCE(fc.length_mm, f.length_mm::numeric), COALESCE(fc.width_mm, f.width_mm::numeric), COALESCE(fc.height_mm, f.height_mm::numeric),
|
|
8072
|
+
CASE WHEN fc.length_mm IS NOT NULL OR fc.width_mm IS NOT NULL OR fc.height_mm IS NOT NULL THEN 'floricode'
|
|
8073
|
+
WHEN f.length_mm IS NOT NULL OR f.width_mm IS NOT NULL OR f.height_mm IS NOT NULL THEN 'handmatig'
|
|
8074
|
+
ELSE 'onbekend' END
|
|
8075
|
+
FROM public.fust_types f
|
|
8076
|
+
LEFT JOIN fc ON f.vbn_code IS NOT NULL AND fc.code = f.vbn_code::text
|
|
8077
|
+
WHERE f.connection_id IS NULL
|
|
8078
|
+
ORDER BY f.name;
|
|
8079
|
+
ELSE
|
|
8080
|
+
RETURN QUERY
|
|
8081
|
+
SELECT f.id, f.fust_key, f.vbn_code, f.name, NULL::text,
|
|
8082
|
+
f.length_mm::numeric, f.width_mm::numeric, f.height_mm::numeric,
|
|
8083
|
+
CASE WHEN f.length_mm IS NOT NULL OR f.width_mm IS NOT NULL OR f.height_mm IS NOT NULL THEN 'handmatig' ELSE 'onbekend' END
|
|
8084
|
+
FROM public.fust_types f
|
|
8085
|
+
WHERE f.connection_id IS NULL
|
|
8086
|
+
ORDER BY f.name;
|
|
8087
|
+
END IF;
|
|
8088
|
+
END $function$
|
|
8089
|
+
;
|
|
8090
|
+
REVOKE ALL ON FUNCTION voorraad_fust_dimensions() FROM PUBLIC;
|
|
8091
|
+
REVOKE ALL ON FUNCTION voorraad_fust_dimensions() FROM anon;
|
|
8092
|
+
GRANT EXECUTE ON FUNCTION voorraad_fust_dimensions() TO authenticated;
|
|
8093
|
+
GRANT EXECUTE ON FUNCTION voorraad_fust_dimensions() TO service_role;
|
|
8006
8094
|
CREATE OR REPLACE FUNCTION public.voorraad_hook_base_url()
|
|
8007
8095
|
RETURNS text
|
|
8008
8096
|
LANGUAGE plpgsql
|
|
@@ -8120,8 +8208,8 @@ CREATE OR REPLACE FUNCTION public.voorraad_install_check()
|
|
|
8120
8208
|
STABLE SECURITY DEFINER
|
|
8121
8209
|
SET search_path TO 'public'
|
|
8122
8210
|
AS $function$
|
|
8123
|
-
DECLARE v_f text[] := ARRAY['_floriday_queue_cleanup_batch','_migrate_rewrite_stock_key','_stock_import_caller','apply_fust_stock_mutation','apply_stock_consumption','apply_stock_reservation','autolink_product_to_floriday','backfill_open_order_reservations','calculate_floriday_desired_stock','calculate_structure_available','canonicalize_trade_item_stock_key','check_product_structure','claim_floriday_base_supply','claim_floriday_stock_queue','cleanup_floriday_stock_queue','cleanup_voorraad_module_history','complete_floriday_base_supply','complete_floriday_stock_queue','complete_floriday_stock_queue_outcome','consume_bom_for_production','consume_order_item','drain_inventory_recompute_queue','enqueue_floriday_continuous_stock','enqueue_floriday_continuous_stock_after_warehouse_preference','enqueue_structure_recompute','ensure_inventory_recompute_drain','ensure_trade_item_stock_row','ensure_trade_item_stock_row_key','fcsq_block_disabled','fcsq_fallback_supersede','fcsq_wake_base_supply','find_trade_item_key','floriday_adopt_connection','floriday_autoheal_connections','floriday_capture_stock_snapshot','floriday_cleanup_stock_queue_v2','floriday_compact_stock_snapshots','floriday_default_owner','floriday_desired_stock_regression_check','floriday_ensure_inventory_settings','floriday_erp_leading_preview','floriday_fill_publish_horizon','floriday_follow_apply','floriday_ingest_sales_orders','floriday_leading_summary','floriday_make_erp_leading','floriday_norm_offer_forms','floriday_orphan_settings_count','floriday_publish_horizon_weeks','floriday_queue_erp_guard','floriday_queue_first_positive','floriday_recompute_inventory','floriday_relink_products','floriday_requeue_dead_letters','floriday_settings_change_recompute','floriday_settings_change_recompute_stmt','floriday_stock_change_recompute','floriday_stock_queue_supersede','floriday_takeover_apply','floriday_takeover_fetch_state','floriday_takeover_store_forms','floriday_takeover_undo','fust_negative_stock_report','fust_types_duplicate_guard','get_active_floriday_context','get_group_allocation_keys','get_group_head_key','get_product_stock','get_product_structure_totals','get_product_structure_totals_batch','inventory_inline_budget_ok','merge_products','normalize_order_source','process_inventory_recompute_queue','produce_designed_product','product_active_group_id','product_id_from_ref','product_is_set','product_label','product_member_group_ids','product_own_available','product_packings_derive','product_packings_replace','product_packings_sync_from_floriday','product_primary_pieces','product_set_depth_above','product_set_depth_below','product_structure_ancestors','product_structure_max_depth','product_structure_path','product_tray_stickers_touch','product_type','promote_trade_item_key','recompute_all_reserved_stock','recompute_order_status','recompute_reserved_for_order','recompute_reserved_stock','requeue_skipped_stock_rows','reset_stalled_floriday_stock_queue','resolve_group_allocation','resolve_group_member_stock_key','resolve_product_id_for_item','resolve_stock_trade_item_key','reverse_production','run_floriday_base_supply_process','run_floriday_continuous_stock_sync','run_floriday_follow','run_floriday_stock_queue_process','run_floriday_stock_reconcile','run_logistics_tasks_dispatch','self_heal_floriday_links','set_module_runtime_config_updated_at','set_product_bom_tenant','set_product_stock','set_updated_at_order_fust_bookings','stock_import_cleanup','stock_import_create','stock_import_process_chunk','stock_import_stop','stock_import_undo_chunk','sync_order_item_fusten','sync_products_quantity_from_stock','touch_fust_types_updated_at','trade_item_drafts_readonly','trade_item_prices_touch_updated_at','trade_item_stock_duplicates','trg_cart_numbers_sync_order_status_fn','trg_cart_session_consume_fn','trg_check_product_structure','trg_floriday_cache_relink_fn','trg_floriday_trade_items_autolink_fn','trg_order_items_autolink_fn','trg_order_items_fusten','trg_order_items_reserve_fn','trg_orders_cancel_release_fn','trg_orders_consume_on_complete_fn','trg_orders_default_phase_fn','trg_orders_external_fulfilled_fn','trg_orders_recompute_reserved_fn','trg_pgi_assign_sort_order','trg_pgi_order_taken_check','trg_process_recompute_on_commit','trg_product_packings_derive_fn','trg_products_autolink_fn','trg_products_floriday_link_enqueue','trg_products_seed_stock_fn','trg_requeue_no_warehouse_cache','trg_requeue_no_warehouse_connection','trg_requeue_no_warehouse_item_pref','trg_requeue_skipped_no_price','trg_stock_structure_recompute_ins','trg_stock_structure_recompute_upd','trg_structure_change_recompute','trg_trade_item_drafts_autolink_fn','trg_trade_item_stock_auto_bom','trg_trade_item_stock_auto_bom_reverse','trg_trade_item_stock_log_change','trg_trade_item_stock_reserve_fn','trg_trade_item_stock_zero_watch','trg_trade_items_cache_autolink_fn','update_updated_at_column','voorraad_alert_floriday_not_updated','voorraad_can_write','voorraad_cleanup_old_rows','voorraad_consume_external_fulfilled','voorraad_correctie_1098','voorraad_correctie_status','voorraad_external_fulfilled_ids','voorraad_floriday_leads_key','voorraad_hook_base_url','voorraad_hook_on','voorraad_hook_post','voorraad_hook_switch_jobs','voorraad_install_check','voorraad_is_server','voorraad_mark_floriday_sold_before_switch','voorraad_production_enabled','voorraad_schema_ddl','voorraad_touch_updated_at','voorraad_vereis','voorraad_week_is_past'];
|
|
8124
|
-
v_t text[] := ARRAY['aa_fcsq_erp_leading_guard@floriday_continuous_stock_queue','aa_fis_norm_offer_forms@floriday_inventory_settings','aa_pgi_assign_sort_order@product_group_items','fcsq_block_disabled@floriday_continuous_stock_queue','fcsq_wake_base_supply_ins@floriday_continuous_stock_queue','fcsq_wake_base_supply_upd@floriday_continuous_stock_queue','fust_stock_mutations_apply@fust_stock_mutations','fust_types_duplicate_guard@fust_types','fust_types_touch@fust_types','product_packings_derive_trg@product_packings','product_packings_updated_at@product_packings','set_product_bom_tenant_trigger@product_bom_items','trade_item_prices_set_updated_at@trade_item_prices','trg_cart_numbers_sync_order_status@cart_numbers','trg_cart_session_consume@cart_control_sessions','trg_check_product_structure@product_bom_items','trg_check_product_structure@product_group_items','trg_check_product_structure@product_groups','trg_fcs_queue_updated_at@floriday_continuous_stock_queue','trg_fcsq_fallback_supersede@floriday_continuous_stock_queue','trg_fcsq_supersede@floriday_continuous_stock_queue','trg_floriday_cache_relink@floriday_trade_items_cache','trg_floriday_ensure_inventory_settings@products','trg_floriday_gate_stock_queue@floriday_continuous_stock_queue','trg_floriday_settings_change_recompute_ins@floriday_inventory_settings','trg_floriday_settings_change_recompute_upd@floriday_inventory_settings','trg_floriday_stock_change_recompute@trade_item_stock','trg_floriday_takeover_runs_updated_at@floriday_takeover_runs','trg_floriday_trade_items_autolink@floriday_trade_items_cache','trg_fust_types_requeue_blocked@fust_types','trg_module_runtime_config_updated_at@module_runtime_config','trg_order_fust_bookings_updated_at@order_fust_bookings','trg_order_items_autolink@order_items','trg_order_items_fusten_aiud@order_items','trg_order_items_reserve@order_items','trg_orders_cancel_release@orders','trg_orders_consume_on_complete@orders','trg_orders_default_phase@orders','trg_orders_external_fulfilled@orders','trg_orders_recompute_reserved@orders','trg_prevent_duplicate_product_draft@trade_item_drafts','trg_product_tray_stickers_touch@product_tray_stickers','trg_products_autolink@products','trg_products_floriday_link_enqueue@products','trg_products_seed_stock@products','trg_requeue_no_warehouse_cache@floriday_trade_items_cache','trg_requeue_no_warehouse_connection@floriday_connections','trg_requeue_no_warehouse_item_pref@trade_item_warehouse_preferences','trg_requeue_skipped_no_price@products','trg_stock_mutation_alert@stock_mutation_log','trg_stock_structure_recompute_ins@trade_item_stock','trg_stock_structure_recompute_upd@trade_item_stock','trg_structure_change_recompute@product_bom_items','trg_structure_change_recompute@product_group_items','trg_structure_change_recompute@product_groups','trg_sync_layer_stock_from_trade_stock@trade_item_stock','trg_sync_products_quantity_from_stock_del@trade_item_stock','trg_sync_products_quantity_from_stock_iu@trade_item_stock','trg_trade_item_drafts_autolink@trade_item_drafts','trg_trade_item_drafts_readonly@trade_item_drafts','trg_trade_item_stock_canonical_key@trade_item_stock','trg_trade_item_stock_publish@trade_item_stock','trg_trade_item_stock_reserve@trade_item_stock','trg_trade_item_stock_updated_at@trade_item_stock','trg_trade_item_stock_zero_watch@trade_item_stock','trg_trade_item_supply_lines_touch@trade_item_supply_lines','trg_trade_item_warehouse_preference_enqueue_stock@trade_item_warehouse_preferences','trg_trade_items_cache_autolink@floriday_trade_items_cache','trg_voorraad_buffer_state_updated_at@voorraad_buffer_state','trg_voorraad_event_log_updated_at@voorraad_logistics_event_log','update_trade_item_drafts_updated_at@trade_item_drafts','update_trade_item_warehouse_preferences_updated_at@trade_item_warehouse_preferences','update_voorraad_custom_fields_updated_at@voorraad_custom_fields','update_voorraad_publish_jobs_updated_at@voorraad_publish_jobs','update_voorraad_publish_learnings_updated_at@voorraad_publish_learnings','update_voorraad_publish_steps_updated_at@voorraad_publish_steps','voorraad_hook_switch_jobs@module_runtime_config','zz_fcsq_first_positive@floriday_continuous_stock_queue'];
|
|
8211
|
+
DECLARE v_f text[] := ARRAY['ensure_voorraad_local_context','get_stock_context','voorraad_stock_context_status','voorraad_fcsq_local_guard','_floriday_queue_cleanup_batch','_migrate_rewrite_stock_key','_stock_import_caller','apply_fust_stock_mutation','apply_stock_consumption','apply_stock_reservation','autolink_product_to_floriday','backfill_open_order_reservations','calculate_floriday_desired_stock','calculate_structure_available','canonicalize_trade_item_stock_key','check_product_structure','claim_floriday_base_supply','claim_floriday_stock_queue','cleanup_floriday_stock_queue','cleanup_voorraad_module_history','complete_floriday_base_supply','complete_floriday_stock_queue','complete_floriday_stock_queue_outcome','consume_bom_for_production','consume_order_item','drain_inventory_recompute_queue','enqueue_floriday_continuous_stock','enqueue_floriday_continuous_stock_after_warehouse_preference','enqueue_structure_recompute','ensure_inventory_recompute_drain','ensure_trade_item_stock_row','ensure_trade_item_stock_row_key','fcsq_block_disabled','fcsq_fallback_supersede','fcsq_wake_base_supply','find_trade_item_key','floriday_adopt_connection','floriday_autoheal_connections','floriday_capture_stock_snapshot','floriday_cleanup_stock_queue_v2','floriday_compact_stock_snapshots','floriday_default_owner','floriday_desired_stock_regression_check','floriday_ensure_inventory_settings','floriday_erp_leading_preview','floriday_fill_publish_horizon','floriday_follow_apply','floriday_ingest_sales_orders','floriday_leading_summary','floriday_make_erp_leading','floriday_norm_offer_forms','floriday_orphan_settings_count','floriday_publish_horizon_weeks','floriday_queue_erp_guard','floriday_queue_first_positive','floriday_recompute_inventory','floriday_relink_products','floriday_requeue_dead_letters','floriday_settings_change_recompute','floriday_settings_change_recompute_stmt','floriday_stock_change_recompute','floriday_stock_queue_supersede','floriday_takeover_apply','floriday_takeover_fetch_state','floriday_takeover_store_forms','floriday_takeover_undo','fust_negative_stock_report','fust_types_duplicate_guard','get_active_floriday_context','get_group_allocation_keys','get_group_head_key','get_product_stock','get_product_structure_totals','get_product_structure_totals_batch','inventory_inline_budget_ok','merge_products','normalize_order_source','process_inventory_recompute_queue','produce_designed_product','product_active_group_id','product_id_from_ref','product_is_set','product_label','product_member_group_ids','product_own_available','product_packings_derive','product_packings_replace','product_packings_sync_from_floriday','product_primary_pieces','product_set_depth_above','product_set_depth_below','product_structure_ancestors','product_structure_max_depth','product_structure_path','product_tray_stickers_touch','product_type','promote_trade_item_key','recompute_all_reserved_stock','recompute_order_status','recompute_reserved_for_order','recompute_reserved_stock','requeue_skipped_stock_rows','reset_stalled_floriday_stock_queue','resolve_group_allocation','resolve_group_member_stock_key','resolve_product_id_for_item','resolve_stock_trade_item_key','reverse_production','run_floriday_base_supply_process','run_floriday_continuous_stock_sync','run_floriday_follow','run_floriday_stock_queue_process','run_floriday_stock_reconcile','run_logistics_tasks_dispatch','self_heal_floriday_links','set_module_runtime_config_updated_at','set_product_bom_tenant','set_product_stock','set_updated_at_order_fust_bookings','stock_import_cleanup','stock_import_create','stock_import_process_chunk','stock_import_stop','stock_import_undo_chunk','sync_order_item_fusten','sync_products_quantity_from_stock','touch_fust_types_updated_at','trade_item_drafts_readonly','trade_item_prices_touch_updated_at','trade_item_stock_duplicates','trg_cart_numbers_sync_order_status_fn','trg_cart_session_consume_fn','trg_check_product_structure','trg_floriday_cache_relink_fn','trg_floriday_trade_items_autolink_fn','trg_order_items_autolink_fn','trg_order_items_fusten','trg_order_items_reserve_fn','trg_orders_cancel_release_fn','trg_orders_consume_on_complete_fn','trg_orders_default_phase_fn','trg_orders_external_fulfilled_fn','trg_orders_recompute_reserved_fn','trg_pgi_assign_sort_order','trg_pgi_order_taken_check','trg_process_recompute_on_commit','trg_product_packings_derive_fn','trg_products_autolink_fn','trg_products_floriday_link_enqueue','trg_products_seed_stock_fn','trg_requeue_no_warehouse_cache','trg_requeue_no_warehouse_connection','trg_requeue_no_warehouse_item_pref','trg_requeue_skipped_no_price','trg_stock_structure_recompute_ins','trg_stock_structure_recompute_upd','trg_structure_change_recompute','trg_trade_item_drafts_autolink_fn','trg_trade_item_stock_auto_bom','trg_trade_item_stock_auto_bom_reverse','trg_trade_item_stock_log_change','trg_trade_item_stock_reserve_fn','trg_trade_item_stock_zero_watch','trg_trade_items_cache_autolink_fn','update_updated_at_column','voorraad_alert_floriday_not_updated','voorraad_can_write','voorraad_cleanup_old_rows','voorraad_consume_external_fulfilled','voorraad_correctie_1098','voorraad_correctie_status','voorraad_external_fulfilled_ids','voorraad_floriday_leads_key','voorraad_fust_dimensions','voorraad_hook_base_url','voorraad_hook_on','voorraad_hook_post','voorraad_hook_switch_jobs','voorraad_install_check','voorraad_is_server','voorraad_mark_floriday_sold_before_switch','voorraad_production_enabled','voorraad_schema_ddl','voorraad_touch_updated_at','voorraad_vereis','voorraad_week_is_past'];
|
|
8212
|
+
v_t text[] := ARRAY['aa0_fcsq_local_context_guard@floriday_continuous_stock_queue','aa_fcsq_erp_leading_guard@floriday_continuous_stock_queue','aa_fis_norm_offer_forms@floriday_inventory_settings','aa_pgi_assign_sort_order@product_group_items','fcsq_block_disabled@floriday_continuous_stock_queue','fcsq_wake_base_supply_ins@floriday_continuous_stock_queue','fcsq_wake_base_supply_upd@floriday_continuous_stock_queue','fust_stock_mutations_apply@fust_stock_mutations','fust_types_duplicate_guard@fust_types','fust_types_touch@fust_types','product_packings_derive_trg@product_packings','product_packings_updated_at@product_packings','set_product_bom_tenant_trigger@product_bom_items','trade_item_prices_set_updated_at@trade_item_prices','trg_cart_numbers_sync_order_status@cart_numbers','trg_cart_session_consume@cart_control_sessions','trg_check_product_structure@product_bom_items','trg_check_product_structure@product_group_items','trg_check_product_structure@product_groups','trg_fcs_queue_updated_at@floriday_continuous_stock_queue','trg_fcsq_fallback_supersede@floriday_continuous_stock_queue','trg_fcsq_supersede@floriday_continuous_stock_queue','trg_floriday_cache_relink@floriday_trade_items_cache','trg_floriday_ensure_inventory_settings@products','trg_floriday_gate_stock_queue@floriday_continuous_stock_queue','trg_floriday_settings_change_recompute_ins@floriday_inventory_settings','trg_floriday_settings_change_recompute_upd@floriday_inventory_settings','trg_floriday_stock_change_recompute@trade_item_stock','trg_floriday_takeover_runs_updated_at@floriday_takeover_runs','trg_floriday_trade_items_autolink@floriday_trade_items_cache','trg_fust_types_requeue_blocked@fust_types','trg_module_runtime_config_updated_at@module_runtime_config','trg_order_fust_bookings_updated_at@order_fust_bookings','trg_order_items_autolink@order_items','trg_order_items_fusten_aiud@order_items','trg_order_items_reserve@order_items','trg_orders_cancel_release@orders','trg_orders_consume_on_complete@orders','trg_orders_default_phase@orders','trg_orders_external_fulfilled@orders','trg_orders_recompute_reserved@orders','trg_prevent_duplicate_product_draft@trade_item_drafts','trg_product_tray_stickers_touch@product_tray_stickers','trg_products_autolink@products','trg_products_floriday_link_enqueue@products','trg_products_seed_stock@products','trg_requeue_no_warehouse_cache@floriday_trade_items_cache','trg_requeue_no_warehouse_connection@floriday_connections','trg_requeue_no_warehouse_item_pref@trade_item_warehouse_preferences','trg_requeue_skipped_no_price@products','trg_stock_mutation_alert@stock_mutation_log','trg_stock_structure_recompute_ins@trade_item_stock','trg_stock_structure_recompute_upd@trade_item_stock','trg_structure_change_recompute@product_bom_items','trg_structure_change_recompute@product_group_items','trg_structure_change_recompute@product_groups','trg_sync_layer_stock_from_trade_stock@trade_item_stock','trg_sync_products_quantity_from_stock_del@trade_item_stock','trg_sync_products_quantity_from_stock_iu@trade_item_stock','trg_trade_item_drafts_autolink@trade_item_drafts','trg_trade_item_drafts_readonly@trade_item_drafts','trg_trade_item_stock_canonical_key@trade_item_stock','trg_trade_item_stock_publish@trade_item_stock','trg_trade_item_stock_reserve@trade_item_stock','trg_trade_item_stock_updated_at@trade_item_stock','trg_trade_item_stock_zero_watch@trade_item_stock','trg_trade_item_supply_lines_touch@trade_item_supply_lines','trg_trade_item_warehouse_preference_enqueue_stock@trade_item_warehouse_preferences','trg_trade_items_cache_autolink@floriday_trade_items_cache','trg_voorraad_buffer_state_updated_at@voorraad_buffer_state','trg_voorraad_event_log_updated_at@voorraad_logistics_event_log','update_trade_item_drafts_updated_at@trade_item_drafts','update_trade_item_warehouse_preferences_updated_at@trade_item_warehouse_preferences','update_voorraad_custom_fields_updated_at@voorraad_custom_fields','update_voorraad_publish_jobs_updated_at@voorraad_publish_jobs','update_voorraad_publish_learnings_updated_at@voorraad_publish_learnings','update_voorraad_publish_steps_updated_at@voorraad_publish_steps','voorraad_hook_switch_jobs@module_runtime_config','zz_fcsq_first_positive@floriday_continuous_stock_queue'];
|
|
8125
8213
|
v_p text[] := ARRAY['Authenticated can add learnings@voorraad_publish_learnings','Authenticated can delete voorraad custom fields@voorraad_custom_fields','Authenticated can insert vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can insert voorraad custom fields@voorraad_custom_fields','Authenticated can read continuous stock cache@floriday_continuous_stock_cache','Authenticated can read learnings@voorraad_publish_learnings','Authenticated can read vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can read voorraad custom fields@voorraad_custom_fields','Authenticated can update learnings@voorraad_publish_learnings','Authenticated can update vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can update voorraad custom fields@voorraad_custom_fields','Authenticated delete trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated insert trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated select trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated update trade_item_warehouse_preferences@trade_item_warehouse_preferences','Eigen momentopnamen lezen@inventory_stock_snapshots','Eigen voorraadinstellingen beheren@floriday_inventory_settings','Eigenaar leest importporties@stock_import_chunks','Eigenaar leest importregels@stock_import_rows','Fust mutations delete@fust_stock_mutations','Fust mutations insert@fust_stock_mutations','Fust mutations read@fust_stock_mutations','Fust mutations update@fust_stock_mutations','Fust types delete@fust_types','Fust types insert@fust_types','Fust types read@fust_types','Fust types update@fust_types','Ingelogde gebruikers kunnen bufferstatus lezen@voorraad_buffer_state','Ingelogde gebruikers kunnen de eventlog lezen@voorraad_logistics_event_log','Ingelogde gebruikers kunnen fustboekingen lezen@order_fust_bookings','Ingelogde gebruikers lezen drempels@inventory_recompute_limits','Ingelogde gebruikers lezen opruimlogboek@structure_cleanup_log','Ingelogde gebruikers lezen opruimruns@floriday_queue_cleanup_runs','Ingelogden beheren traystickers@product_tray_stickers','Ingelogden lezen herberekenwachtrij@inventory_recompute_queue','Ingelogden lezen voorraadmeldingen@stock_integrity_alerts','Ingelogden markeren voorraadmeldingen als gezien@stock_integrity_alerts','Own queue rows select@floriday_continuous_stock_queue','Owner delete trade_item_drafts@trade_item_drafts','Owner insert trade_item_drafts@trade_item_drafts','Owner select trade_item_drafts@trade_item_drafts','Owner update trade_item_drafts@trade_item_drafts','Signed-in users read reconcile runs@floriday_reconcile_runs','Stock delete@trade_item_stock','Stock insert@trade_item_stock','Stock read@trade_item_stock','Stock update@trade_item_stock','Synchronisatieposities lezen@floriday_sync_cursors','Users can insert own publish attempts@voorraad_publish_attempts','Users can read own publish attempts@voorraad_publish_attempts','Users can read own stock mutations@stock_mutation_log','Users manage own import runs@stock_import_runs','Users manage own supply lines@trade_item_supply_lines','Users manage own trade item prices@trade_item_prices','Users manage their own publish jobs@voorraad_publish_jobs','Users manage their own publish steps@voorraad_publish_steps','Verwerkte orders lezen@floriday_sales_order_ingest','Voorraadschrijvers lezen overnameregels@floriday_takeover_items','Voorraadschrijvers lezen overnames@floriday_takeover_runs','authenticated can insert merge log@product_merge_log','authenticated can read merge log@product_merge_log','service role only@voorraad_media_upload_failures','product_packings_read@product_packings','product_packings_write@product_packings'];
|
|
8126
8214
|
v_open text[] := ARRAY['voorraad_is_server','voorraad_vereis'];
|
|
8127
8215
|
v_func jsonb; v_trig jsonb; v_pol jsonb;
|
|
@@ -8157,7 +8245,7 @@ BEGIN
|
|
|
8157
8245
|
'policies_ontbrekend', (SELECT count(*) FROM jsonb_array_elements(v_pol) e WHERE NOT (e->>'aanwezig')::boolean),
|
|
8158
8246
|
'nog_zonder_controle_volgende_ronde', (SELECT COALESCE(jsonb_agg(e->>'functie' ORDER BY e->>'functie'), '[]'::jsonb) FROM jsonb_array_elements(v_func) e WHERE e->>'soort' = 'sql' AND NOT COALESCE((e->>'interne_controle')::boolean, false) AND NOT (e->>'functie' = ANY(v_open))),
|
|
8159
8247
|
'bewust_open', 'geen pickscherm/scanner-functies zonder inlog in Voorraad'),
|
|
8160
|
-
'correctie_1098', public.voorraad_correctie_status('1098'),
|
|
8248
|
+
'correctie_1098', public.voorraad_correctie_status('1098'), 'voorraad_context', public.voorraad_stock_context_status(),
|
|
8161
8249
|
'functies', v_func, 'triggers', v_trig, 'policies', v_pol);
|
|
8162
8250
|
END $function$
|
|
8163
8251
|
;
|
|
@@ -8334,6 +8422,29 @@ END $function$
|
|
|
8334
8422
|
REVOKE ALL ON FUNCTION voorraad_schema_ddl(text[],text[]) FROM PUBLIC;
|
|
8335
8423
|
REVOKE ALL ON FUNCTION voorraad_schema_ddl(text[],text[]) FROM anon;
|
|
8336
8424
|
GRANT EXECUTE ON FUNCTION voorraad_schema_ddl(text[],text[]) TO service_role;
|
|
8425
|
+
CREATE OR REPLACE FUNCTION public.voorraad_stock_context_status()
|
|
8426
|
+
RETURNS jsonb
|
|
8427
|
+
LANGUAGE plpgsql
|
|
8428
|
+
SECURITY DEFINER
|
|
8429
|
+
SET search_path TO 'public'
|
|
8430
|
+
AS $function$
|
|
8431
|
+
DECLARE v record;
|
|
8432
|
+
BEGIN
|
|
8433
|
+
PERFORM public.voorraad_vereis('ingelogd', 'voorraad_stock_context_status');
|
|
8434
|
+
BEGIN
|
|
8435
|
+
SELECT * INTO v FROM public.get_stock_context();
|
|
8436
|
+
RETURN jsonb_build_object('lokale_context_bestaat', EXISTS (SELECT 1 FROM public.voorraad_local_context WHERE singleton),
|
|
8437
|
+
'actief', v.context_kind, 'context_id', v.context_id);
|
|
8438
|
+
EXCEPTION WHEN others THEN
|
|
8439
|
+
RETURN jsonb_build_object('lokale_context_bestaat', EXISTS (SELECT 1 FROM public.voorraad_local_context WHERE singleton),
|
|
8440
|
+
'actief', 'fout', 'foutcode', SQLSTATE, 'melding', SQLERRM);
|
|
8441
|
+
END;
|
|
8442
|
+
END $function$
|
|
8443
|
+
;
|
|
8444
|
+
REVOKE ALL ON FUNCTION voorraad_stock_context_status() FROM PUBLIC;
|
|
8445
|
+
REVOKE ALL ON FUNCTION voorraad_stock_context_status() FROM anon;
|
|
8446
|
+
GRANT EXECUTE ON FUNCTION voorraad_stock_context_status() TO authenticated;
|
|
8447
|
+
GRANT EXECUTE ON FUNCTION voorraad_stock_context_status() TO service_role;
|
|
8337
8448
|
CREATE OR REPLACE FUNCTION public.voorraad_touch_updated_at()
|
|
8338
8449
|
RETURNS trigger
|
|
8339
8450
|
LANGUAGE plpgsql
|
|
@@ -8430,6 +8541,7 @@ DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'trade_i
|
|
|
8430
8541
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_buffer_state_pkey' AND conrelid = 'public.voorraad_buffer_state'::regclass) THEN ALTER TABLE public.voorraad_buffer_state ADD CONSTRAINT voorraad_buffer_state_pkey PRIMARY KEY (buffer_id); END IF; END $c$;
|
|
8431
8542
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_correcties_pkey' AND conrelid = 'public.voorraad_correcties'::regclass) THEN ALTER TABLE public.voorraad_correcties ADD CONSTRAINT voorraad_correcties_pkey PRIMARY KEY (id); END IF; END $c$;
|
|
8432
8543
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_custom_fields_pkey' AND conrelid = 'public.voorraad_custom_fields'::regclass) THEN ALTER TABLE public.voorraad_custom_fields ADD CONSTRAINT voorraad_custom_fields_pkey PRIMARY KEY (id); END IF; END $c$;
|
|
8544
|
+
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_local_context_pkey' AND conrelid = 'public.voorraad_local_context'::regclass) THEN ALTER TABLE public.voorraad_local_context ADD CONSTRAINT voorraad_local_context_pkey PRIMARY KEY (id); END IF; END $c$;
|
|
8433
8545
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_logistics_event_log_pkey' AND conrelid = 'public.voorraad_logistics_event_log'::regclass) THEN ALTER TABLE public.voorraad_logistics_event_log ADD CONSTRAINT voorraad_logistics_event_log_pkey PRIMARY KEY (event_id); END IF; END $c$;
|
|
8434
8546
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_media_upload_failures_pkey' AND conrelid = 'public.voorraad_media_upload_failures'::regclass) THEN ALTER TABLE public.voorraad_media_upload_failures ADD CONSTRAINT voorraad_media_upload_failures_pkey PRIMARY KEY (id); END IF; END $c$;
|
|
8435
8547
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_publish_attempts_pkey' AND conrelid = 'public.voorraad_publish_attempts'::regclass) THEN ALTER TABLE public.voorraad_publish_attempts ADD CONSTRAINT voorraad_publish_attempts_pkey PRIMARY KEY (id); END IF; END $c$;
|
|
@@ -8448,6 +8560,7 @@ DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'trade_i
|
|
|
8448
8560
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'trade_item_supply_lines_user_id_trade_item_id_key' AND conrelid = 'public.trade_item_supply_lines'::regclass) THEN ALTER TABLE public.trade_item_supply_lines ADD CONSTRAINT trade_item_supply_lines_user_id_trade_item_id_key UNIQUE (user_id, trade_item_id); END IF; END $c$;
|
|
8449
8561
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'trade_item_warehouse_preference_connection_id_trade_item_id_key' AND conrelid = 'public.trade_item_warehouse_preferences'::regclass) THEN ALTER TABLE public.trade_item_warehouse_preferences ADD CONSTRAINT trade_item_warehouse_preference_connection_id_trade_item_id_key UNIQUE (connection_id, trade_item_id); END IF; END $c$;
|
|
8450
8562
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_custom_fields_field_key_key' AND conrelid = 'public.voorraad_custom_fields'::regclass) THEN ALTER TABLE public.voorraad_custom_fields ADD CONSTRAINT voorraad_custom_fields_field_key_key UNIQUE (field_key); END IF; END $c$;
|
|
8563
|
+
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_local_context_singleton_key' AND conrelid = 'public.voorraad_local_context'::regclass) THEN ALTER TABLE public.voorraad_local_context ADD CONSTRAINT voorraad_local_context_singleton_key UNIQUE (singleton); END IF; END $c$;
|
|
8451
8564
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_publish_learnings_vbn_code_scope_field_key_key' AND conrelid = 'public.voorraad_publish_learnings'::regclass) THEN ALTER TABLE public.voorraad_publish_learnings ADD CONSTRAINT voorraad_publish_learnings_vbn_code_scope_field_key_key UNIQUE (vbn_code, scope, field_key); END IF; END $c$;
|
|
8452
8565
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_publish_steps_job_id_step_key_key' AND conrelid = 'public.voorraad_publish_steps'::regclass) THEN ALTER TABLE public.voorraad_publish_steps ADD CONSTRAINT voorraad_publish_steps_job_id_step_key_key UNIQUE (job_id, step_key); END IF; END $c$;
|
|
8453
8566
|
ALTER TABLE public.floriday_continuous_stock_queue DROP CONSTRAINT IF EXISTS floriday_continuous_stock_queue_status_check;
|
|
@@ -8492,6 +8605,8 @@ ALTER TABLE public.stock_mutation_log DROP CONSTRAINT IF EXISTS stock_mutation_l
|
|
|
8492
8605
|
ALTER TABLE public.stock_mutation_log ADD CONSTRAINT stock_mutation_log_mutation_type_check CHECK ((mutation_type = ANY (ARRAY['reservation'::text, 'reservation_release'::text, 'consumption'::text, 'stock_check'::text, 'reservation_skipped'::text, 'consumption_skipped'::text, 'consumption_blocked'::text, 'production_consume'::text, 'production_output'::text, 'production_reverse'::text, 'manual_correction'::text, 'order_sync'::text, 'import'::text, 'production'::text, 'stock_update'::text, 'reservation_recompute'::text, 'unknown'::text, 'consumption_done'::text, 'new_article'::text])));
|
|
8493
8606
|
ALTER TABLE public.trade_item_drafts DROP CONSTRAINT IF EXISTS trade_item_drafts_link_status_chk;
|
|
8494
8607
|
ALTER TABLE public.trade_item_drafts ADD CONSTRAINT trade_item_drafts_link_status_chk CHECK ((floriday_link_status = ANY (ARRAY['unlinked'::text, 'linked'::text, 'waiting_for_data'::text, 'ready_to_publish'::text, 'publish_failed'::text, 'ambiguous_match'::text, 'published'::text])));
|
|
8608
|
+
ALTER TABLE public.voorraad_local_context DROP CONSTRAINT IF EXISTS voorraad_local_context_singleton_check;
|
|
8609
|
+
ALTER TABLE public.voorraad_local_context ADD CONSTRAINT voorraad_local_context_singleton_check CHECK (singleton);
|
|
8495
8610
|
DO $g$ BEGIN IF to_regclass('public.products') IS NULL THEN RAISE NOTICE 'Voorraad: products (core) ontbreekt, controles overgeslagen; draai de schema-update opnieuw na die module'; ELSE EXECUTE $q$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'floriday_inventory_settings_product_id_fkey' AND conrelid = 'public.floriday_inventory_settings'::regclass) THEN ALTER TABLE public.floriday_inventory_settings ADD CONSTRAINT floriday_inventory_settings_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$q$; END IF; END $g$;
|
|
8496
8611
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'floriday_takeover_items_run_id_fkey' AND conrelid = 'public.floriday_takeover_items'::regclass) THEN ALTER TABLE public.floriday_takeover_items ADD CONSTRAINT floriday_takeover_items_run_id_fkey FOREIGN KEY (run_id) REFERENCES floriday_takeover_runs(id) ON DELETE CASCADE; END IF; END $c$;
|
|
8497
8612
|
DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'floriday_vbn_required_characteristics_updated_by_fkey' AND conrelid = 'public.floriday_vbn_required_characteristics'::regclass) THEN ALTER TABLE public.floriday_vbn_required_characteristics ADD CONSTRAINT floriday_vbn_required_characteristics_updated_by_fkey FOREIGN KEY (updated_by) REFERENCES auth.users(id) ON DELETE SET NULL; END IF; END $c$;
|
|
@@ -8678,6 +8793,9 @@ ALTER TABLE public.voorraad_custom_fields ENABLE ROW LEVEL SECURITY;
|
|
|
8678
8793
|
REVOKE ALL ON public.voorraad_custom_fields FROM anon;
|
|
8679
8794
|
GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_custom_fields TO authenticated;
|
|
8680
8795
|
GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_custom_fields TO service_role;
|
|
8796
|
+
ALTER TABLE public.voorraad_local_context ENABLE ROW LEVEL SECURITY;
|
|
8797
|
+
GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_local_context TO authenticated;
|
|
8798
|
+
GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_local_context TO service_role;
|
|
8681
8799
|
ALTER TABLE public.voorraad_logistics_event_log ENABLE ROW LEVEL SECURITY;
|
|
8682
8800
|
REVOKE ALL ON public.voorraad_logistics_event_log FROM anon;
|
|
8683
8801
|
GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_logistics_event_log TO authenticated;
|
|
@@ -8818,6 +8936,8 @@ DROP POLICY IF EXISTS "Authenticated can read voorraad custom fields" ON public.
|
|
|
8818
8936
|
CREATE POLICY "Authenticated can read voorraad custom fields" ON public.voorraad_custom_fields AS PERMISSIVE FOR SELECT TO authenticated USING (true);
|
|
8819
8937
|
DROP POLICY IF EXISTS "Authenticated can update voorraad custom fields" ON public.voorraad_custom_fields;
|
|
8820
8938
|
CREATE POLICY "Authenticated can update voorraad custom fields" ON public.voorraad_custom_fields AS PERMISSIVE FOR UPDATE TO authenticated USING (true) WITH CHECK (true);
|
|
8939
|
+
DROP POLICY IF EXISTS "Lokale context lezen" ON public.voorraad_local_context;
|
|
8940
|
+
CREATE POLICY "Lokale context lezen" ON public.voorraad_local_context AS PERMISSIVE FOR SELECT TO authenticated USING (true);
|
|
8821
8941
|
DROP POLICY IF EXISTS "Ingelogde gebruikers kunnen de eventlog lezen" ON public.voorraad_logistics_event_log;
|
|
8822
8942
|
CREATE POLICY "Ingelogde gebruikers kunnen de eventlog lezen" ON public.voorraad_logistics_event_log AS PERMISSIVE FOR SELECT TO authenticated USING (true);
|
|
8823
8943
|
DROP POLICY IF EXISTS "service role only" ON public.voorraad_media_upload_failures;
|
|
@@ -8841,6 +8961,8 @@ CREATE POLICY "Users manage their own publish steps" ON public.voorraad_publish_
|
|
|
8841
8961
|
DO $g$ BEGIN IF to_regclass('public.cart_control_sessions') IS NULL THEN RAISE NOTICE 'Voorraad: cart_control_sessions (andere module) ontbreekt, triggers overgeslagen; draai de schema-update opnieuw na die module'; ELSE EXECUTE $q$CREATE TRIGGER trg_cart_session_consume AFTER UPDATE OF stock_consumed_at ON public.cart_control_sessions FOR EACH ROW EXECUTE FUNCTION trg_cart_session_consume_fn()$q$; END IF; END $g$;
|
|
8842
8962
|
DO $g$ BEGIN IF to_regclass('public.cart_numbers') IS NULL THEN RAISE NOTICE 'Voorraad: cart_numbers (andere module) ontbreekt, triggers overgeslagen; draai de schema-update opnieuw na die module'; ELSE EXECUTE $q$CREATE TRIGGER trg_cart_numbers_sync_order_status AFTER INSERT OR DELETE OR UPDATE OF status ON public.cart_numbers FOR EACH ROW EXECUTE FUNCTION trg_cart_numbers_sync_order_status_fn()$q$; END IF; END $g$;
|
|
8843
8963
|
DO $g$ BEGIN IF to_regclass('public.floriday_connections') IS NULL THEN RAISE NOTICE 'Voorraad: floriday_connections (Floriday-auth) ontbreekt, triggers overgeslagen; draai de schema-update opnieuw na die module'; ELSE EXECUTE $q$CREATE TRIGGER trg_requeue_no_warehouse_connection AFTER UPDATE OF preferred_warehouse_id ON public.floriday_connections FOR EACH ROW EXECUTE FUNCTION trg_requeue_no_warehouse_connection()$q$; END IF; END $g$;
|
|
8964
|
+
DROP TRIGGER IF EXISTS aa0_fcsq_local_context_guard ON public.floriday_continuous_stock_queue;
|
|
8965
|
+
CREATE TRIGGER aa0_fcsq_local_context_guard BEFORE INSERT ON public.floriday_continuous_stock_queue FOR EACH ROW EXECUTE FUNCTION voorraad_fcsq_local_guard();
|
|
8844
8966
|
DROP TRIGGER IF EXISTS aa_fcsq_erp_leading_guard ON public.floriday_continuous_stock_queue;
|
|
8845
8967
|
CREATE TRIGGER aa_fcsq_erp_leading_guard BEFORE INSERT OR UPDATE OF status ON public.floriday_continuous_stock_queue FOR EACH ROW EXECUTE FUNCTION floriday_queue_erp_guard();
|
|
8846
8968
|
DROP TRIGGER IF EXISTS fcsq_block_disabled ON public.floriday_continuous_stock_queue;
|