From b416ac16b5c67d902444041882c31a99e0525fa0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 28 Apr 2015 17:00:44 +0200 Subject: [PATCH] Bug 12178: Update serial status to "claimed" when exporting to CSV On the same way as late issues, the serial status should be updated to 'claimed' when the issues as exported as csv. QA note: The updateClaim and UpdateClaimdateIssues subroutine did almost the same thing, I kick the second on off to centralize the code. Test plan: 1/ Export some late issues as CSV (serials/claims.pl). 2/ Refresh the page (the export does not do it) and confirm that the status, the claim date and the claim count have been updated. 3/ Select some others issues, select a notice and send the notification. Confirm that the behavior is the same. Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall --- C4/Serials.pm | 47 ++++++++------------------------- serials/claims.pl | 2 +- t/db_dependent/Serials.t | 5 +--- t/db_dependent/Serials/Claims.t | 14 +++++++++- 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 02349a4c64..35d62c9605 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -77,7 +77,6 @@ BEGIN { &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected - &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid &GetDistributedTo &SetDistributedTo &getroutinglist &delroutingmember &addroutingmember @@ -261,34 +260,6 @@ sub AddItem2Serial { return $rq->rows; } -=head2 UpdateClaimdateIssues - -UpdateClaimdateIssues($serialids,[$date]); - -Update Claimdate for issues in @$serialids list with date $date -(Take Today if none) - -=cut - -sub UpdateClaimdateIssues { - my ( $serialids, $date ) = @_; - - return unless ($serialids); - - my $dbh = C4::Context->dbh; - $date = strftime( "%Y-%m-%d", localtime ) unless ($date); - my $query = " - UPDATE serial - SET claimdate = ?, - status = ?, - claims_count = claims_count + 1 - WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ") - "; - my $rq = $dbh->prepare($query); - $rq->execute($date, CLAIMED, @$serialids); - return $rq->rows; -} - =head2 GetSubscription $subs = GetSubscription($subscriptionid) @@ -1895,15 +1866,19 @@ called from claims.pl file =cut sub updateClaim { - my ($serialid) = @_; - my $dbh = C4::Context->dbh; - $dbh->do(q| + my ($serialids) = @_; + return unless $serialids; + unless ( ref $serialids ) { + $serialids = [ $serialids ]; + } + my $dbh = C4::Context->dbh; + return $dbh->do(q| UPDATE serial SET claimdate = NOW(), - claims_count = claims_count + 1 - WHERE serialid = ? - |, {}, $serialid ); - return; + claims_count = claims_count + 1, + status = ? + WHERE serialid in (| . join( q|,|, (q|?|) x @$serialids ) . q|)|, + {}, CLAIMED, @$serialids ); } =head2 getsupplierbyserialid diff --git a/serials/claims.pl b/serials/claims.pl index 1a0c5cfaa3..3c5f738f3f 100755 --- a/serials/claims.pl +++ b/serials/claims.pl @@ -73,7 +73,7 @@ if (@serialnums) { # i.e. they have been flagged to generate claims eval { $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code")); if ( not ref $err or not exists $err->{error} ) { - UpdateClaimdateIssues(\@serialnums); + C4::Serials::updateClaim( \@serialnums ); } }; if ( $@ ) { diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index b053681f9c..a144ec98e3 100755 --- 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 => 48; +use Test::More tests => 46; BEGIN { use_ok('C4::Serials'); @@ -151,7 +151,6 @@ if ($old_frequency) { # Test calling subs without parameters is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial'); -is(C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date'); is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription'); is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data'); is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number'); @@ -182,8 +181,6 @@ is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues'); -is(C4::Serials::updateClaim(),undef, 'test updating claim'); - is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea'); is(C4::Serials::check_routing(), undef, 'test checking route'); diff --git a/t/db_dependent/Serials/Claims.t b/t/db_dependent/Serials/Claims.t index 622f91021e..b887d78a05 100644 --- a/t/db_dependent/Serials/Claims.t +++ b/t/db_dependent/Serials/Claims.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 17; use C4::Acquisition; use C4::Bookseller; @@ -135,6 +135,7 @@ is( exists $late_or_missing_issues[0]->{claimdate}, 1, 'GetLateOrMissingIssues r is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' ); is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' ); +is( updateClaim(), undef, 'updateClaim should return undef if not param passed' ); my $serialid_to_claim = $late_or_missing_issues[0]->{serialid}; updateClaim( $serialid_to_claim ); @@ -144,6 +145,17 @@ is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues; is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' ); +my @serials_to_claim = map { $_->{serialid} } @late_or_missing_issues; +updateClaim( \@serials_to_claim ); +@late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2); +is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late' ); + +( $serial_claimed ) = grep { ($_->{serialid} == $serials_to_claim[0]) ? $_ : () } @late_or_missing_issues; +is( $serial_claimed->{claims_count}, 2, 'The serial should have been claimed' ); +( $serial_claimed ) = grep { ($_->{serialid} == $serials_to_claim[1]) ? $_ : () } @late_or_missing_issues; +is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' ); + + my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); # FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format! #is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' ); -- 2.39.5