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

(-)a/C4/Circulation.pm (-15 / +20 lines)
Lines 1607-1612 holdallowed => Hold policy for this branch and itemtype. Possible values: Link Here
1607
returnbranch => branch to which to return item.  Possible values:
1607
returnbranch => branch to which to return item.  Possible values:
1608
  noreturn: do not return, let item remain where checked in (floating collections)
1608
  noreturn: do not return, let item remain where checked in (floating collections)
1609
  homebranch: return to item's home branch
1609
  homebranch: return to item's home branch
1610
  holdingbranch: return to issuer branch
1610
1611
1611
This searches branchitemrules in the following order:
1612
This searches branchitemrules in the following order:
1612
1613
Lines 1725-1730 fields from the reserves table of the Koha database, and Link Here
1725
C<biblioitemnumber>. It also has the key C<ResFound>, whose value is
1726
C<biblioitemnumber>. It also has the key C<ResFound>, whose value is
1726
either C<Waiting>, C<Reserved>, or 0.
1727
either C<Waiting>, C<Reserved>, or 0.
1727
1728
1729
=item C<WasReturned>
1730
1731
Value 1 if return is successful.
1732
1733
=item C<NeedsTransfer>
1734
1735
If AutomaticItemReturn is disabled, return branch is given as value of NeedsTransfer.
1736
1728
=back
1737
=back
1729
1738
1730
C<$iteminformation> is a reference-to-hash, giving information about the
1739
C<$iteminformation> is a reference-to-hash, giving information about the
Lines 1756-1762 sub AddReturn { Link Here
1756
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1765
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1757
    }
1766
    }
1758
    my $issue  = GetItemIssue($itemnumber);
1767
    my $issue  = GetItemIssue($itemnumber);
1759
#   warn Dumper($iteminformation);
1760
    if ($issue and $issue->{borrowernumber}) {
1768
    if ($issue and $issue->{borrowernumber}) {
1761
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
1769
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
1762
            or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existant borrowernumber '$issue->{borrowernumber}'\n"
1770
            or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existant borrowernumber '$issue->{borrowernumber}'\n"
Lines 1788-1796 sub AddReturn { Link Here
1788
1796
1789
        # full item data, but no borrowernumber or checkout info (no issue)
1797
        # full item data, but no borrowernumber or checkout info (no issue)
1790
        # we know GetItem should work because GetItemnumberFromBarcode worked
1798
        # we know GetItem should work because GetItemnumberFromBarcode worked
1791
    my $hbr      = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1799
    my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1792
        # get the proper branch to which to return the item
1800
        # get the proper branch to which to return the item
1793
    $hbr = $item->{$hbr} || $branch ;
1801
    my $returnbranch = $item->{$hbr} || $branch ;
1794
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1802
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1795
1803
1796
    my $borrowernumber = $borrower->{'borrowernumber'} || undef;    # we don't know if we had a borrower or not
1804
    my $borrowernumber = $borrower->{'borrowernumber'} || undef;    # we don't know if we had a borrower or not
Lines 1817-1825 sub AddReturn { Link Here
1817
1825
1818
    # check if the book is in a permanent collection....
1826
    # check if the book is in a permanent collection....
1819
    # FIXME -- This 'PE' attribute is largely undocumented.  afaict, there's no user interface that reflects this functionality.
1827
    # FIXME -- This 'PE' attribute is largely undocumented.  afaict, there's no user interface that reflects this functionality.
1820
    if ( $hbr ) {
1828
    if ( $returnbranch ) {
1821
        my $branches = GetBranches();    # a potentially expensive call for a non-feature.
1829
        my $branches = GetBranches();    # a potentially expensive call for a non-feature.
1822
        $branches->{$hbr}->{PE} and $messages->{'IsPermanent'} = $hbr;
1830
        $branches->{$returnbranch}->{PE} and $messages->{'IsPermanent'} = $returnbranch;
1823
    }
1831
    }
1824
1832
1825
    # check if the return is allowed at this branch
1833
    # check if the return is allowed at this branch
Lines 2023-2043 sub AddReturn { Link Here
2023
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2031
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2024
    }
2032
    }
2025
2033
2026
    # FIXME: make this comment intelligible.
2034
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2027
    #adding message if holdingbranch is non equal a userenv branch to return the document to homebranch
2035
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2028
    #we check, if we don't have reserv or transfert for this document, if not, return it to homebranch .
2036
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2029
2030
    if ( !$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $hbr) and not $messages->{'WrongTransfer'}){
2031
        if ( C4::Context->preference("AutomaticItemReturn"    ) or
2032
            (C4::Context->preference("UseBranchTransferLimits") and
2037
            (C4::Context->preference("UseBranchTransferLimits") and
2033
             ! IsBranchTransferAllowed($branch, $hbr, $item->{C4::Context->preference("BranchTransferLimitsType")} )
2038
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
2034
           )) {
2039
           )) {
2035
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $hbr;
2040
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
2036
            $debug and warn "item: " . Dumper($item);
2041
            $debug and warn "item: " . Dumper($item);
2037
            ModItemTransfer($item->{'itemnumber'}, $branch, $hbr);
2042
            ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
2038
            $messages->{'WasTransfered'} = 1;
2043
            $messages->{'WasTransfered'} = 1;
2039
        } else {
2044
        } else {
2040
            $messages->{'NeedsTransfer'} = 1;   # TODO: instead of 1, specify branchcode that the transfer SHOULD go to, $item->{homebranch}
2045
            $messages->{'NeedsTransfer'} = $returnbranch;
2041
        }
2046
        }
2042
    }
2047
    }
2043
2048
(-)a/circ/returns.pl (-6 / +12 lines)
Lines 240-249 if ($barcode) { Link Here
240
#
240
#
241
# save the return
241
# save the return
242
#
242
#
243
    ( $returned, $messages, $issueinformation, $borrower ) =
244
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );
245
    my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
246
    $homeorholdingbranchreturn ||= 'homebranch';
247
243
248
    # get biblio description
244
    # get biblio description
249
    my $biblio = GetBiblioFromItemNumber($itemnumber);
245
    my $biblio = GetBiblioFromItemNumber($itemnumber);
Lines 260-269 if ($barcode) { Link Here
260
        );
256
        );
261
    }
257
    }
262
258
259
    # make sure return branch respects home branch circulation rules, default to homebranch
260
    my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype)->{'returnbranch'} || "homebranch";
261
    my $returnbranch = $biblio->{$hbr} ;
262
263
    $template->param(
263
    $template->param(
264
        title            => $biblio->{'title'},
264
        title            => $biblio->{'title'},
265
        homebranch       => $biblio->{'homebranch'},
265
        homebranch       => $biblio->{'homebranch'},
266
        homebranchname   => GetBranchName( $biblio->{$homeorholdingbranchreturn} ),
266
        homebranchname   => GetBranchName( $biblio->{'homebranch'} ),
267
        returnbranch     => $returnbranch,
268
        returnbranchname => GetBranchName( $returnbranch ),
267
        author           => $biblio->{'author'},
269
        author           => $biblio->{'author'},
268
        itembarcode      => $biblio->{'barcode'},
270
        itembarcode      => $biblio->{'barcode'},
269
        itemtype         => $biblio->{'itemtype'},
271
        itemtype         => $biblio->{'itemtype'},
Lines 279-284 if ($barcode) { Link Here
279
        barcode => $barcode,
281
        barcode => $barcode,
280
    );
282
    );
281
283
284
    # do the return
285
    ( $returned, $messages, $issueinformation, $borrower ) =
286
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
287
282
    if ($returned) {
288
    if ($returned) {
283
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
289
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
284
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
290
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
Lines 348-354 if ( $messages->{'WasTransfered'} ) { Link Here
348
if ( $messages->{'NeedsTransfer'} ){
354
if ( $messages->{'NeedsTransfer'} ){
349
    $template->param(
355
    $template->param(
350
        found          => 1,
356
        found          => 1,
351
        needstransfer  => 1,
357
        needstransfer  => $messages->{'NeedsTransfer'},
352
        itemnumber     => $itemnumber,
358
        itemnumber     => $itemnumber,
353
    );
359
    );
354
}
360
}
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 142-148 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
142
('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch\'s items to emphasize. If PatronBranch, emphasize the logged in user\'s library\'s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha\'s Apache configuration file.','Choice'),
142
('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch\'s items to emphasize. If PatronBranch, emphasize the logged in user\'s library\'s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha\'s Apache configuration file.','Choice'),
143
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
143
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
144
('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'),
144
('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'),
145
('HomeOrHoldingBranchReturn','homebranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check checking-in items','Choice'),
146
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
145
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
147
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
146
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
148
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
147
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 8502-8507 if ( CheckVersion($DBversion) ) { Link Here
8502
    ");
8502
    ");
8503
8503
8504
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8504
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8505
8506
$DBversion = "3.15.00.XXX";
8507
if ( CheckVersion($DBversion) ) {
8508
    $dbh->do(q{
8509
        DELETE FROM systempreferences WHERE variable = 'HomeOrHoldingBranchReturn';
8510
    });
8511
    print "Upgrade to $DBversion done (Bug 7981 - Transfer message on return. HomeOrHoldingBranchReturn syspref removed in favour of circulation rules.)\n";
8505
    SetVersion($DBversion);
8512
    SetVersion($DBversion);
8506
}
8513
}
8507
8514
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-7 lines)
Lines 366-378 Circulation: Link Here
366
            - <br>Leave this field empty if you don't want to charge the user for lost items.
366
            - <br>Leave this field empty if you don't want to charge the user for lost items.
367
            - <br>(Used when the longoverdue.pl script is called without the --charge parameter)
367
            - <br>(Used when the longoverdue.pl script is called without the --charge parameter)
368
        -
368
        -
369
            - On checkin route the returned item to
370
            - pref: HomeOrHoldingBranchReturn
371
              type: choice
372
              choices:
373
                  homebranch: the library the item is from.
374
                  holdingbranch: the library the item was checked out from.
375
        -
376
            - "When issuing an item that has been marked as lost, "
369
            - "When issuing an item that has been marked as lost, "
377
            - pref: IssueLostItem
370
            - pref: IssueLostItem
378
              choices:
371
              choices:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-5 / +5 lines)
Lines 262-270 $(document).ready(function () { Link Here
262
    [% END %]
262
    [% END %]
263
263
264
    [% IF ( transfer ) %]
264
    [% IF ( transfer ) %]
265
    <!-- transfer: item with no reservation, must be returned to its home library -->
265
    <!-- transfer: item with no reservation, must be returned according to home library circulation rules -->
266
	<div id="return1" class="dialog message">
266
	<div id="return1" class="dialog message">
267
            <h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title or "item" |html %]</a> to [% homebranchname %]<br/>( <a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> )</h3>
267
            <h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title or "item" |html %]</a> to [% returnbranchname %]<br/>( <a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;branchcode=[% returnbranch %]&amp;op=slip'); return true;">Print slip</a> )</h3>
268
        </div>
268
        </div>
269
        [% IF ( soundon ) %]
269
        [% IF ( soundon ) %]
270
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
270
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
Lines 276-290 $(document).ready(function () { Link Here
276
        [% IF ( soundon ) %]
276
        [% IF ( soundon ) %]
277
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
277
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
278
        [% END %]
278
        [% END %]
279
	<div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% homebranchname %]</h3>
279
	<div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% returnbranchname %]</h3>
280
    Transfer now?<br />
280
    Transfer now?<br />
281
    <form method="post" action="returns.pl" name="mainform" id="mainform">
281
    <form method="post" action="returns.pl" name="mainform" id="mainform">
282
    [% IF itemnumber %]
282
    [% IF itemnumber %]
283
        <input type="submit" name="dotransfer" value="Yes, Print slip" class="print" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;" />
283
        <input type="submit" name="dotransfer" value="Yes, Print slip" class="print" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% returnbranch %]&amp;op=slip'); return true;" />
284
    [% END %]
284
    [% END %]
285
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
285
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
286
	<input type="submit" name="notransfer" value="No" class="submit" />
286
	<input type="submit" name="notransfer" value="No" class="submit" />
287
	<input type="hidden" name="tobranch" value="[% homebranch %]" />
287
	<input type="hidden" name="tobranch" value="[% returnbranch %]" />
288
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
288
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
289
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
289
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
290
        <input type="hidden" name="dropboxmode" value="[% dropboxmode %]" />
290
        <input type="hidden" name="dropboxmode" value="[% dropboxmode %]" />
(-)a/t/db_dependent/Circulation_Branch.t (-18 / +107 lines)
Lines 7-23 use C4::Branch; Link Here
7
use C4::Circulation;
7
use C4::Circulation;
8
use C4::Items;
8
use C4::Items;
9
use C4::Context;
9
use C4::Context;
10
10
use Data::Dumper;
11
use Test::More tests => 10;
11
use Test::More tests => 13;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Circulation');
14
    use_ok('C4::Circulation');
15
}
15
}
16
16
17
can_ok( 'C4::Circulation', qw(
17
can_ok( 'C4::Circulation', qw(
18
                            GetBranchBorrowerCircRule
18
    AddIssue
19
                            GetBranchItemRule
19
    AddReturn
20
                            )
20
    GetBranchBorrowerCircRule
21
    GetBranchItemRule
22
    GetIssuingRule
23
    )
21
);
24
);
22
25
23
#Start transaction
26
#Start transaction
Lines 160-165 $sth->execute( Link Here
160
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
163
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
161
);
164
);
162
165
166
#Add biblio and item
167
my $record = MARC::Record->new();
168
$record->append_fields(
169
    MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) );
170
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' );
171
172
# item 2 has home branch and holding branch samplebranch1
173
my @sampleitem1 = C4::Items::AddItem(
174
    {
175
        barcode        => 'barcode_1',
176
        itemcallnumber => 'callnumber1',
177
        homebranch     => $samplebranch1->{branchcode},
178
        holdingbranch  => $samplebranch1->{branchcode}
179
    },
180
    $biblionumber
181
);
182
my $item_id1    = $sampleitem1[2];
183
184
# item 2 has holding branch samplebranch2
185
my @sampleitem2 = C4::Items::AddItem(
186
    {
187
        barcode        => 'barcode_2',
188
        itemcallnumber => 'callnumber2',
189
        homebranch     => $samplebranch2->{branchcode},
190
        holdingbranch  => $samplebranch1->{branchcode}
191
    },
192
    $biblionumber
193
);
194
my $item_id2 = $sampleitem2[2];
195
196
# item 3 has item type sampleitemtype2 with noreturn policy
197
my @sampleitem3 = C4::Items::AddItem(
198
    {
199
        barcode        => 'barcode_3',
200
        itemcallnumber => 'callnumber3',
201
        homebranch     => $samplebranch2->{branchcode},
202
        holdingbranch  => $samplebranch2->{branchcode},
203
        itype          => $sampleitemtype2->{itemtype}
204
    },
205
    $biblionumber
206
);
207
my $item_id3 = $sampleitem3[2];
208
209
#Add borrower
210
my $borrower_id1 = C4::Members::AddMember(
211
    firstname    => 'firstname1',
212
    surname      => 'surname1 ',
213
    categorycode => $samplecat->{categorycode},
214
    branchcode   => $samplebranch1->{branchcode},
215
);
216
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1);
217
163
$query =
218
$query =
164
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
219
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
165
$dbh->do(
220
$dbh->do(
Lines 167-179 $dbh->do( Link Here
167
    $samplebranch1->{branchcode},
222
    $samplebranch1->{branchcode},
168
    $samplecat->{categorycode}, 5
223
    $samplecat->{categorycode}, 5
169
);
224
);
170
$query =
225
171
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
173
    3, 1, $samplebranch2->{branchcode} );
174
$query =
226
$query =
175
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
227
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
176
$dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode} );
228
$dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' );
229
230
$query =
231
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
232
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 3, 1, 'holdingbranch' );
177
233
178
$query =
234
$query =
179
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
235
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
Lines 181-192 $sth = $dbh->prepare($query); Link Here
181
$sth->execute(
237
$sth->execute(
182
    $samplebranch1->{branchcode},
238
    $samplebranch1->{branchcode},
183
    $sampleitemtype1->{itemtype},
239
    $sampleitemtype1->{itemtype},
184
    5, $samplebranch1->{branchcode}
240
    5, 'homebranch'
241
);
242
$sth->execute(
243
    $samplebranch2->{branchcode},
244
    $sampleitemtype1->{itemtype},
245
    5, 'holdingbranch'
185
);
246
);
186
$sth->execute(
247
$sth->execute(
187
    $samplebranch2->{branchcode},
248
    $samplebranch2->{branchcode},
188
    $sampleitemtype2->{itemtype},
249
    $sampleitemtype2->{itemtype},
189
    5, $samplebranch1->{branchcode}
250
    5, 'noreturn'
190
);
251
);
191
252
192
#Test GetBranchBorrowerCircRule
253
#Test GetBranchBorrowerCircRule
Lines 220-242 is_deeply( Link Here
220
        $samplebranch1->{branchcode},
281
        $samplebranch1->{branchcode},
221
        $sampleitemtype1->{itemtype}
282
        $sampleitemtype1->{itemtype}
222
    ),
283
    ),
223
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 5 },
284
    { returnbranch => 'homebranch', holdallowed => 5 },
224
    "GetBranchitem returns holdallowed and return branch"
285
    "GetBranchitem returns holdallowed and return branch"
225
);
286
);
226
is_deeply(
287
is_deeply(
227
    GetBranchItemRule(),
288
    GetBranchItemRule(),
228
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
289
    { returnbranch => 'homebranch', holdallowed => 3 },
229
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
290
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
230
);
291
);
231
is_deeply(
292
is_deeply(
232
    GetBranchItemRule( $samplebranch1->{branchcode} ),
293
    GetBranchItemRule( $samplebranch2->{branchcode} ),
233
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
294
    { returnbranch => 'holdingbranch', holdallowed => 1 },
234
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
295
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
235
);
296
);
236
is_deeply(
297
is_deeply(
237
    GetBranchItemRule( -1, -1 ),
298
    GetBranchItemRule( -1, -1 ),
238
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
299
    { returnbranch => 'homebranch', holdallowed => 3 },
239
    "With only one parametern GetBranchItemRule returns default values"
300
    "With only one parametern GetBranchItemRule returns default values"
240
);
301
);
241
302
303
# Test return policies
304
C4::Context->set_preference('AutomaticItemReturn','0');
305
306
# item1 returned at branch2 should trigger transfer to homebranch
307
$query =
308
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
309
$dbh->do( $query, {}, $borrower_id1, $item_id1, $samplebranch1->{branchcode} );
310
311
my ($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_1',
312
    $samplebranch2->{branchcode});
313
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects default return policy - return to homebranch" );
314
315
# item2 returned at branch2 should trigger transfer to holding branch
316
$query =
317
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
318
$dbh->do( $query, {}, $borrower_id1, $item_id2, $samplebranch2->{branchcode} );
319
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2',
320
    $samplebranch2->{branchcode});
321
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects branch return policy - item2->homebranch policy = 'holdingbranch'" );
322
323
# item3 should not trigger transfer - floating collection
324
$query =
325
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
326
$dbh->do( $query, {}, $borrower_id1, $item_id3, $samplebranch1->{branchcode} );
327
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_3',
328
    $samplebranch1->{branchcode});
329
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn");
330
331
242
$dbh->rollback;
332
$dbh->rollback;
243
- 

Return to bug 7981