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

(-)a/Koha/Club/Hold.pm (-6 / +21 lines)
Lines 29-34 use base qw(Koha::Object); Link Here
29
use Koha::Exceptions::ClubHold;
29
use Koha::Exceptions::ClubHold;
30
use Koha::Club::Hold::PatronHold;
30
use Koha::Club::Hold::PatronHold;
31
use Koha::Clubs;
31
use Koha::Clubs;
32
use Koha::Patrons;
32
33
33
use List::Util 'shuffle';
34
use List::Util 'shuffle';
34
35
Lines 72-82 sub add { Link Here
72
73
73
    foreach my $enrollment (@enrollments) {
74
    foreach my $enrollment (@enrollments) {
74
        my $patron_id = $enrollment->borrowernumber;
75
        my $patron_id = $enrollment->borrowernumber;
76
        my $pickup_id = $params->{pickup_library_id};
77
78
        my $can_place_hold;
79
        if($params->{default_patron_home}) {
80
            my $patron = Koha::Patrons->find($patron_id);
81
            my $patron_home = $patron->branchcode;
82
            $can_place_hold = $params->{item_id}
83
                ? C4::Reserves::CanItemBeReserved( $patron_id, $params->{item_id}, $patron_home )
84
                : C4::Reserves::CanBookBeReserved( $patron_id, $params->{biblio_id}, $patron_home );
85
            $pickup_id = $patron_home if $can_place_hold->{status} eq 'OK';
86
            unless ( $can_place_hold->{status} eq 'OK' ) {
87
                warn "Patron(".$patron_id.") Hold cannot be placed with patron's homebranch ($patron_home). Reason: " . $can_place_hold->{status};
88
            }
89
        }
75
90
76
        my $can_place_hold
91
        unless ( defined $can_place_hold && $can_place_hold->{status} eq 'OK' ) {
77
        = $params->{item_id}
92
            $can_place_hold = $params->{item_id}
78
        ? C4::Reserves::CanItemBeReserved( $patron_id, $params->{club_id} )
93
                ? C4::Reserves::CanItemBeReserved( $patron_id, $params->{item_id}, $pickup_id )
79
        : C4::Reserves::CanBookBeReserved( $patron_id, $params->{biblio_id} );
94
                : C4::Reserves::CanBookBeReserved( $patron_id, $params->{biblio_id}, $pickup_id );
95
        }
80
96
81
        unless ( $can_place_hold->{status} eq 'OK' ) {
97
        unless ( $can_place_hold->{status} eq 'OK' ) {
82
            warn "Patron(".$patron_id.") Hold cannot be placed. Reason: " . $can_place_hold->{status};
98
            warn "Patron(".$patron_id.") Hold cannot be placed. Reason: " . $can_place_hold->{status};
Lines 92-98 sub add { Link Here
92
108
93
        my $hold_id = C4::Reserves::AddReserve(
109
        my $hold_id = C4::Reserves::AddReserve(
94
            {
110
            {
95
                branchcode      => $params->{pickup_library_id},
111
                branchcode      => $pickup_id,
96
                borrowernumber  => $patron_id,
112
                borrowernumber  => $patron_id,
97
                biblionumber    => $params->{biblio_id},
113
                biblionumber    => $params->{biblio_id},
98
                priority        => $priority,
114
                priority        => $priority,
Lines 118-124 sub add { Link Here
118
                error_message => "Could not create hold for Patron(".$patron_id.")"
134
                error_message => "Could not create hold for Patron(".$patron_id.")"
119
            })->store();
135
            })->store();
120
        }
136
        }
121
122
    }
137
    }
123
138
124
    return $club_hold;
139
    return $club_hold;
(-)a/Koha/REST/V1/Clubs/Holds.pm (-1 / +3 lines)
Lines 58-63 sub add { Link Here
58
        my $item_type         = $body->{item_type};
58
        my $item_type         = $body->{item_type};
59
        my $expiration_date   = $body->{expiration_date};
59
        my $expiration_date   = $body->{expiration_date};
60
        my $notes             = $body->{notes};
60
        my $notes             = $body->{notes};
61
        my $default_patron_home = $body->{default_patron_home};
61
62
62
        if ( $item_id and $biblio_id ) {
63
        if ( $item_id and $biblio_id ) {
63
64
Lines 116-122 sub add { Link Here
116
            pickup_library_id => $pickup_library_id,
117
            pickup_library_id => $pickup_library_id,
117
            expiration_date => $expiration_date,
118
            expiration_date => $expiration_date,
118
            notes => $notes,
119
            notes => $notes,
119
            item_type => $item_type
120
            item_type => $item_type,
121
            default_patron_home => $default_patron_home
120
        });
122
        });
121
123
122
        return $c->render(
124
        return $c->render(
(-)a/api/v1/swagger/paths/clubs.json (+4 lines)
Lines 38-43 Link Here
38
                    "item_type": {
38
                    "item_type": {
39
                      "description": "Limit hold on one itemtype (ignored for item-level holds)",
39
                      "description": "Limit hold on one itemtype (ignored for item-level holds)",
40
                      "type": [ "string", "null" ]
40
                      "type": [ "string", "null" ]
41
                    },
42
                    "default_patron_home": {
43
                      "description": "For each patron, set pickup location to patron's home library if possible",
44
                      "type": "integer"
41
                    }
45
                    }
42
                  },
46
                  },
43
                  "required": [ "pickup_library_id" ]
47
                  "required": [ "pickup_library_id" ]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-1 / +7 lines)
Lines 162-167 Link Here
162
                                    [% PROCESS options_for_libraries libraries => Branches.all({ selected => club.branchcode, search_params => { pickup_location => 1 } }) %]
162
                                    [% PROCESS options_for_libraries libraries => Branches.all({ selected => club.branchcode, search_params => { pickup_location => 1 } }) %]
163
                                </select>
163
                                </select>
164
                            </li>
164
                            </li>
165
                            <li>
166
                                <label for="default_patron_home">Pickup at patron's home library when possible</label>
167
                                <input type="checkbox" name="default_patron_home"/>
168
                            </li>
165
                        </ol>
169
                        </ol>
166
                        <h2 style="padding: 0 1em;">Members</h2>
170
                        <h2 style="padding: 0 1em;">Members</h2>
167
                        <ol>
171
                        <ol>
Lines 1039-1044 Link Here
1039
                if($('input[name="itemtype"]').length) {
1043
                if($('input[name="itemtype"]').length) {
1040
                    data.item_type = $('input[name="itemtype"]').val()||null;
1044
                    data.item_type = $('input[name="itemtype"]').val()||null;
1041
                }
1045
                }
1046
                if($('input[name="default_patron_home"]:checked').length) {
1047
                    data.default_patron_home = 1;
1048
                }
1042
                if($('input[name="biblionumbers"]').length) {
1049
                if($('input[name="biblionumbers"]').length) {
1043
                    biblionumbers_text = $('input[name="biblionumbers"]').val();
1050
                    biblionumbers_text = $('input[name="biblionumbers"]').val();
1044
                    biblionumbers = biblionumbers_text.replace(/\/$/, '').split('/')
1051
                    biblionumbers = biblionumbers_text.replace(/\/$/, '').split('/')
1045
- 

Return to bug 23820