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 249-258 if ($barcode) { Link Here
249
#
249
#
250
# save the return
250
# save the return
251
#
251
#
252
    ( $returned, $messages, $issueinformation, $borrower ) =
253
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );
254
    my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
255
    $homeorholdingbranchreturn ||= 'homebranch';
256
252
257
    # get biblio description
253
    # get biblio description
258
    my $biblio = GetBiblioFromItemNumber($itemnumber);
254
    my $biblio = GetBiblioFromItemNumber($itemnumber);
Lines 269-278 if ($barcode) { Link Here
269
        );
265
        );
270
    }
266
    }
271
267
268
    # make sure return branch respects home branch circulation rules, default to homebranch
269
    my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype)->{'returnbranch'} || "homebranch";
270
    my $returnbranch = $biblio->{$hbr} ;
271
272
    $template->param(
272
    $template->param(
273
        title            => $biblio->{'title'},
273
        title            => $biblio->{'title'},
274
        homebranch       => $biblio->{'homebranch'},
274
        homebranch       => $biblio->{'homebranch'},
275
        homebranchname   => GetBranchName( $biblio->{$homeorholdingbranchreturn} ),
275
        homebranchname   => GetBranchName( $biblio->{'homebranch'} ),
276
        returnbranch     => $returnbranch,
277
        returnbranchname => GetBranchName( $returnbranch ),
276
        author           => $biblio->{'author'},
278
        author           => $biblio->{'author'},
277
        itembarcode      => $biblio->{'barcode'},
279
        itembarcode      => $biblio->{'barcode'},
278
        itemtype         => $biblio->{'itemtype'},
280
        itemtype         => $biblio->{'itemtype'},
Lines 289-294 if ($barcode) { Link Here
289
        barcode => $barcode,
291
        barcode => $barcode,
290
    );
292
    );
291
293
294
    # do the return
295
    ( $returned, $messages, $issueinformation, $borrower ) =
296
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
297
292
    if ($returned) {
298
    if ($returned) {
293
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
299
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
294
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
300
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
Lines 358-364 if ( $messages->{'WasTransfered'} ) { Link Here
358
if ( $messages->{'NeedsTransfer'} ){
364
if ( $messages->{'NeedsTransfer'} ){
359
    $template->param(
365
    $template->param(
360
        found          => 1,
366
        found          => 1,
361
        needstransfer  => 1,
367
        needstransfer  => $messages->{'NeedsTransfer'},
362
        itemnumber     => $itemnumber,
368
        itemnumber     => $itemnumber,
363
    );
369
    );
364
}
370
}
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 145-151 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
145
('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'),
145
('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'),
146
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
146
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
147
('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'),
147
('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'),
148
('HomeOrHoldingBranchReturn','homebranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check checking-in items','Choice'),
149
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
148
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
150
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
149
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
151
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
150
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 8507-8512 if ( CheckVersion($DBversion) ) { Link Here
8507
    ");
8507
    ");
8508
8508
8509
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8509
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8510
8511
$DBversion = "3.15.00.XXX";
8512
if ( CheckVersion($DBversion) ) {
8513
    $dbh->do(q{
8514
        DELETE FROM systempreferences WHERE variable = 'HomeOrHoldingBranchReturn';
8515
    });
8516
    print "Upgrade to $DBversion done (Bug 7981 - Transfer message on return. HomeOrHoldingBranchReturn syspref removed in favour of circulation rules.)\n";
8510
    SetVersion($DBversion);
8517
    SetVersion($DBversion);
8511
}
8518
}
8512
8519
(-)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 275-283 $(document).ready(function () { Link Here
275
    [% END %]
275
    [% END %]
276
276
277
    [% IF ( transfer ) %]
277
    [% IF ( transfer ) %]
278
    <!-- transfer: item with no reservation, must be returned to its home library -->
278
    <!-- transfer: item with no reservation, must be returned according to home library circulation rules -->
279
	<div id="return1" class="dialog message">
279
	<div id="return1" class="dialog message">
280
            <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>
280
            <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>
281
        </div>
281
        </div>
282
        [% IF ( soundon ) %]
282
        [% IF ( soundon ) %]
283
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
283
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
Lines 289-303 $(document).ready(function () { Link Here
289
        [% IF ( soundon ) %]
289
        [% IF ( soundon ) %]
290
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
290
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
291
        [% END %]
291
        [% END %]
292
	<div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% homebranchname %]</h3>
292
	<div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% returnbranchname %]</h3>
293
    Transfer now?<br />
293
    Transfer now?<br />
294
    <form method="post" action="returns.pl" name="mainform" id="mainform">
294
    <form method="post" action="returns.pl" name="mainform" id="mainform">
295
    [% IF itemnumber %]
295
    [% IF itemnumber %]
296
        <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;" />
296
        <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;" />
297
    [% END %]
297
    [% END %]
298
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
298
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
299
	<input type="submit" name="notransfer" value="No" class="submit" />
299
	<input type="submit" name="notransfer" value="No" class="submit" />
300
	<input type="hidden" name="tobranch" value="[% homebranch %]" />
300
	<input type="hidden" name="tobranch" value="[% returnbranch %]" />
301
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
301
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
302
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
302
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
303
        <input type="hidden" name="dropboxmode" value="[% dropboxmode %]" />
303
        <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