View | Details | Raw Unified | Return to bug 33236
Collapse All | Expand All

(-)a/C4/Serials.pm (-4 / +5 lines)
Lines 41-46 use Koha::Biblios; Link Here
41
use Koha::Serial;
41
use Koha::Serial;
42
use Koha::Subscriptions;
42
use Koha::Subscriptions;
43
use Koha::Subscription::Histories;
43
use Koha::Subscription::Histories;
44
use Koha::Suggestions;
44
use Koha::SharedContent;
45
use Koha::SharedContent;
45
use Scalar::Util qw( looks_like_number );
46
use Scalar::Util qw( looks_like_number );
46
47
Lines 1528-1536 sub ReNewSubscription { Link Here
1528
    my $biblio = $sth->fetchrow_hashref;
1529
    my $biblio = $sth->fetchrow_hashref;
1529
1530
1530
    if ( C4::Context->preference("RenewSerialAddsSuggestion") ) {
1531
    if ( C4::Context->preference("RenewSerialAddsSuggestion") ) {
1531
        require C4::Suggestions;
1532
        Koha::Suggestion->new(
1532
        C4::Suggestions::NewSuggestion(
1533
            {
1533
            {   'suggestedby'   => $user,
1534
                'suggestedby'   => $user,
1534
                'title'         => $subscription->{bibliotitle},
1535
                'title'         => $subscription->{bibliotitle},
1535
                'author'        => $biblio->{author},
1536
                'author'        => $biblio->{author},
1536
                'publishercode' => $biblio->{publishercode},
1537
                'publishercode' => $biblio->{publishercode},
Lines 1538-1544 sub ReNewSubscription { Link Here
1538
                'biblionumber'  => $subscription->{biblionumber},
1539
                'biblionumber'  => $subscription->{biblionumber},
1539
                'branchcode'    => $branchcode,
1540
                'branchcode'    => $branchcode,
1540
            }
1541
            }
1541
        );
1542
        )->store;
1542
    }
1543
    }
1543
1544
1544
    $numberlength ||= 0; # Should not we raise an exception instead?
1545
    $numberlength ||= 0; # Should not we raise an exception instead?
(-)a/Koha/Suggestion.pm (-1 / +1 lines)
Lines 48-54 sub store { Link Here
48
48
49
    $self->STATUS("ASKED") unless $self->STATUS;
49
    $self->STATUS("ASKED") unless $self->STATUS;
50
50
51
    $self->branchcode(undef) if $self->branchcode eq '';
51
    $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
52
    unless ( $self->suggesteddate() ) {
52
    unless ( $self->suggesteddate() ) {
53
        $self->suggesteddate( dt_from_string()->ymd );
53
        $self->suggesteddate( dt_from_string()->ymd );
54
    }
54
    }
(-)a/t/db_dependent/Serials/ReNewSubscription.t (-9 / +26 lines)
Lines 22-28 Link Here
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
24
25
use Test::More tests => 7;
25
use Test::More tests => 10;
26
use Test::MockModule;
26
use Test::MockModule;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
28
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 85-92 my $subscriptionhistory = $builder->build({ Link Here
85
    }
85
    }
86
});
86
});
87
87
88
t::lib::Mocks::mock_preference( 'RenewSerialAddsSuggestion', '0' );
89
my $suggestions_count = Koha::Suggestions->search()->count;
90
88
# Actual testing starts here!
91
# Actual testing starts here!
89
# Renew the subscription and check that enddate has not been set
92
# Renew the subscription and check that enddate has been set
93
ReNewSubscription(
94
    {
95
        subscriptionid => $subscription->{subscriptionid},
96
        startdate      => "2016-01-01",
97
        monthlength    => 12
98
    }
99
);
100
101
$subscription = Koha::Subscriptions->find( $subscription->{subscriptionid} );
102
is( $subscription->enddate, '2017-01-01', "We don't update the subscription end date when renewing with a month length");
103
104
is( $suggestions_count, Koha::Suggestions->search()->count, "Suggestion not added when RenewSerialAddsSuggestion set to Don't add");
105
106
t::lib::Mocks::mock_preference( 'RenewSerialAddsSuggestion', '1' );
107
90
ReNewSubscription(
108
ReNewSubscription(
91
    {
109
    {
92
        subscriptionid => $subscription->{subscriptionid},
110
        subscriptionid => $subscription->{subscriptionid},
Lines 95-101 ReNewSubscription( Link Here
95
    }
113
    }
96
);
114
);
97
115
116
is( $suggestions_count + 1, Koha::Suggestions->search()->count, "Suggestion added when RenewSerialAddsSuggestion set to add");
117
118
my $history = Koha::Subscription::Histories->find($subscription->subscriptionid);
119
120
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
98
# Calculate the subscription length for the renewal for issues, days and months
121
# Calculate the subscription length for the renewal for issues, days and months
122
99
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 7);
123
my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('issues', 7);
100
is ( $numberlength, 7, "Subscription length is 7 issues");
124
is ( $numberlength, 7, "Subscription length is 7 issues");
101
125
Lines 117-128 is ($monthlength, undef, "Subscription length is undef issues, invalid issue dat Link Here
117
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', '!');
141
($numberlength, $weeklength, $monthlength) = GetSubscriptionLength('weeks', '!');
118
is ($weeklength, undef, "Subscription length is undef weeks, invalid weeks data was not stored");
142
is ($weeklength, undef, "Subscription length is undef weeks, invalid weeks data was not stored");
119
143
120
# Renew the subscription and check that enddate has not been set
121
122
my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
123
124
is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
125
126
# End of tests
144
# End of tests
127
145
128
$schema->storage->txn_rollback;
146
$schema->storage->txn_rollback;
129
- 

Return to bug 33236