CREATE OR REPLACE FUNCTION core.items_unit_check_trigger()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
IF(core.get_root_unit_id(NEW.unit_id) != core.get_root_unit_id(NEW.reorder_unit_id)) THEN
RAISE EXCEPTION 'Acess is denied. The reorder unit is incompatible with the base unit.';
END IF;
RETURN NEW;
END
$function$