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

(-)a/Koha/Hold.pm (-2 / +27 lines)
Lines 574-586 sub item_group { Link Here
574
574
575
=head3 branch
575
=head3 branch
576
576
577
Returns the related Koha::Library object for this Hold
577
Returns the related Koha::Library object for this hold
578
579
DEPRECATED
578
580
579
=cut
581
=cut
580
582
581
sub branch {
583
sub branch {
584
    return shift->pickup_library(@_);
585
}
586
587
=head3 pickup_library
588
589
Returns the related Koha::Library object for this hold
590
591
=cut
592
593
sub pickup_library {
582
    my ($self) = @_;
594
    my ($self) = @_;
583
    my $rs = $self->_result->branchcode;
595
    my $rs = $self->_result->pickup_library;
584
    return Koha::Library->_new_from_dbic($rs);
596
    return Koha::Library->_new_from_dbic($rs);
585
}
597
}
586
598
Lines 1041-1046 sub can_update_pickup_location_opac { Link Here
1041
    return 0;
1053
    return 0;
1042
}
1054
}
1043
1055
1056
=head3 strings_map
1057
1058
Returns a map of column name to string representations including the string.
1059
1060
=cut
1061
1062
sub strings_map {
1063
    my ($self) = @_;
1064
    return {
1065
        pickup_library_id => { str => $self->branch->branchname, type => 'library' },
1066
    };
1067
}
1068
1044
=head2 Internal methods
1069
=head2 Internal methods
1045
1070
1046
=head3 _type
1071
=head3 _type
(-)a/Koha/Old/Hold.pm (+26 lines)
Lines 47-52 sub biblio { Link Here
47
    return Koha::Biblio->_new_from_dbic($rs);
47
    return Koha::Biblio->_new_from_dbic($rs);
48
}
48
}
49
49
50
=head3 item
51
52
Returns the related Koha::Item object for this old Hold
53
54
=cut
55
56
sub item {
57
    my ($self) = @_;
58
    my $rs = $self->_result->itemnumber;
59
    return unless $rs;
60
    return Koha::Item->_new_from_dbic($rs);
61
}
62
63
=head3 pickup_library
64
65
Returns the related Koha::Biblio object for this old hold
66
67
=cut
68
69
sub pickup_library {
70
    my ($self) = @_;
71
    my $rs = $self->_result->pickup_library;
72
    return unless $rs;
73
    return Koha::Library->_new_from_dbic($rs);
74
}
75
50
=head3 anonymize
76
=head3 anonymize
51
77
52
    $old_hold->anonymize();
78
    $old_hold->anonymize();
(-)a/Koha/REST/V1/Holds.pm (-3 / +11 lines)
Lines 26-31 use C4::Reserves; Link Here
26
use Koha::Items;
26
use Koha::Items;
27
use Koha::Patrons;
27
use Koha::Patrons;
28
use Koha::Holds;
28
use Koha::Holds;
29
use Koha::Old::Holds;
29
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
30
31
31
use List::MoreUtils qw( any );
32
use List::MoreUtils qw( any );
Lines 44-54 Method that handles listing Koha::Hold objects Link Here
44
sub list {
45
sub list {
45
    my $c = shift->openapi->valid_input or return;
46
    my $c = shift->openapi->valid_input or return;
46
47
48
    my $old = $c->param('old');
49
    $c->req->params->remove('old');
50
47
    return try {
51
    return try {
48
        my $holds = $c->objects->search( Koha::Holds->new );
52
        my $holds_set =
53
              $old
54
            ? Koha::Old::Holds->new
55
            : Koha::Holds->new;
56
57
        my $holds = $c->objects->search($holds_set);
49
        return $c->render( status => 200, openapi => $holds );
58
        return $c->render( status => 200, openapi => $holds );
50
    }
59
    } catch {
51
    catch {
52
        $c->unhandled_exception($_);
60
        $c->unhandled_exception($_);
53
    };
61
    };
54
}
62
}
(-)a/Koha/REST/V1/Patrons/Holds.pm (-8 / +10 lines)
Lines 49-64 sub list { Link Here
49
        );
49
        );
50
    }
50
    }
51
51
52
    return try {
52
    my $old = $c->param('old');
53
    $c->req->params->remove('old');
53
54
54
        my $holds = $c->objects->search( $patron->holds );
55
    return try {
56
        my $holds_set =
57
            $old
58
            ? $patron->old_holds
59
            : $patron->holds;
55
60
56
        return $c->render(
61
        my $holds = $c->objects->search( $holds_set );
57
            status  => 200,
62
        return $c->render( status => 200, openapi => $holds );
58
            openapi => $holds
63
    } catch {
59
        );
60
    }
61
    catch {
62
        $c->unhandled_exception($_);
64
        $c->unhandled_exception($_);
63
    };
65
    };
64
}
66
}
(-)a/api/v1/swagger/definitions/hold.yaml (+15 lines)
Lines 108-112 properties: Link Here
108
      - boolean
108
      - boolean
109
      - "null"
109
      - "null"
110
    description: Cancellation requests count for the hold (x-koha-embed)
110
    description: Cancellation requests count for the hold (x-koha-embed)
111
  biblio:
112
    type:
113
      - object
114
      - "null"
115
    description: Bibliographic record
116
  item:
117
    type:
118
      - object
119
      - "null"
120
    description: The item
121
  pickup_library:
122
    type:
123
      - object
124
      - "null"
125
    description: Pickup library
111
126
112
additionalProperties: false
127
additionalProperties: false
(-)a/api/v1/swagger/paths/holds.yaml (+7 lines)
Lines 88-93 Link Here
88
      - $ref: "../swagger.yaml#/parameters/q_param"
88
      - $ref: "../swagger.yaml#/parameters/q_param"
89
      - $ref: "../swagger.yaml#/parameters/q_body"
89
      - $ref: "../swagger.yaml#/parameters/q_body"
90
      - $ref: "../swagger.yaml#/parameters/request_id_header"
90
      - $ref: "../swagger.yaml#/parameters/request_id_header"
91
      - name: old
92
        in: query
93
        description: By default, current holds are returned, when this is true then
94
          old holds are returned as result.
95
        type: boolean
91
      - name: x-koha-embed
96
      - name: x-koha-embed
92
        in: header
97
        in: header
93
        required: false
98
        required: false
Lines 97-102 Link Here
97
          type: string
102
          type: string
98
          enum:
103
          enum:
99
            - cancellation_requested
104
            - cancellation_requested
105
            - biblio
106
            - pickup_library
100
          collectionFormat: csv
107
          collectionFormat: csv
101
    produces:
108
    produces:
102
      - application/json
109
      - application/json
(-)a/api/v1/swagger/paths/patrons_holds.yaml (+9 lines)
Lines 15-20 Link Here
15
      - $ref: "../swagger.yaml#/parameters/q_param"
15
      - $ref: "../swagger.yaml#/parameters/q_param"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
18
      - name: old
19
        in: query
20
        description: By default, current holds are returned, when this is true then
21
          old holds are returned as result.
22
        type: boolean
18
      - name: x-koha-embed
23
      - name: x-koha-embed
19
        in: header
24
        in: header
20
        required: false
25
        required: false
Lines 24-29 Link Here
24
          type: string
29
          type: string
25
          enum:
30
          enum:
26
            - cancellation_requested
31
            - cancellation_requested
32
            - biblio
33
            - item
34
            - pickup_library
35
            - pickup_library.branchname
27
        collectionFormat: csv
36
        collectionFormat: csv
28
    produces:
37
    produces:
29
      - application/json
38
      - application/json
(-)a/t/db_dependent/Koha/Hold.t (-1 / +18 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 13;
22
use Test::More tests => 14;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 87-92 subtest 'biblio() tests' => sub { Link Here
87
    $schema->storage->txn_rollback;
87
    $schema->storage->txn_rollback;
88
};
88
};
89
89
90
subtest 'pickup_library/branch tests' => sub {
91
92
    plan tests => 1;
93
94
    $schema->storage->txn_begin;
95
96
    my $hold = $builder->build_object(
97
        {
98
            class => 'Koha::Holds',
99
        }
100
    );
101
102
    is( ref( $hold->pickup_library ), 'Koha::Library', '->pickup_library should return a Koha::Library object' );
103
104
    $schema->storage->txn_rollback;
105
};
106
90
subtest 'fill() tests' => sub {
107
subtest 'fill() tests' => sub {
91
108
92
    plan tests => 14;
109
    plan tests => 14;
(-)a/t/db_dependent/Koha/Old/Hold.t (-1 / +26 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use Koha::Database;
23
use Koha::Database;
Lines 118-120 subtest 'biblio() tests' => sub { Link Here
118
118
119
    $schema->storage->txn_rollback;
119
    $schema->storage->txn_rollback;
120
};
120
};
121
122
subtest 'item/pickup_library() tests' => sub {
123
124
    plan tests => 4;
125
126
    $schema->storage->txn_begin;
127
128
    my $old_hold = $builder->build_object(
129
        {
130
            class => 'Koha::Old::Holds',
131
        }
132
    );
133
    is( ref( $old_hold->item ),           'Koha::Item',    '->item should return a Koha::Item object' );
134
    is( ref( $old_hold->pickup_library ), 'Koha::Library', '->pickup_library should return a Koha::Library object' );
135
136
    $old_hold->item->delete;
137
    $old_hold->pickup_library->delete;
138
139
    $old_hold = $old_hold->get_from_storage;    # Be on the safe side
140
141
    is( $old_hold->item,           undef, 'Item has been deleted, ->item should return undef' );
142
    is( $old_hold->pickup_library, undef, 'Library has been deleted, ->pickup_library should return undef' );
143
144
    $schema->storage->txn_rollback;
145
};
(-)a/t/db_dependent/api/v1/patrons_holds.t (-7 / +27 lines)
Lines 35-41 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
35
35
36
subtest 'list() tests' => sub {
36
subtest 'list() tests' => sub {
37
37
38
    plan tests => 9;
38
    plan tests => 18;
39
39
40
    $schema->storage->txn_begin;
40
    $schema->storage->txn_begin;
41
41
Lines 51-62 subtest 'list() tests' => sub { Link Here
51
      ->status_is( 200, 'SWAGGER3.2.2' )
51
      ->status_is( 200, 'SWAGGER3.2.2' )
52
      ->json_is( [] );
52
      ->json_is( [] );
53
53
54
    my $hold_1 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
54
    my $hold_1 = $builder->build_object( { class => 'Koha::Holds', value => { borrowernumber => $patron->id } } );
55
    my $hold_2 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
55
    my $hold_2 = $builder->build_object( { class => 'Koha::Holds', value => { borrowernumber => $patron->id } } );
56
    my $hold_3 = $builder->build_object( { class => 'Koha::Holds', value => { borrowernumber => $patron->id } } );
56
57
57
    $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?_order_by=+me.hold_id')
58
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?_order_by=+me.hold_id' )
58
      ->status_is( 200, 'SWAGGER3.2.2' )
59
        ->status_is( 200, 'SWAGGER3.2.2' )
59
      ->json_is( '' => [ $hold_1->to_api, $hold_2->to_api ], 'Holds retrieved' );
60
        ->json_is( '' => [ $hold_1->to_api, $hold_2->to_api, $hold_3->to_api ], 'Holds retrieved' );
61
62
    $hold_1->fill;
63
    $hold_3->fill;
64
65
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?_order_by=+me.hold_id' )
66
        ->status_is( 200, 'SWAGGER3.2.2' )->json_is( '' => [ $hold_2->to_api ], 'Only current holds retrieved' );
67
68
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?old=1&_order_by=+me.hold_id' )
69
        ->status_is( 200, 'SWAGGER3.2.2' )
70
        ->json_is( '' => [ $hold_1->to_api, $hold_3->to_api ], 'Only old holds retrieved' );
71
72
    my $old_hold_1 = Koha::Old::Holds->find( $hold_1->id );
73
    $old_hold_1->item->delete;
74
    $old_hold_1->pickup_library->delete;
75
76
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?old=1&_order_by=+me.hold_id' )
77
        ->status_is( 200, 'SWAGGER3.2.2' )->json_is(
78
        '' => [ $old_hold_1->get_from_storage->to_api, $hold_3->to_api ],
79
        'Old holds even after item and library removed'
80
        );
60
81
61
    my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' });
82
    my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' });
62
    my $non_existent_patron_id = $non_existent_patron->id;
83
    my $non_existent_patron_id = $non_existent_patron->id;
63
- 

Return to bug 35353