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

(-)a/Koha/REST/V1/Holds.pm (-5 / +11 lines)
Lines 276-292 sub edit { Link Here
276
276
277
        $pickup_library_id //= $hold->branchcode;
277
        $pickup_library_id //= $hold->branchcode;
278
        my $priority         = $body->{priority} // $hold->priority;
278
        my $priority         = $body->{priority} // $hold->priority;
279
        my $hold_date       = $body->{hold_date}       // $hold->reservedate;
280
        my $expiration_date = $body->{expiration_date} // $hold->expirationdate;
281
279
        # suspended_until can also be set to undef
282
        # suspended_until can also be set to undef
280
        my $suspended_until = $body->{suspended_until} || $hold->suspend_until;
283
        my $suspended_until = $body->{suspended_until} || $hold->suspend_until;
281
284
282
        my $params = {
285
        my $params = {
283
            reserve_id    => $hold->id,
286
            reserve_id     => $hold->id,
284
            branchcode    => $pickup_library_id,
287
            branchcode     => $pickup_library_id,
285
            rank          => $priority,
288
            rank           => $priority,
286
            suspend_until => $suspended_until,
289
            suspend_until  => $suspended_until,
287
            itemnumber    => $hold->itemnumber,
290
            itemnumber     => $hold->itemnumber,
291
            reservedate    => $hold_date,
292
            expirationdate => $expiration_date,
288
        };
293
        };
289
294
295
290
        C4::Reserves::ModReserve($params);
296
        C4::Reserves::ModReserve($params);
291
        $hold->discard_changes; # refresh
297
        $hold->discard_changes; # refresh
292
298
(-)a/api/v1/swagger/paths/holds.yaml (+8 lines)
Lines 287-292 Link Here
287
              description: Date until which the hold has been suspended
287
              description: Date until which the hold has been suspended
288
              type: string
288
              type: string
289
              format: date-time
289
              format: date-time
290
            hold_date:
291
              description: Hold date
292
              type: string
293
              format: date
294
            expiration_date:
295
              description: Hold's expiration date
296
              type: string
297
              format: date
290
          additionalProperties: false
298
          additionalProperties: false
291
    consumes:
299
    consumes:
292
      - application/json
300
      - application/json
(-)a/t/db_dependent/api/v1/holds.t (-12 / +39 lines)
Lines 917-923 subtest 'pickup_locations() tests' => sub { Link Here
917
917
918
subtest 'edit() tests' => sub {
918
subtest 'edit() tests' => sub {
919
919
920
    plan tests => 39;
920
    plan tests => 47;
921
921
922
    $schema->storage->txn_begin;
922
    $schema->storage->txn_begin;
923
923
Lines 968-977 subtest 'edit() tests' => sub { Link Here
968
        {
968
        {
969
            class => "Koha::Holds",
969
            class => "Koha::Holds",
970
            value => {
970
            value => {
971
                biblionumber => $biblio->biblionumber,
971
                biblionumber   => $biblio->biblionumber,
972
                branchcode   => $library_3->branchcode,
972
                branchcode     => $library_3->branchcode,
973
                itemnumber   => undef,
973
                itemnumber     => undef,
974
                priority     => 1,
974
                priority       => 1,
975
                reservedate    => '2022-01-01',
976
                expirationdate => '2022-03-01'
975
            }
977
            }
976
        }
978
        }
977
    );
979
    );
Lines 1026-1042 subtest 'edit() tests' => sub { Link Here
1026
    $biblio_hold->discard_changes;
1028
    $biblio_hold->discard_changes;
1027
    is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
1029
    is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
1028
1030
1031
    $biblio_hold_data = {
1032
        hold_date       => '2022-01-02',
1033
        expiration_date => '2022-03-02'
1034
    };
1035
1036
    $t->patch_ok( "//$userid:$password@/api/v1/holds/" . $biblio_hold->id => json => $biblio_hold_data )
1037
        ->status_is(200);
1038
1039
    $biblio_hold->discard_changes;
1040
    is( $biblio_hold->reservedate,    '2022-01-02', 'Hold date changed correctly' );
1041
    is( $biblio_hold->expirationdate, '2022-03-02', 'Expiration date changed correctly' );
1042
1043
1029
    # Test item-level holds
1044
    # Test item-level holds
1030
    my $item_hold = $builder->build_object(
1045
    my $item_hold = $builder->build_object(
1031
        {
1046
        {
1032
            class => "Koha::Holds",
1047
            class => "Koha::Holds",
1033
            value => {
1048
            value => {
1034
                biblionumber => $biblio->biblionumber,
1049
                biblionumber   => $biblio->biblionumber,
1035
                branchcode   => $library_3->branchcode,
1050
                branchcode     => $library_3->branchcode,
1036
                itemnumber   => $item->itemnumber,
1051
                itemnumber     => $item->itemnumber,
1037
                priority     => 1,
1052
                priority       => 1,
1038
                suspend       => 0,
1053
                suspend        => 0,
1039
                suspend_until => undef,
1054
                suspend_until  => undef,
1055
                reservedate    => '2022-01-01',
1056
                expirationdate => '2022-03-01'
1040
            }
1057
            }
1041
        }
1058
        }
1042
    );
1059
    );
Lines 1091-1096 subtest 'edit() tests' => sub { Link Here
1091
    is( $item_hold->suspend, 0, 'Location change should not activate suspended status' );
1108
    is( $item_hold->suspend, 0, 'Location change should not activate suspended status' );
1092
    is( $item_hold->suspend_until, undef, 'Location change should keep suspended_until be undef' );
1109
    is( $item_hold->suspend_until, undef, 'Location change should keep suspended_until be undef' );
1093
1110
1111
    $item_hold_data = {
1112
        hold_date       => '2022-01-02',
1113
        expiration_date => '2022-03-02'
1114
    };
1115
1116
    $t->patch_ok( "//$userid:$password@/api/v1/holds/" . $item_hold->id => json => $item_hold_data )->status_is(200);
1117
1118
    $item_hold->discard_changes;
1119
    is( $item_hold->reservedate,    '2022-01-02', 'Hold date changed correctly' );
1120
    is( $item_hold->expirationdate, '2022-03-02', 'Expiration date changed correctly' );
1121
1094
    $schema->storage->txn_rollback;
1122
    $schema->storage->txn_rollback;
1095
1123
1096
};
1124
};
1097
- 

Return to bug 30661