From c52d5b5020ed1abc6736decc841b60a5db028558 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. --- C4/Serials.pm | 47 ++++++++++------------------------------- serials/claims.pl | 2 +- t/db_dependent/Serials.t | 3 --- t/db_dependent/Serials/Claims.t | 14 +++++++++++- 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 72dc44b..c77826d 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -52,7 +52,6 @@ BEGIN { &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected - &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid &GetDistributedTo &SetDistributedTo &getroutinglist &delroutingmember &addroutingmember @@ -235,34 +234,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 = 7, - claims_count = claims_count + 1 - WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ") - "; - my $rq = $dbh->prepare($query); - $rq->execute($date, @$serialids); - return $rq->rows; -} - =head2 GetSubscription $subs = GetSubscription($subscriptionid) @@ -1963,15 +1934,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 = 7 + WHERE serialid in (| . join( q|,|, (q|?|) x @$serialids ) . q|)|, + {}, @$serialids ); } =head2 getsupplierbyserialid diff --git a/serials/claims.pl b/serials/claims.pl index fb3bcd9..d85dd51 100755 --- a/serials/claims.pl +++ b/serials/claims.pl @@ -64,7 +64,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 4777116..132a682 100644 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -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'); @@ -184,8 +183,6 @@ is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing i is(C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue'); -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 622f910..b887d78 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.1.0