@@ -, +, @@ bug Added a new sub to Serials.pm to be able to get serials with their statuses. Now the sub ModSerialStatus checks for other serials with an "expected" status before doing anything. Also modified Serials.t to be able to test those changes. Test Plan 1) Apply patch 2) Run ./t/db_dependent/Serials.t 3) Validate that there are no errors 4) Go on "Serial collection information" page for a serial of your choice 5) Click on "Generate next" 6) Change the status of the original serial from "late" to "expected" 7) Change the newly generated serial from "expected" to "delete" 8) Validate that there are no new serials created by instruction 7 and that the serial was deleted --- C4/Serials.pm | 24 ++++++++++++++++++++++-- t/db_dependent/Serials.t | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) mode change 100644 => 100755 t/db_dependent/Serials.t --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -1125,8 +1125,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(1, $subscriptionid); + if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); @@ -2731,6 +2733,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 = qq| SELECT * from serial + WHERE status = ? + AND subscriptionid = ? + |; + my $sth = $dbh->prepare($query); + $sth->execute($status, $subscriptionid); + return @{$sth->fetchall_arrayref({})}; +} 1; __END__ --- a/t/db_dependent/Serials.t +++ a/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 => 46; +use Test::More tests => 48; BEGIN { use_ok('C4::Serials'); @@ -190,6 +190,7 @@ is(C4::Serials::check_routing(), undef, 'test checking route'); is(C4::Serials::addroutingmember(),undef, 'test adding route member'); +is( C4::Serials::findSerialByStatus() ,0, "test finding a serial by its status"); # Unit tests for statuses management (Bug 11689) $subscriptionid = NewSubscription( @@ -246,4 +247,5 @@ for my $am ( @arrived_missing ) { } is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" ); +is( C4::Serials::findSerialByStatus(2,$subscriptionid) ,2, "findSerialByStatus returns array of serials if status and subscriptionid is given"); $dbh->rollback; --