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 173-178 Link Here
173
                                    [% PROCESS options_for_libraries libraries => Branches.all({ selected => club.branchcode, search_params => { pickup_location => 1 } }) %]
173
                                    [% PROCESS options_for_libraries libraries => Branches.all({ selected => club.branchcode, search_params => { pickup_location => 1 } }) %]
174
                                </select>
174
                                </select>
175
                            </li>
175
                            </li>
176
                            <li>
177
                                <label for="default_patron_home">Pickup at patron's home library when possible</label>
178
                                <input type="checkbox" name="default_patron_home"/>
179
                            </li>
176
                        </ol>
180
                        </ol>
177
                        <h2 style="padding: 0 1em;">Members</h2>
181
                        <h2 style="padding: 0 1em;">Members</h2>
178
                        <ol>
182
                        <ol>
Lines 1052-1057 Link Here
1052
                if($('input[name="itemtype"]').length) {
1056
                if($('input[name="itemtype"]').length) {
1053
                    data.item_type = $('input[name="itemtype"]').val()||null;
1057
                    data.item_type = $('input[name="itemtype"]').val()||null;
1054
                }
1058
                }
1059
                if($('input[name="default_patron_home"]:checked').length) {
1060
                    data.default_patron_home = 1;
1061
                }
1055
                if($('input[name="biblionumbers"]').length) {
1062
                if($('input[name="biblionumbers"]').length) {
1056
                    biblionumbers_text = $('input[name="biblionumbers"]').val();
1063
                    biblionumbers_text = $('input[name="biblionumbers"]').val();
1057
                    biblionumbers = biblionumbers_text.replace(/\/$/, '').split('/')
1064
                    biblionumbers = biblionumbers_text.replace(/\/$/, '').split('/')
1058
- 

Return to bug 23820