Bug 33236: (follow-up) Handle new suggestion in ReNewSubscription
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
4880f2d91d
commit
882aa3eb8a
|
|
@ -41,6 +41,7 @@ use Koha::Biblios;
|
|||
use Koha::Serial;
|
||||
use Koha::Subscriptions;
|
||||
use Koha::Subscription::Histories;
|
||||
use Koha::Suggestions;
|
||||
use Koha::SharedContent;
|
||||
use Scalar::Util qw( looks_like_number );
|
||||
|
||||
|
|
@ -1528,9 +1529,9 @@ sub ReNewSubscription {
|
|||
my $biblio = $sth->fetchrow_hashref;
|
||||
|
||||
if ( C4::Context->preference("RenewSerialAddsSuggestion") ) {
|
||||
require C4::Suggestions;
|
||||
C4::Suggestions::NewSuggestion(
|
||||
{ 'suggestedby' => $user,
|
||||
Koha::Suggestion->new(
|
||||
{
|
||||
'suggestedby' => $user,
|
||||
'title' => $subscription->{bibliotitle},
|
||||
'author' => $biblio->{author},
|
||||
'publishercode' => $biblio->{publishercode},
|
||||
|
|
@ -1538,7 +1539,7 @@ sub ReNewSubscription {
|
|||
'biblionumber' => $subscription->{biblionumber},
|
||||
'branchcode' => $branchcode,
|
||||
}
|
||||
);
|
||||
)->store;
|
||||
}
|
||||
|
||||
$numberlength ||= 0; # Should not we raise an exception instead?
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ sub store {
|
|||
|
||||
$self->STATUS("ASKED") unless $self->STATUS;
|
||||
|
||||
$self->branchcode(undef) if $self->branchcode eq '';
|
||||
$self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
|
||||
unless ( $self->suggesteddate() ) {
|
||||
$self->suggesteddate( dt_from_string()->ymd );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 7;
|
||||
use Test::More tests => 10;
|
||||
use Test::MockModule;
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
|
@ -85,8 +85,11 @@ my $subscriptionhistory = $builder->build({
|
|||
}
|
||||
});
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RenewSerialAddsSuggestion', '0' );
|
||||
my $suggestions_count = Koha::Suggestions->search()->count;
|
||||
|
||||
# Actual testing starts here!
|
||||
# Renew the subscription and check that enddate has not been set
|
||||
# Renew the subscription and check that enddate has been set
|
||||
ReNewSubscription(
|
||||
{
|
||||
subscriptionid => $subscription->{subscriptionid},
|
||||
|
|
@ -95,7 +98,28 @@ ReNewSubscription(
|
|||
}
|
||||
);
|
||||
|
||||
$subscription = Koha::Subscriptions->find( $subscription->{subscriptionid} );
|
||||
is( $subscription->enddate, '2017-01-01', "We don't update the subscription end date when renewing with a month length");
|
||||
|
||||
is( $suggestions_count, Koha::Suggestions->search()->count, "Suggestion not added when RenewSerialAddsSuggestion set to Don't add");
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RenewSerialAddsSuggestion', '1' );
|
||||
|
||||
ReNewSubscription(
|
||||
{
|
||||
subscriptionid => $subscription->{subscriptionid},
|
||||
startdate => "2016-01-01",
|
||||
monthlength => 12
|
||||
}
|
||||
);
|
||||
|
||||
is( $suggestions_count + 1, Koha::Suggestions->search()->count, "Suggestion added when RenewSerialAddsSuggestion set to add");
|
||||
|
||||
my $history = Koha::Subscription::Histories->find($subscription->subscriptionid);
|
||||
|
||||
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
|
||||
# Calculate the subscription length for the renewal for issues, days and months
|
||||
|
||||
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 7);
|
||||
is ( $numberlength, 7, "Subscription length is 7 issues");
|
||||
|
||||
|
|
@ -117,12 +141,6 @@ is ($monthlength, undef, "Subscription length is undef issues, invalid issue dat
|
|||
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', '!');
|
||||
is ($weeklength, undef, "Subscription length is undef weeks, invalid weeks data was not stored");
|
||||
|
||||
# Renew the subscription and check that enddate has not been set
|
||||
|
||||
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
|
||||
|
||||
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
|
||||
|
||||
# End of tests
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue