diff --git a/C4/Serials.pm b/C4/Serials.pm index 237e459b84..816213c1ad 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1172,8 +1172,10 @@ sub ModSerialStatus { } } - # create new waited entry if needed (ie : was a "waited" and has changed) - if ( $oldstatus == EXPECTED && $status != EXPECTED ) { + # create new expected entry if needed (ie : was "expected" and has changed) + # BUG 12748: Check if there are no other expected issues. + my $otherIssueExpected = scalar findSerialByStatus(EXPECTED, $subscriptionid); + if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); @@ -2670,6 +2672,24 @@ sub _can_do_on_subscription { return 0; } +=head2 findSerialByStatus + + @serials = findSerialByStatus($status, $subscriptionid); + + Returns an array of serials matching a given status and subscription id. + +=cut + +sub findSerialByStatus{ + my($status, $subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $query = q| SELECT * from serial + WHERE status = ? + AND subscriptionid = ? + |; + my $serials = $dbh->selectall_arrayref( $query, { Slice => {} }, $status, $subscriptionid ); + return @$serials; +} 1; __END__ diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t old mode 100644 new mode 100755 index 1f3ebb0e86..b350ccd648 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -15,7 +15,7 @@ use C4::Bookseller; use C4::Biblio; use C4::Budgets; use Koha::DateUtils; -use Test::More tests => 45; +use Test::More tests => 48; BEGIN { use_ok('C4::Serials'); @@ -173,6 +173,7 @@ is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription hist is(C4::Serials::ModSerialStatus(),undef, 'test modding serials'); +is(C4::Serials::findSerialByStatus(), 0, 'test finding serial by status with no parameters'); is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered'); is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired'); @@ -218,6 +219,8 @@ for my $status ( @statuses ) { $counter++; } # Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1 +my @serialsByStatus = C4::Serials::findSerialByStatus(2,$subscriptionid); +is(@serialsByStatus,2,"findSerialByStatus returns all serials with chosen status"); ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); my @arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;