my $closest_cn = $_storage->request(
"open-ils.cstore.direct.asset.call_number.search.atomic",
{ label => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } },
- owning_lib => $ou_ids,
+ (scalar(@$ou_ids) ? (owning_lib => $ou_ids) : ()),
deleted => 'f',
@$cp_filter
},
my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
- my $o_search = { shortname => $ou };
- if (!$ou || $ou eq '-') {
- $o_search = { parent_ou => undef };
- }
-
- my $orgs = $_storage->request(
- "open-ils.cstore.direct.actor.org_unit.search",
- $o_search,
- { flesh => 100,
- flesh_fields => { aou => [qw/children/] }
- }
- )->gather(1);
+ my @ou_ids;
+ # if OU is not specified, or if '-' is specified, do not enter the block
+ unless (!$ou || $ou eq '-') {
+ # check if the shortname of the top org_unit is specified
+ my $top_org = $_storage->request(
+ "open-ils.cstore.direct.actor.org_unit.search",
+ { parent_ou => undef }
+ )->gather(1);
+
+ if ($ou eq $top_org->shortname) {
+ $logger->debug("Searching for CNs at top org $ou");
+ } else {
+ my $o_search = { shortname => $ou };
+
+ my $orgs = $_storage->request(
+ "open-ils.cstore.direct.actor.org_unit.search",
+ $o_search,
+ { flesh => 100,
+ flesh_fields => { aou => [qw/children/] }
+ }
+ )->gather(1);
- my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
+ @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
- $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
+ $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
+ }
+ }
my @list = ();
my $before = $_storage->request(
"open-ils.cstore.direct.asset.call_number.search.atomic",
{ label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
- owning_lib => \@ou_ids,
+ (scalar(@ou_ids) ? (owning_lib => \@ou_ids) : ()),
deleted => 'f',
@cp_filter
},
my $after = $_storage->request(
"open-ils.cstore.direct.asset.call_number.search.atomic",
{ label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
- owning_lib => \@ou_ids,
+ (scalar(@ou_ids) ? (owning_lib => \@ou_ids) : ()),
deleted => 'f',
@cp_filter
},