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

(-)a/C4/Acquisition.pm (-1 / +1 lines)
Lines 21-27 use Modern::Perl; Link Here
21
use Carp qw( carp croak );
21
use Carp qw( carp croak );
22
use Text::CSV_XS;
22
use Text::CSV_XS;
23
use C4::Context;
23
use C4::Context;
24
use C4::Suggestions qw( GetSuggestion GetSuggestionFromBiblionumber ModSuggestion );
24
use C4::Suggestions qw( GetSuggestionFromBiblionumber ModSuggestion );
25
use C4::Biblio      qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal );
25
use C4::Biblio      qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal );
26
use C4::Contract    qw( GetContract );
26
use C4::Contract    qw( GetContract );
27
use C4::Log         qw( logaction );
27
use C4::Log         qw( logaction );
(-)a/C4/Suggestions.pm (-26 / +1 lines)
Lines 34-40 use base qw(Exporter); Link Here
34
our @EXPORT = qw(
34
our @EXPORT = qw(
35
    ConnectSuggestionAndBiblio
35
    ConnectSuggestionAndBiblio
36
    DelSuggestion
36
    DelSuggestion
37
    GetSuggestion
38
    GetSuggestionByStatus
37
    GetSuggestionByStatus
39
    GetSuggestionFromBiblionumber
38
    GetSuggestionFromBiblionumber
40
    GetSuggestionInfoFromBiblionumber
39
    GetSuggestionInfoFromBiblionumber
Lines 71-100 Suggestions done by other borrowers can be seen when not "AVAILABLE" Link Here
71
70
72
=head1 FUNCTIONS
71
=head1 FUNCTIONS
73
72
74
=head2 GetSuggestion
75
76
\%sth = &GetSuggestion($suggestionid)
77
78
this function get the detail of the suggestion $suggestionid (input arg)
79
80
return :
81
    the result of the SQL query as a hash : $sth->fetchrow_hashref.
82
83
=cut
84
85
sub GetSuggestion {
86
    my ($suggestionid) = @_;
87
    my $dbh            = C4::Context->dbh;
88
    my $query          = q{
89
        SELECT *
90
        FROM   suggestions
91
        WHERE  suggestionid=?
92
    };
93
    my $sth = $dbh->prepare($query);
94
    $sth->execute($suggestionid);
95
    return ( $sth->fetchrow_hashref );
96
}
97
98
=head2 GetSuggestionFromBiblionumber
73
=head2 GetSuggestionFromBiblionumber
99
74
100
$ordernumber = &GetSuggestionFromBiblionumber($biblionumber)
75
$ordernumber = &GetSuggestionFromBiblionumber($biblionumber)
Lines 265-271 sub ModSuggestion { Link Here
265
    {
240
    {
266
241
267
        # fetch the entire updated suggestion so that we can populate the letter
242
        # fetch the entire updated suggestion so that we can populate the letter
268
        my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} );
243
        my $full_suggestion = Koha::Suggestions->find( $suggestion->{suggestionid} )->unblessed();
269
244
270
        my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} );
245
        my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} );
271
246
(-)a/acqui/basket.pl (-1 / +1 lines)
Lines 28-34 use C4::Acquisition Link Here
28
    qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price );
28
    qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price );
29
use C4::Budgets     qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
29
use C4::Budgets     qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
30
use C4::Contract    qw( GetContract );
30
use C4::Contract    qw( GetContract );
31
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
31
use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
32
use Koha::Biblios;
32
use Koha::Biblios;
33
use Koha::Acquisition::Baskets;
33
use Koha::Acquisition::Baskets;
34
use Koha::Acquisition::Booksellers;
34
use Koha::Acquisition::Booksellers;
(-)a/acqui/neworderempty.pl (-2 / +2 lines)
Lines 72-78 use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget ); Link Here
72
72
73
use C4::Acquisition qw( GetOrder GetBasket FillWithDefaultValues GetOrderUsers );
73
use C4::Acquisition qw( GetOrder GetBasket FillWithDefaultValues GetOrderUsers );
74
use C4::Contract    qw( GetContract );
74
use C4::Contract    qw( GetContract );
75
use C4::Suggestions qw( GetSuggestion GetSuggestionInfo );
75
use C4::Suggestions qw( GetSuggestionInfo );
76
use C4::Biblio      qw(
76
use C4::Biblio      qw(
77
    AddBiblio
77
    AddBiblio
78
    GetBiblioData
78
    GetBiblioData
Lines 209-215 if ( not $ordernumber ) { # create order Link Here
209
    # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
209
    # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
210
    # otherwise, retrieve suggestion information.
210
    # otherwise, retrieve suggestion information.
211
    elsif ($suggestionid) {
211
    elsif ($suggestionid) {
212
        $data = GetSuggestion($suggestionid);
212
        $data = Koha::Suggestions->find($suggestionid)->unblessed();
213
        $data->{quantitysugg} = $data->{quantity};
213
        $data->{quantitysugg} = $data->{quantity};
214
        undef $data->{quantity};
214
        undef $data->{quantity};
215
        $budget_id ||= $data->{'budgetid'} // 0;
215
        $budget_id ||= $data->{'budgetid'} // 0;
(-)a/acqui/orderreceive.pl (-1 / +1 lines)
Lines 67-73 use C4::Output qw( output_html_with_http_headers ); Link Here
67
use C4::Budgets     qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget );
67
use C4::Budgets     qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget );
68
use C4::Members;
68
use C4::Members;
69
use C4::Biblio      qw( GetMarcStructure );
69
use C4::Biblio      qw( GetMarcStructure );
70
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
70
use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
71
71
72
use Koha::Acquisition::Booksellers;
72
use Koha::Acquisition::Booksellers;
73
use Koha::Acquisition::Currencies qw( get_active );
73
use Koha::Acquisition::Currencies qw( get_active );
(-)a/acqui/parcel.pl (-1 / +1 lines)
Lines 60-66 use C4::Acquisition qw( CancelReceipt GetInvoice GetInvoiceDetails get_rounded_p Link Here
60
use C4::Budgets     qw( GetBudget GetBudgetByOrderNumber GetBudgetName );
60
use C4::Budgets     qw( GetBudget GetBudgetByOrderNumber GetBudgetName );
61
use CGI             qw ( -utf8 );
61
use CGI             qw ( -utf8 );
62
use C4::Output      qw( output_html_with_http_headers );
62
use C4::Output      qw( output_html_with_http_headers );
63
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
63
use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
64
64
65
use Koha::Acquisition::Baskets;
65
use Koha::Acquisition::Baskets;
66
use Koha::Acquisition::Bookseller;
66
use Koha::Acquisition::Bookseller;
(-)a/suggestion/suggestion.pl (-2 / +2 lines)
Lines 290-296 if ( $op =~ /cud-save/ ) { Link Here
290
} elsif ( $op eq 'edit_form' ) {
290
} elsif ( $op eq 'edit_form' ) {
291
291
292
    #Edit suggestion
292
    #Edit suggestion
293
    $suggestion_ref = &GetSuggestion( $$suggestion_ref{'suggestionid'} );
293
    $suggestion_ref = Koha::Suggestions->find( $suggestion_ref->{suggestionid} )->unblessed();
294
    $suggestion_ref->{reasonsloop} = $reasonsloop;
294
    $suggestion_ref->{reasonsloop} = $reasonsloop;
295
    my $other_reason = 1;
295
    my $other_reason = 1;
296
    foreach my $reason ( @{$reasonsloop} ) {
296
    foreach my $reason ( @{$reasonsloop} ) {
Lines 383-389 if ( $op =~ /cud-save/ ) { Link Here
383
        $template->param( messages => \@messages, );
383
        $template->param( messages => \@messages, );
384
    }
384
    }
385
} elsif ( $op eq 'show' ) {
385
} elsif ( $op eq 'show' ) {
386
    $suggestion_ref = &GetSuggestion( $$suggestion_ref{'suggestionid'} );
386
    $suggestion_ref = Koha::Suggestions->find( $suggestion_ref->{suggestionid} )->unblessed();
387
    my $budget = GetBudget $$suggestion_ref{budgetid};
387
    my $budget = GetBudget $$suggestion_ref{budgetid};
388
    $$suggestion_ref{budgetname} = $$budget{budget_name};
388
    $$suggestion_ref{budgetname} = $$budget{budget_name};
389
    Init($suggestion_ref);
389
    Init($suggestion_ref);
(-)a/t/db_dependent/Suggestions.t (-14 / +12 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 96;
22
use Test::More tests => 95;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 38-44 use Koha::Suggestions; Link Here
38
BEGIN {
38
BEGIN {
39
    use_ok(
39
    use_ok(
40
        'C4::Suggestions',
40
        'C4::Suggestions',
41
        qw( GetSuggestion ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )
41
        qw( ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )
42
    );
42
    );
43
}
43
}
44
44
Lines 177-184 isnt( $my_suggestionid, 0, 'Suggestion is correctly saved' ); Link Here
177
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store;
177
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store;
178
my $my_suggestionid_with_budget      = $my_suggestion_with_budget_object->id;
178
my $my_suggestionid_with_budget      = $my_suggestion_with_budget_object->id;
179
179
180
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' );
180
my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
181
my $suggestion = GetSuggestion($my_suggestionid);
182
is( $suggestion->{title},         $my_suggestion->{title},         'Suggestion stores the title correctly' );
181
is( $suggestion->{title},         $my_suggestion->{title},         'Suggestion stores the title correctly' );
183
is( $suggestion->{author},        $my_suggestion->{author},        'Suggestion stores the author correctly' );
182
is( $suggestion->{author},        $my_suggestion->{author},        'Suggestion stores the author correctly' );
184
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' );
183
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' );
Lines 203-209 is( $status, undef, 'ModSuggestion without the suggestion id returns undef' ); Link Here
203
$mod_suggestion1->{suggestionid} = $my_suggestionid;
202
$mod_suggestion1->{suggestionid} = $my_suggestionid;
204
$status = ModSuggestion($mod_suggestion1);
203
$status = ModSuggestion($mod_suggestion1);
205
is( $status, 1, 'ModSuggestion modifies one entry' );
204
is( $status, 1, 'ModSuggestion modifies one entry' );
206
$suggestion = GetSuggestion($my_suggestionid);
205
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
207
is( $suggestion->{title},  $mod_suggestion1->{title},  'ModSuggestion modifies the title  correctly' );
206
is( $suggestion->{title},  $mod_suggestion1->{title},  'ModSuggestion modifies the title  correctly' );
208
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
207
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
209
is(
208
is(
Lines 247-253 my $mod_suggestion3 = { Link Here
247
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 );
246
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 );
248
$status = ModSuggestion($mod_suggestion3);
247
$status = ModSuggestion($mod_suggestion3);
249
is( $status, 1, 'ModSuggestion modifies one entry' );
248
is( $status, 1, 'ModSuggestion modifies one entry' );
250
$suggestion = GetSuggestion($my_suggestionid);
249
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
251
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
250
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
252
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
251
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
253
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
252
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
Lines 438-444 is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arg Link Here
438
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
437
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
439
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
438
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
440
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
439
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
441
$suggestion = GetSuggestion($my_suggestionid);
440
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
442
is(
441
is(
443
    $suggestion->{biblionumber}, $biblio_2->biblionumber,
442
    $suggestion->{biblionumber}, $biblio_2->biblionumber,
444
    'ConnectSuggestionAndBiblio updates the biblio number correctly'
443
    'ConnectSuggestionAndBiblio updates the biblio number correctly'
Lines 469-480 is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes Link Here
469
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
468
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
470
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
469
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
471
my $my_suggestionid_test_budgetid      = $my_suggestionid_test_budget_object->id;
470
my $my_suggestionid_test_budgetid      = $my_suggestionid_test_budget_object->id;
472
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
471
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed();
473
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
472
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
474
473
475
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
474
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
476
ModSuggestion($my_suggestion);
475
ModSuggestion($my_suggestion);
477
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
476
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed();
478
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
477
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
479
478
480
my $suggestion2 = {
479
my $suggestion2 = {
Lines 511-520 subtest 'GetUnprocessedSuggestions' => sub { Link Here
511
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
510
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
512
    );
511
    );
513
    my $status     = ModSuggestion($mod_suggestion1);
512
    my $status     = ModSuggestion($mod_suggestion1);
514
    my $suggestion = GetSuggestion($my_suggestionid);
513
    my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
515
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
514
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
516
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
515
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
517
    $suggestion = GetSuggestion($my_suggestionid);
516
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
518
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
517
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
519
518
520
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
519
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
Lines 734-740 subtest 'ModSuggestion should work on suggestions without a suggester' => sub { Link Here
734
733
735
    $dbh->do(q|DELETE FROM suggestions|);
734
    $dbh->do(q|DELETE FROM suggestions|);
736
    my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id;
735
    my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id;
737
    $suggestion = GetSuggestion($my_suggestionid);
736
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
738
    is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" );
737
    is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" );
739
738
740
    ModSuggestion(
739
    ModSuggestion(
Lines 744-750 subtest 'ModSuggestion should work on suggestions without a suggester' => sub { Link Here
744
            note         => "Test note"
743
            note         => "Test note"
745
        }
744
        }
746
    );
745
    );
747
    $suggestion = GetSuggestion($my_suggestionid);
746
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
748
747
749
    is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" );
748
    is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" );
750
};
749
};
751
- 

Return to bug 39721