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

(-)a/Koha/Suggestion.pm (+25 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Letters;
23
use C4::Letters;
24
use C4::Reserves qw( AddReserve );
24
25
25
use Koha::Database;
26
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
Lines 207-212 sub fund { Link Here
207
    return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
208
    return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
208
}
209
}
209
210
211
=head3 place_hold
212
213
my $hold_id = $suggestion->place_hold();
214
215
Places a hold for the suggester if the suggestion is tied to a biblio.
216
217
=cut
218
219
sub place_hold {
220
    my ($self) = @_;
221
222
    return unless C4::Context->preference('PlaceHoldsOnOrdersFromSuggestions');
223
    return unless $self->biblionumber;
224
225
    my $hold_id = AddReserve(
226
        {
227
            borrowernumber => $self->suggestedby,
228
            biblionumber   => $self->biblionumber,
229
            branchcode     => $self->branchcode,
230
            title          => $self->title,
231
        }
232
    );
233
}
234
210
=head3 type
235
=head3 type
211
236
212
=cut
237
=cut
(-)a/t/db_dependent/Suggestions.t (-2 / +47 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::More tests => 91;
21
use Test::More tests => 92;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 29-34 use C4::Letters qw( GetQueuedMessages GetMessage ); Link Here
29
use C4::Budgets qw( AddBudgetPeriod AddBudget GetBudget );
29
use C4::Budgets qw( AddBudgetPeriod AddBudget GetBudget );
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::DateUtils qw( dt_from_string output_pref );
32
use Koha::Holds;
32
use Koha::Libraries;
33
use Koha::Libraries;
33
use Koha::Patrons;
34
use Koha::Patrons;
34
use Koha::Suggestions;
35
use Koha::Suggestions;
Lines 594-599 subtest 'ModSuggestion should work on suggestions without a suggester' => sub { Link Here
594
    is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" );
595
    is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" );
595
};
596
};
596
597
598
subtest 'place_hold tests' => sub {
599
    plan tests => 4;
600
601
    t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "0" );
602
603
    my $biblio     = $builder->build_sample_biblio();
604
    my $patron     = $builder->build_object( { class => 'Koha::Patrons' } );
605
    my $suggestion = $builder->build_object(
606
        {
607
            class => 'Koha::Suggestions',
608
            value => {
609
                branchcode   => $patron->branchcode,
610
                biblionumber => undef,
611
                suggestedby  => $patron->id
612
            }
613
        }
614
    );
615
616
    my $hold_id = $suggestion->place_hold();
617
    is( $hold_id, undef, "No suggestion placed when preference is disabled" );
618
619
    t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "1" );
620
621
    $hold_id = $suggestion->place_hold();
622
    is(
623
        $hold_id, undef,
624
        "No suggestion placed when preference is enabled and suggestion does not have a biblionumber"
625
    );
626
627
    $suggestion->biblionumber( $biblio->id )->store();
628
    $suggestion->discard_changes();
629
630
    $hold_id = $suggestion->place_hold();
631
    ok( $hold_id, "Suggestion placed when preference is enabled and suggestion does have a biblionumber" );
632
633
    my $hold = Koha::Holds->find($hold_id);
634
    $hold->delete();
635
636
    t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "0" );
637
638
    $hold_id = $suggestion->place_hold();
639
    is( $hold_id, undef, "Suggestion not placed when preference is disabled and suggestion does have a biblionumber" );
640
641
};
642
597
subtest 'Suggestion with ISBN' => sub {
643
subtest 'Suggestion with ISBN' => sub {
598
    my $suggestion_with_isbn = {
644
    my $suggestion_with_isbn = {
599
        isbn     => '1940997232',
645
        isbn     => '1940997232',
600
- 

Return to bug 27595