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

(-)a/C4/Circulation.pm (-8 / +2 lines)
Lines 1930-1940 holdallowed => Hold policy for this branch and itemtype. Possible values: Link Here
1930
  from_any_library:      Holds allowed from any patron.
1930
  from_any_library:      Holds allowed from any patron.
1931
  from_local_hold_group: Holds allowed from libraries in hold group
1931
  from_local_hold_group: Holds allowed from libraries in hold group
1932
1932
1933
returnbranch => branch to which to return item.  Possible values:
1934
  noreturn: do not return, let item remain where checked in (floating collections)
1935
  homebranch: return to item's home branch
1936
  holdingbranch: return to issuer branch
1937
1938
This searches branchitemrules in the following order:
1933
This searches branchitemrules in the following order:
1939
1934
1940
  * Same branchcode and itemtype
1935
  * Same branchcode and itemtype
Lines 1953-1965 sub GetBranchItemRule { Link Here
1953
    my $rules = Koha::CirculationRules->get_effective_rules({
1948
    my $rules = Koha::CirculationRules->get_effective_rules({
1954
        branchcode => $branchcode,
1949
        branchcode => $branchcode,
1955
        itemtype => $itemtype,
1950
        itemtype => $itemtype,
1956
        rules => ['holdallowed', 'hold_fulfillment_policy', 'returnbranch']
1951
        rules => ['holdallowed', 'hold_fulfillment_policy']
1957
    });
1952
    });
1958
1953
1959
    # built-in default circulation rule
1954
    # built-in default circulation rule
1960
    $rules->{holdallowed} //= 'from_any_library';
1955
    $rules->{holdallowed} //= 'from_any_library';
1961
    $rules->{hold_fulfillment_policy} //= 'any';
1956
    $rules->{hold_fulfillment_policy} //= 'any';
1962
    $rules->{returnbranch} //= 'homebranch';
1963
1957
1964
    return $rules;
1958
    return $rules;
1965
}
1959
}
Lines 2092-2098 sub AddReturn { Link Here
2092
    }
2086
    }
2093
2087
2094
        # full item data, but no borrowernumber or checkout info (no issue)
2088
        # full item data, but no borrowernumber or checkout info (no issue)
2095
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
2089
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2096
        # get the proper branch to which to return the item
2090
        # get the proper branch to which to return the item
2097
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2091
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2098
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2092
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
(-)a/Koha/CirculationRules.pm (+47 lines)
Lines 474-479 sub clone { Link Here
474
    }
474
    }
475
}
475
}
476
476
477
=head2 get_return_branch_policy
478
479
  my $returnbranch = Koha::CirculationRules->get_return_branch_policy($item);
480
481
Returns the branch to use for returning the item based on the
482
item type, and a branch selected via CircControlReturnsBrnch.
483
484
The return value is the branch to which to return item.  Possible values:
485
  noreturn: do not return, let item remain where checked in (floating collections)
486
  homebranch: return to item's home branch
487
  holdingbranch: return to issuer branch
488
489
This searches branchitemrules in the following order:
490
  * Same branchcode and itemtype
491
  * Same branchcode, itemtype '*'
492
  * branchcode '*', same itemtype
493
  * branchcode and itemtype '*'
494
495
=cut
496
497
sub get_return_branch_policy {
498
    my ( $self, $item ) = @_;
499
500
    my $pref = C4::Context->preference('CircControlReturnsBranch');
501
502
    my $branchcode =
503
        $pref eq 'ItemHomeLibrary'     ? $item->homebranch
504
      : $pref eq 'ItemHoldingLibrary' ? $item->holdingbranch
505
      : $pref eq 'CheckInLibrary'      ? C4::Context->userenv
506
          ? C4::Context->userenv->{branch}
507
          : $item->homebranch
508
      : $item->homebranch;
509
510
    my $itemtype = $item->effective_itemtype;
511
512
    my $rule = Koha::CirculationRules->get_effective_rule(
513
        {
514
            rule_name  => 'returnbranch',
515
            itemtype   => $itemtype,
516
            branchcode => $branchcode,
517
        }
518
    );
519
520
    return $rule ? $rule->rule_value : 'homebranch';
521
}
522
523
477
=head3 get_opacitemholds_policy
524
=head3 get_opacitemholds_policy
478
525
479
my $can_place_a_hold_at_item_level = Koha::CirculationRules->get_opacitemholds_policy( { patron => $patron, item => $item } );
526
my $can_place_a_hold_at_item_level = Koha::CirculationRules->get_opacitemholds_policy( { patron => $patron, item => $item } );
(-)a/circ/returns.pl (-2 / +3 lines)
Lines 47-56 use Koha::AuthorisedValues; Link Here
47
use Koha::BiblioFrameworks;
47
use Koha::BiblioFrameworks;
48
use Koha::Calendar;
48
use Koha::Calendar;
49
use Koha::Checkouts;
49
use Koha::Checkouts;
50
use Koha::CirculationRules;
50
use Koha::DateUtils qw( dt_from_string );
51
use Koha::DateUtils qw( dt_from_string );
51
use Koha::Holds;
52
use Koha::Holds;
52
use Koha::Items;
53
use Koha::Item::Transfers;
53
use Koha::Item::Transfers;
54
use Koha::Items;
54
use Koha::Patrons;
55
use Koha::Patrons;
55
use Koha::Recalls;
56
use Koha::Recalls;
56
57
Lines 293-299 if ($barcode) { Link Here
293
        }
294
        }
294
295
295
        # make sure return branch respects home branch circulation rules, default to homebranch
296
        # make sure return branch respects home branch circulation rules, default to homebranch
296
        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
297
        my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
297
        $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
298
        $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
298
299
299
        my $materials = $item->materials;
300
        my $materials = $item->materials;
(-)a/installer/data/mysql/atomicupdate/bug_25426.pl (+17 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "25426",
5
    description => "Add new syspref CircControlReturnsBranch",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{
11
            INSERT INTO systempreferences VALUES (
12
              'CircControlReturnsBranch','ItemHomeLibrary','ItemHomeLibrary|ItemHoldingLibrary|CheckInLibrary',
13
              'Specify the agency that controls the return policy','Choice'
14
            )
15
        });
16
    },
17
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 135-140 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
135
('CircAutoPrintQuickSlip','qslip',NULL,'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window, Display a print slip window or Clear the screen.','Choice'),
135
('CircAutoPrintQuickSlip','qslip',NULL,'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window, Display a print slip window or Clear the screen.','Choice'),
136
('CircConfirmItemParts', '0', NULL, 'Require staff to confirm that all parts of an item are present at checkin/checkout.', 'Yes/No'),
136
('CircConfirmItemParts', '0', NULL, 'Require staff to confirm that all parts of an item are present at checkin/checkout.', 'Yes/No'),
137
('CircControl','ItemHomeLibrary','PickupLibrary|PatronLibrary|ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','Choice'),
137
('CircControl','ItemHomeLibrary','PickupLibrary|PatronLibrary|ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','Choice'),
138
('CircControlReturnsBranch','ItemHomeLibrary','ItemHomeLibrary|ItemHoldingLibrary|CheckInLibrary','Specify the agency that controls the return policy','Choice'),
138
('CircSidebar','0',NULL,'Activate or deactivate the navigation sidebar on all Circulation pages','YesNo'),
139
('CircSidebar','0',NULL,'Activate or deactivate the navigation sidebar on all Circulation pages','YesNo'),
139
('CirculateILL','0','','If enabled, it is possible to circulate ILL items from within ILL','YesNo'),
140
('CirculateILL','0','','If enabled, it is possible to circulate ILL items from within ILL','YesNo'),
140
('ClaimsBccCopy','0','','Bcc the ClaimAcquisition and ClaimIssues alerts','YesNo'),
141
('ClaimsBccCopy','0','','Bcc the ClaimAcquisition and ClaimIssues alerts','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+8 lines)
Lines 270-275 Circulation: Link Here
270
                  PickupLibrary: the library you are logged in at.
270
                  PickupLibrary: the library you are logged in at.
271
                  PatronLibrary: the library the patron is from.
271
                  PatronLibrary: the library the patron is from.
272
                  ItemHomeLibrary: the library the item is from.
272
                  ItemHomeLibrary: the library the item is from.
273
        -
274
            - For check in, use the circulation rules of
275
            - pref: CircControlReturnsBranch
276
              type: choice
277
              choices:
278
                  ItemHoldingLibrary: the library the item is currently held by.
279
                  CheckInLibrary: the library you are logged in at.
280
                  ItemHomeLibrary: the library the item is owned by.
273
        -
281
        -
274
            - Use the checkout and fines rules of
282
            - Use the checkout and fines rules of
275
            - pref: HomeOrHoldingBranch
283
            - pref: HomeOrHoldingBranch
(-)a/t/db_dependent/Circulation/Branch.t (-7 / +72 lines)
Lines 25-31 use Koha::CirculationRules; Link Here
25
25
26
use Koha::Patrons;
26
use Koha::Patrons;
27
27
28
use Test::More tests => 17;
28
use Test::More tests => 18;
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
Lines 264-285 is_deeply( Link Here
264
        $samplebranch1->{branchcode},
264
        $samplebranch1->{branchcode},
265
        $sampleitemtype1->{itemtype},
265
        $sampleitemtype1->{itemtype},
266
    ),
266
    ),
267
    { returnbranch => 'homebranch', holdallowed => 'invalid_value', @lazy_any },
267
    { holdallowed => 'invalid_value', @lazy_any },
268
    "GetBranchitem returns holdallowed and return branch"
268
    "GetBranchitem returns holdallowed and return branch"
269
);
269
);
270
is_deeply(
270
is_deeply(
271
    GetBranchItemRule(),
271
    GetBranchItemRule(),
272
    { returnbranch => 'homebranch', holdallowed => 'from_local_hold_group', @lazy_any },
272
    { holdallowed => 'from_local_hold_group', @lazy_any },
273
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
273
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
274
);
274
);
275
is_deeply(
275
is_deeply(
276
    GetBranchItemRule( $samplebranch2->{branchcode} ),
276
    GetBranchItemRule( $samplebranch2->{branchcode} ),
277
    { returnbranch => 'holdingbranch', holdallowed => 'from_home_library', @lazy_any },
277
    { holdallowed => 'from_home_library', @lazy_any },
278
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
278
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
279
);
279
);
280
is_deeply(
280
is_deeply(
281
    GetBranchItemRule( -1, -1 ),
281
    GetBranchItemRule( -1, -1 ),
282
    { returnbranch => 'homebranch', holdallowed => 'from_local_hold_group', @lazy_any },
282
    { holdallowed => 'from_local_hold_group', @lazy_any },
283
    "With only one parametern GetBranchItemRule returns default values"
283
    "With only one parametern GetBranchItemRule returns default values"
284
);
284
);
285
285
Lines 329-333 t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); Link Here
329
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn");
329
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn");
330
t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
330
t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
331
331
332
$schema->storage->txn_rollback;
332
subtest "Test GetBranchItemRule" => sub {
333
    plan tests => 3;
334
335
    $schema->storage->txn_begin;
336
337
    $dbh->do('DELETE FROM circulation_rules');
338
339
    my $homebranch    = $builder->build( { source => 'Branch' } )->{branchcode};
340
    my $holdingbranch = $builder->build( { source => 'Branch' } )->{branchcode};
341
    my $checkinbranch = $builder->build( { source => 'Branch' } )->{branchcode};
333
342
334
- 
343
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
344
    t::lib::Mocks::mock_userenv(
345
        {
346
            patron     => $manager,
347
            branchcode => $checkinbranch,
348
        }
349
    );
350
351
    my $item = Koha::Item->new(
352
        {
353
            biblionumber  => $biblionumber,
354
            homebranch    => $homebranch,
355
            holdingbranch => $holdingbranch,
356
            itype         => $sampleitemtype1->{itemtype}
357
        }
358
    )->store;
359
360
    Koha::CirculationRules->set_rule(
361
        {
362
            branchcode   => $homebranch,
363
            itemtype     => undef,
364
            rule_name    => 'returnbranch',
365
            rule_value   => 'homebranch',
366
        }
367
    );
368
369
    Koha::CirculationRules->set_rule(
370
        {
371
            branchcode   => $holdingbranch,
372
            itemtype     => undef,
373
            rule_name    => 'returnbranch',
374
            rule_value   => 'holdingbranch',
375
        }
376
    );
377
378
    Koha::CirculationRules->set_rule(
379
        {
380
            branchcode   => $checkinbranch,
381
            itemtype     => undef,
382
            rule_name    => 'returnbranch',
383
            rule_value   => 'noreturn',
384
        }
385
    );
386
387
    t::lib::Mocks::mock_preference( 'CircControlReturnsBranch', 'ItemHomeLibrary' );
388
    is( Koha::CirculationRules->get_return_branch_policy($item), 'homebranch' );
389
390
    t::lib::Mocks::mock_preference( 'CircControlReturnsBranch', 'ItemHoldingLibrary' );
391
    is( Koha::CirculationRules->get_return_branch_policy($item), 'holdingbranch' );
392
393
    t::lib::Mocks::mock_preference( 'CircControlReturnsBranch', 'CheckInLibrary' );
394
    is( Koha::CirculationRules->get_return_branch_policy($item), 'noreturn' );
395
396
    $schema->storage->txn_rollback;
397
};
398
399
$schema->storage->txn_rollback;

Return to bug 25426