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

(-)a/C4/Circulation.pm (-24 / +76 lines)
Lines 1041-1049 sub CanBookBeIssued { Link Here
1041
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
1041
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
1042
}
1042
}
1043
1043
1044
=head2 CanBookBeReturned
1044
=head2 CanItemBeReturned
1045
1045
1046
  ($returnallowed, $message) = CanBookBeReturned($item, $branch)
1046
  ($returnallowed, $message) = CanItemBeReturned($item, $branch)
1047
1047
1048
Check whether the item can be returned to the provided branch
1048
Check whether the item can be returned to the provided branch
1049
1049
Lines 1061-1090 Returns: Link Here
1061
1061
1062
=item C<$returnallowed> is 0 or 1, corresponding to whether the return is allowed (1) or not (0)
1062
=item C<$returnallowed> is 0 or 1, corresponding to whether the return is allowed (1) or not (0)
1063
1063
1064
=item C<$message> is the branchcode where the item SHOULD be returned, if the return is not allowed
1064
=item C<$message> If $message->{Wrongbranch},
1065
                      $message->{Wrongbranch} is the branchcode where the item SHOULD be returned, if the return is not allowed.
1066
                  If $message->{BranchTransferDenied},
1067
                      $message->{BranchTransferDenied} is the CheckBranchTransferAllowed() error code.
1065
1068
1066
=back
1069
=back
1067
1070
1068
=cut
1071
=cut
1069
1072
1070
sub CanBookBeReturned {
1073
sub CanItemBeReturned {
1071
  my ($item, $branch) = @_;
1074
  my ($item, $branch) = @_;
1072
  my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1075
  my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1073
1076
1074
  # assume return is allowed to start
1077
  # assume return is allowed to start
1075
  my $allowed = 1;
1078
  my $allowed = 1;
1079
  my $toBranch; #The branch this item needs to be transferred.
1076
  my $message;
1080
  my $message;
1077
1081
1078
  # identify all cases where return is forbidden
1082
  # identify all cases where return is forbidden and determine the transfer destination branch
1079
  if ($allowreturntobranch eq 'homebranch' && $branch ne $item->{'homebranch'}) {
1083
  if ($allowreturntobranch eq 'homebranch') {
1080
     $allowed = 0;
1084
    $toBranch = $item->{'homebranch'};
1081
     $message = $item->{'homebranch'};
1085
    if ($branch ne $toBranch) {
1082
  } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->{'holdingbranch'}) {
1086
      $allowed = 0;
1083
     $allowed = 0;
1087
      $message->{Wrongbranch} = $toBranch;
1084
     $message = $item->{'holdingbranch'};
1088
    }
1085
  } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->{'homebranch'} && $branch ne $item->{'holdingbranch'}) {
1089
  }
1086
     $allowed = 0;
1090
  elsif ($allowreturntobranch eq 'holdingbranch') {
1087
     $message = $item->{'homebranch'}; # FIXME: choice of homebranch is arbitrary
1091
    $toBranch = $item->{'holdingbranch'};
1092
    if ($branch ne $toBranch) {
1093
      $allowed = 0;
1094
      $message->{Wrongbranch} = $toBranch;
1095
    }
1096
  }
1097
  elsif ($allowreturntobranch eq 'homeorholdingbranch') {
1098
    $toBranch = $item->{'homebranch'}; # FIXME: choice of homebranch is arbitrary
1099
    if ($branch ne $item->{'homebranch'} && $branch ne $item->{'holdingbranch'}) {
1100
      $allowed = 0;
1101
      $message->{Wrongbranch} = $toBranch;
1102
    }
1103
  }
1104
  else {
1105
    #
1106
    $toBranch = $item->{'homebranch'};
1107
  }
1108
  # It needs to be ok to transfer the Item from the check-in branch to the $toBranch, for the Item to be accepted.
1109
  #CheckBranchTransferAllowed(), returns [1,undef] if transfer allowed, [0,errorMsg] if denied.
1110
  if ( '1' ne   ( my $transferOk = CheckBranchTransferAllowed($toBranch, $branch, $item, undef) )   ) {
1111
	$allowed = 0;
1112
    $message->{BranchTransferDenied} = $transferOk;
1088
  }
1113
  }
1089
1114
1090
  return ($allowed, $message);
1115
  return ($allowed, $message);
Lines 1631-1637 sub GetBranchItemRule { Link Here
1631
=head2 AddReturn
1656
=head2 AddReturn
1632
1657
1633
  ($doreturn, $messages, $iteminformation, $borrower) =
1658
  ($doreturn, $messages, $iteminformation, $borrower) =
1634
      &AddReturn($barcode, $branch, $exemptfine, $dropbox);
1659
      &AddReturn($barcode, $branch, $exemptfine, $dropbox, $overrides);
1635
1660
1636
Returns a book.
1661
Returns a book.
1637
1662
Lines 1650-1655 overdue charges are applied and C<$dropbox> is true, the last charge Link Here
1650
will be removed.  This assumes that the fines accrual script has run
1675
will be removed.  This assumes that the fines accrual script has run
1651
for _today_.
1676
for _today_.
1652
1677
1678
=item C<$overrides> A hash with various overrides as keys:
1679
$overrides->{overrideBranchTransferDenied} == 1
1680
TODO:: $exemptFine should be moved under this one as well, but the rule is,
1681
if it's not broken, don't fix it :)
1682
1653
=back
1683
=back
1654
1684
1655
C<&AddReturn> returns a list of four items:
1685
C<&AddReturn> returns a list of four items:
Lines 1685-1690 This book has was returned to the wrong branch. The value is a hashref Link Here
1685
so that C<$messages->{Wrongbranch}->{Wrongbranch}> and C<$messages->{Wrongbranch}->{Rightbranch}>
1715
so that C<$messages->{Wrongbranch}->{Wrongbranch}> and C<$messages->{Wrongbranch}->{Rightbranch}>
1686
contain the branchcode of the incorrect and correct return library, respectively.
1716
contain the branchcode of the incorrect and correct return library, respectively.
1687
1717
1718
=item C<BranchTransferDenied>
1719
1720
Implements the UseBranchTransferLimits-preference.
1721
This book cannot be transferred from this branch to the Item's homebranch, or other branch defined by
1722
the  AllowReturnToBranch-preference.
1723
C<$messages->{BranchTransferDenied}> contains the From-, To-branches and the code of failure.
1724
See CanBookBeIssued() for more.
1725
1688
=item C<ResFound>
1726
=item C<ResFound>
1689
1727
1690
The item was reserved. The value is a reference-to-hash whose keys are
1728
The item was reserved. The value is a reference-to-hash whose keys are
Lines 1703-1709 patron who last borrowed the book. Link Here
1703
=cut
1741
=cut
1704
1742
1705
sub AddReturn {
1743
sub AddReturn {
1706
    my ( $barcode, $branch, $exemptfine, $dropbox ) = @_;
1744
    my ( $barcode, $branch, $exemptfine, $dropbox, $overrides ) = @_;
1707
1745
1708
    if ($branch and not GetBranchDetail($branch)) {
1746
    if ($branch and not GetBranchDetail($branch)) {
1709
        warn "AddReturn error: branch '$branch' not found.  Reverting to " . C4::Context->userenv->{'branch'};
1747
        warn "AddReturn error: branch '$branch' not found.  Reverting to " . C4::Context->userenv->{'branch'};
Lines 1722-1728 sub AddReturn { Link Here
1722
    unless ($itemnumber) {
1760
    unless ($itemnumber) {
1723
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1761
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1724
    }
1762
    }
1725
    my $issue  = GetItemIssue($itemnumber);
1763
    my $issue = GetItemIssue($itemnumber);
1726
#   warn Dumper($iteminformation);
1764
#   warn Dumper($iteminformation);
1727
    if ($issue and $issue->{borrowernumber}) {
1765
    if ($issue and $issue->{borrowernumber}) {
1728
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
1766
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
Lines 1758-1771 sub AddReturn { Link Here
1758
    }
1796
    }
1759
1797
1760
    # check if the return is allowed at this branch
1798
    # check if the return is allowed at this branch
1761
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
1799
    my ($returnallowed, $message) = CanItemBeReturned($item, $branch);
1762
    unless ($returnallowed){
1800
    unless ($returnallowed){
1763
        $messages->{'Wrongbranch'} = {
1801
        if (defined $message->{Wrongbranch}) {
1764
            Wrongbranch => $branch,
1802
            $messages->{'Wrongbranch'} = {
1765
            Rightbranch => $message
1803
                Wrongbranch => $branch,
1766
        };
1804
                Rightbranch => $message
1767
        $doreturn = 0;
1805
            };
1768
        return ( $doreturn, $messages, $issue, $borrower );
1806
            $doreturn = 0;
1807
            return ( $doreturn, $messages, $issue, $borrower );
1808
        }
1809
        if (defined $message->{BranchTransferDenied} &&
1810
                (my @msgs = split('->', $message->{BranchTransferDenied}) ) &&
1811
                ( ! exists $overrides->{overrideBranchTransferDenied} )      ) {
1812
            $messages->{BranchTransferDenied} = {
1813
                Frombranch => $msgs[0],
1814
                Tobranch => $msgs[1],
1815
                Code => $msgs[2]
1816
            };
1817
            $doreturn = 0;
1818
            return ( $doreturn, $messages, $issue, $borrower );
1819
        }
1820
        #Some blocks can be overridden, so keep moving forward.
1769
    }
1821
    }
1770
1822
1771
    if ( $item->{'withdrawn'} ) { # book has been cancelled
1823
    if ( $item->{'withdrawn'} ) { # book has been cancelled
(-)a/C4/SIP/ILS/Transaction/Checkin.pm (+4 lines)
Lines 70-75 sub do_checkin { Link Here
70
        $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
70
        $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
71
        $self->alert_type('04');            # send to other branch
71
        $self->alert_type('04');            # send to other branch
72
    }
72
    }
73
	if ($messages->{BranchTransferDenied}) {
74
        $self->destination_loc($messages->{BranchTransferDenied}->{Tobranch});
75
        $self->alert_type('04');            # send to other branch
76
    }
73
    if ($messages->{WrongTransfer}) {
77
    if ($messages->{WrongTransfer}) {
74
        $self->destination_loc($messages->{WrongTransfer});
78
        $self->destination_loc($messages->{WrongTransfer});
75
        $self->alert_type('04');            # send to other branch
79
        $self->alert_type('04');            # send to other branch
(-)a/C4/SIP/README (+6 lines)
Lines 22-24 is already using that facililty, just change the definition of Link Here
22
22
23
Make sure to update your syslog configuration to capture facility
23
Make sure to update your syslog configuration to capture facility
24
'local6' and record it.
24
'local6' and record it.
25
26
UNIT TEST CASES!
27
-----------------
28
Remember that the SIP-server is a remote program and you cannot make test cases which depend on non-permanent DB changes,
29
Like when using the $dbh->{AutoCommit} = 0.
30
All testing material needs to be INSERTed for real to the Koha DB and cannot be just rolled back.
(-)a/C4/SIP/t/08checkin.t (-9 / +92 lines)
Lines 3-8 Link Here
3
3
4
use strict;
4
use strict;
5
use warnings;
5
use warnings;
6
#Can't run this test case without this directive from this directory.
7
# Can't run this test case from any other directory without some kind of a hack either.
8
use lib('../');
9
10
use lib('../../../t/db_dependent/');
11
use UseBranchTransferLimits::PreparedTestEnvironment;
12
6
use Clone qw(clone);
13
use Clone qw(clone);
7
14
8
use Sip::Constants qw(:all);
15
use Sip::Constants qw(:all);
Lines 24-29 use SIPtest qw(:basic :user1 :item1); Link Here
24
# alert: Y or N
31
# alert: Y or N
25
# date
32
# date
26
33
34
print "WARNING! This test will INSERT the necessary testing material PERMANENTLY to your Koha DB.\n";
35
print "You have 10 seconds to press CTRL-C.";
36
sleep(10);
37
38
27
my $checkout_template = {
39
my $checkout_template = {
28
    id  => "Checkin: prep: check out item ($item_barcode)",
40
    id  => "Checkin: prep: check out item ($item_barcode)",
29
    msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC|",
41
    msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC|",
Lines 31-36 my $checkout_template = { Link Here
31
    fields => [],
43
    fields => [],
32
};
44
};
33
45
46
34
my $checkin_test_template = {
47
my $checkin_test_template = {
35
    id  => "Checkin: Item ($item_barcode) is checked out",
48
    id  => "Checkin: Item ($item_barcode) is checked out",
36
    msg => "09N20060102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|AC$password|",
49
    msg => "09N20060102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|AC$password|",
Lines 56-70 my $checkin_test_template = { Link Here
56
          required => 0, }, # 3M Extension
69
          required => 0, }, # 3M Extension
57
   ],};
70
   ],};
58
71
59
my @tests = (
60
	$SIPtest::login_test,
61
	$SIPtest::sc_status_test,
62
	$checkout_template,
63
	$checkin_test_template,
64
	);
65
66
my $test;
72
my $test;
67
68
# Checkin item that's not checked out.  Basically, this
73
# Checkin item that's not checked out.  Basically, this
69
# is identical to the first case, except the header says that
74
# is identical to the first case, except the header says that
70
# the ILS didn't check the item in, and there's no patron id.
75
# the ILS didn't check the item in, and there's no patron id.
Lines 73-79 $test->{id} = 'Checkin: Item not checked out'; Link Here
73
$test->{pat} = qr/^100[NY][NYU][NY]$datepat/o;
78
$test->{pat} = qr/^100[NY][NYU][NY]$datepat/o;
74
$test->{fields} = [grep $_->{field} ne FID_PATRON_ID, @{$test->{fields}}];
79
$test->{fields} = [grep $_->{field} ne FID_PATRON_ID, @{$test->{fields}}];
75
80
76
push @tests, $test;
81
########################################
82
#>> Checking UseBranchTransferLimits >>#
83
########################################
84
85
### Use case1: BranchTransfer denied.
86
87
my $branchtransfer_checkout_ok = {
88
    id  => "Checkin: prep: BranchTransfer check out item (".$itemCPLFull->{barcode}." from CPL)",
89
    msg => "11YN20060329    203000                  AO$instid|AA".$borrower->{cardnumber}."|AB".$itemCPLFull->{barcode}."|AC|",
90
    pat => qr/^121N[NYU][NY]$datepat/,
91
    fields => [],
92
};
93
my $branchtransfer_checkin_fails = {
94
    id  => "Checkin: BranchTransfer Item (".$itemCPLFull->{barcode}.") check out denied to FFL",
95
    msg => "09N20060102    08423620060113    084235AP".'FFL'."|AO$instid|AB".$itemCPLFull->{barcode}."|AC$password|",
96
    pat => qr/^101[NY][NYU]Y$datepat/,
97
    fields => [
98
        $SIPtest::field_specs{(FID_INST_ID   )},
99
        $SIPtest::field_specs{(FID_SCREEN_MSG)},
100
        $SIPtest::field_specs{(FID_PRINT_LINE)},
101
        { field    => FID_PATRON_ID,
102
          pat      => qr/^$borrower->{cardnumber}$/,
103
          required => 1, },
104
        { field    => FID_ITEM_ID,
105
          pat      => qr/^$itemCPLFull->{barcode}$/,
106
          required => 1, },
107
        { field    => FID_PERM_LOCN,
108
          pat      => $textpat,
109
          required => 1, },
110
        { field    => FID_TITLE_ID,
111
          pat      => qr/^$biblioitem->{title}\s*$/,
112
          required => 1, }, # not required by the spec.
113
        { field    => FID_DESTINATION_LOCATION,
114
          pat      => qr/^FFL\s*$/,
115
          required => 0, }, # 3M Extension
116
   ],};
117
118
### Use case2: BranchTransfer allowed.
119
120
my $branchtransfer_checkin_ok = {
121
    id  => "Checkin: BranchTransfer Item (".$itemCPLFull->{barcode}.") check out allowed to IPT",
122
    msg => "09N20060102    08423620060113    084235AP".'IPT'."|AO$instid|AB".$itemCPLFull->{barcode}."|AC$password|",
123
    pat => qr/^101[NY][NYU]N$datepat/,
124
    fields => [
125
        $SIPtest::field_specs{(FID_INST_ID   )},
126
        $SIPtest::field_specs{(FID_SCREEN_MSG)},
127
        $SIPtest::field_specs{(FID_PRINT_LINE)},
128
        { field    => FID_PATRON_ID,
129
          pat      => qr/^$borrower->{cardnumber}$/,
130
          required => 1, },
131
        { field    => FID_ITEM_ID,
132
          pat      => qr/^$itemCPLFull->{barcode}$/,
133
          required => 1, },
134
        { field    => FID_PERM_LOCN,
135
          pat      => $textpat,
136
          required => 1, },
137
        { field    => FID_TITLE_ID,
138
          pat      => qr/^$biblioitem->{title}\s*$/,
139
          required => 1, }, # not required by the spec.
140
        { field    => FID_DESTINATION_LOCATION,
141
          pat      => qr/^IPT\s*$/,
142
          required => 0, }, # 3M Extension
143
   ],};
144
145
#######################################
146
#<< UseBranchTransferLimits Checked <<#
147
#######################################
148
149
150
my @tests = (
151
	$SIPtest::login_test,
152
	$SIPtest::sc_status_test,
153
	$checkout_template,
154
	$checkin_test_template,
155
    $test,
156
    $branchtransfer_checkout_ok,
157
    $branchtransfer_checkin_fails,
158
    $branchtransfer_checkin_ok,
159
);
77
160
78
# 
161
# 
79
# Still need tests for magnetic media
162
# Still need tests for magnetic media
(-)a/circ/returns.pl (-1 / +19 lines)
Lines 124-129 foreach ( $query->param ) { Link Here
124
    push( @inputloop, \%input );
124
    push( @inputloop, \%input );
125
}
125
}
126
126
127
### Build the overrides-object used to signal various modules about different overrides.
128
my $overrides;
129
130
#Used to skip the UseBranchTransferLimits-check in AddReserve.
131
if ($query->param('overrideBranchTransferDenied')) {
132
	$overrides->{overrideBranchTransferDenied} = 1;
133
}
134
135
127
############
136
############
128
# Deal with the requests....
137
# Deal with the requests....
129
138
Lines 216-222 if ($barcode) { Link Here
216
# save the return
225
# save the return
217
#
226
#
218
    ( $returned, $messages, $issueinformation, $borrower ) =
227
    ( $returned, $messages, $issueinformation, $borrower ) =
219
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode);     # do the return
228
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $overrides);     # do the return
220
    my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
229
    my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
221
    $homeorholdingbranchreturn ||= 'homebranch';
230
    $homeorholdingbranchreturn ||= 'homebranch';
222
231
Lines 329-334 if ( $messages->{'Wrongbranch'} ){ Link Here
329
    );
338
    );
330
}
339
}
331
340
341
if ( $messages->{'BranchTransferDenied'} ){
342
    $template->param(
343
        BranchTransferDenied => $messages->{'BranchTransferDenied'},
344
    );
345
}
346
332
# case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
347
# case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
333
348
334
if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
349
if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
Lines 440-445 foreach my $code ( keys %$messages ) { Link Here
440
    elsif ( $code eq 'WasTransfered' ) {
455
    elsif ( $code eq 'WasTransfered' ) {
441
        ;    # FIXME... anything to do here?
456
        ;    # FIXME... anything to do here?
442
    }
457
    }
458
	elsif ( $code eq 'BranchTransferDenied' ) {
459
		;	# I am confused as well # FIXME... anything to do here?
460
	}
443
    elsif ( $code eq 'withdrawn' ) {
461
    elsif ( $code eq 'withdrawn' ) {
444
        $err{withdrawn} = 1;
462
        $err{withdrawn} = 1;
445
        $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
463
        $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (+14 lines)
Lines 91-96 $(document).ready(function () { Link Here
91
<div class="dialog alert"><h3>Cannot check in</h3><p>This item must be checked in at its home library. <strong>NOT CHECKED IN</strong></p>
91
<div class="dialog alert"><h3>Cannot check in</h3><p>This item must be checked in at its home library. <strong>NOT CHECKED IN</strong></p>
92
</div>
92
</div>
93
[% END %]
93
[% END %]
94
[% IF ( BranchTransferDenied ) %]
95
<div class="dialog alert"><h3>Cannot check in</h3>
96
	<p>Cannot receive this item because it cannot be transferred to it's original pickup location. This branch transfer rule blocks the check-in:<br/>
97
		[% BranchTransferDenied.Frombranch %] -> [% BranchTransferDenied.Tobranch %] -> [% BranchTransferDenied.Code %]
98
	</p>
99
	[% IF CAN_user_circulate %]
100
	<form method="post" action="returns.pl" class="confirm">
101
        <input type="hidden" name="barcode" value="[% itembarcode %]" />
102
        <input type="hidden" name="overrideBranchTransferDenied" value="1" />
103
        <input type="submit" value="Override" class="deny" />
104
    </form>
105
	[% END %]
106
</div>
107
[% END %]
94
<!-- case of a mistake in transfer loop -->
108
<!-- case of a mistake in transfer loop -->
95
[% IF ( WrongTransfer ) %]<div id="return2" class="dialog message"><!-- WrongTransfer --><h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title |html %]</a> to [% TransferWaitingAt | $KohaBranchName %]</h3><h3><a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> or <a href="/cgi-bin/koha/circ/returns.pl?itemnumber=[% itemnumber %]&amp;canceltransfer=1">Cancel transfer</a></h3>
109
[% IF ( WrongTransfer ) %]<div id="return2" class="dialog message"><!-- WrongTransfer --><h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title |html %]</a> to [% TransferWaitingAt | $KohaBranchName %]</h3><h3><a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> or <a href="/cgi-bin/koha/circ/returns.pl?itemnumber=[% itemnumber %]&amp;canceltransfer=1">Cancel transfer</a></h3>
96
[% IF ( wborcnum ) %]<h5>Hold for:</h5>
110
[% IF ( wborcnum ) %]<h5>Hold for:</h5>
(-)a/t/db_dependent/Circulation/CheckBranchTransferAllowed.t (-105 / +29 lines)
Lines 1-9 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 20;
2
use Test::More tests => 24;
3
4
use lib('../');
5
use UseBranchTransferLimits::PreparedTestEnvironment qw($biblioitem $itemCPLFull $itemCPLLite $borrower);
3
6
4
use C4::Circulation;
7
use C4::Circulation;
5
use C4::Context;
8
use C4::Context;
6
use C4::Record;
9
use C4::Record;
10
use C4::Members;
7
11
8
my $dbh = C4::Context->dbh;
12
my $dbh = C4::Context->dbh;
9
$dbh->{AutoCommit} = 0;
13
$dbh->{AutoCommit} = 0;
Lines 15-20 my $originalBranchTransferLimitsType = C4::Context->preference('BranchTransferLi Link Here
15
sub runTestsForCCode {
19
sub runTestsForCCode {
16
    my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_;
20
    my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_;
17
    
21
    
22
    C4::Context->set_preference("BranchTransferLimitsType", 'ccode');
23
    
18
    print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n";
24
    print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n";
19
    
25
    
20
    #howto use:               CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] );
26
    #howto use:               CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] );
Lines 53-58 sub runTestsForCCode { Link Here
53
sub runTestsForItype {
59
sub runTestsForItype {
54
    my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_;
60
    my ($itemCPLFull, $itemCPLLite, $biblioitem) = @_;
55
    
61
    
62
    C4::Context->set_preference("BranchTransferLimitsType", 'itemtype');
63
    
56
    print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n";
64
    print 'Running tests for '.C4::Context->preference("BranchTransferLimitsType")."\n";
57
    
65
    
58
    #howto use:               CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] );
66
    #howto use:               CheckBranchTransferAllowed( $toBranch, $fromBranch, $item, $biblioitem] );
Lines 88-208 sub runTestsForItype { Link Here
88
}
96
}
89
### Tests prepared
97
### Tests prepared
90
98
91
### Preparing our generic testing data ###
99
### Run them tests!
92
93
#Set the item variables
94
my $ccode = 'FANTASY';
95
my $itemtype = 'BK';
96
97
## Add a example Bibliographic record
98
my $bibFramework = ''; #Using the default bibliographic framework.
99
my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
100
<record format="MARC21" type="Bibliographic">
101
  <leader>00000cim a22000004a 4500</leader>
102
  <controlfield tag="001">1001</controlfield>
103
  <controlfield tag="005">2013-06-03 07:04:07+02</controlfield>
104
  <controlfield tag="007">ss||||j|||||||</controlfield>
105
  <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
106
  <datafield tag="020" ind1=" " ind2=" ">
107
    <subfield code="a">0-00-103147-3</subfield>
108
    <subfield code="c">14.46 EUR</subfield>
109
  </datafield>
110
  <datafield tag="041" ind1="0" ind2=" ">
111
    <subfield code="d">eng</subfield>
112
  </datafield>
113
  <datafield tag="084" ind1=" " ind2=" ">
114
    <subfield code="a">83.5</subfield>
115
    <subfield code="2">ykl</subfield>
116
  </datafield>
117
  <datafield tag="100" ind1="1" ind2=" ">
118
    <subfield code="a">SHAKESPEARE, WILLIAM.</subfield>
119
  </datafield>
120
  <datafield tag="245" ind1="1" ind2="4">
121
    <subfield code="a">THE TAMING OF THE SHREW /</subfield>
122
    <subfield code="c">WILLIAM SHAKESPEARE</subfield>
123
    <subfield code="h">[ÄÄNITE].</subfield>
124
  </datafield>
125
  <datafield tag="260" ind1=" " ind2=" ">
126
    <subfield code="a">LONDON :</subfield>
127
    <subfield code="b">COLLINS.</subfield>
128
  </datafield>
129
  <datafield tag="300" ind1=" " ind2=" ">
130
    <subfield code="a">2 ÄÄNIKASETTIA.</subfield>
131
  </datafield>
132
  <datafield tag="852" ind1=" " ind2=" ">
133
    <subfield code="a">FI-Jm</subfield>
134
    <subfield code="h">83.5</subfield>
135
  </datafield>
136
  <datafield tag="852" ind1=" " ind2=" ">
137
    <subfield code="a">FI-Konti</subfield>
138
    <subfield code="h">83.5</subfield>
139
  </datafield>
140
</record>
141
);
142
my $record=C4::Record::marcxml2marc($marcxml);
143
144
# Add a itemtype definition to the Record.
145
my ( $biblioitemtypeTagid, $biblioitemtypeSubfieldid ) =
146
            C4::Biblio::GetMarcFromKohaField( 'biblioitems.itemtype', $bibFramework );
147
my $itemtypeField = MARC::Field->new($biblioitemtypeTagid, '', '',
148
                                     $biblioitemtypeSubfieldid => $itemtype);
149
$record->append_fields( $itemtypeField );
150
151
my ( $newBiblionumber, $newBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
152
153
## Add an item with a ccode.
154
my ($item_bibnum, $item_bibitemnum);
155
my ($itemCPLFull, $itemCPLFullId); #Item with a itemtype and ccode in its data.
156
my ($itemCPLLite, $itemCPLLiteId); #Item with no itemtype nor ccode in its data. Forces to look for it from the biblio.
157
($item_bibnum, $item_bibitemnum, $itemCPLFullId) = C4::Items::AddItem({ barcode => 'CPLFull', homebranch => 'CPL', holdingbranch => 'CPL', ccode => $ccode, itemtype => $itemtype}, $newBiblionumber);#, biblioitemnumber => $newBiblioitemnumber, biblionumber => $newBiblioitemnumber });
158
($item_bibnum, $item_bibitemnum, $itemCPLLiteId) = C4::Items::AddItem({ barcode => 'CPLLite', homebranch => 'CPL', holdingbranch => 'CPL'}, $newBiblionumber);# biblioitemnumber => $newBiblioitemnumber, biblionumber => $newBiblioitemnumber });
159
160
161
### Created the generic testing material. ###
162
### Setting preferences for ccode use-case ###
163
164
C4::Context->set_preference("BranchTransferLimitsType", 'ccode');
165
166
## Add the TransferLimit rules:
167
## IPT -> CPL -> FFL -> IPT
168
#                                            to     from
169
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $ccode );
170
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $ccode );
171
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $ccode );
172
173
## Ready to start testing ccode use-case ##
174
175
$itemCPLFull = C4::Items::GetItem($itemCPLFullId);
176
$itemCPLLite = C4::Items::GetItem($itemCPLLiteId);
177
my $biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} );
178
179
180
runTestsForCCode($itemCPLFull, $itemCPLLite, $biblioitem);
100
runTestsForCCode($itemCPLFull, $itemCPLLite, $biblioitem);
181
101
102
runTestsForItype($itemCPLFull, $itemCPLLite, $biblioitem);
103
182
104
105
#One cannot return an Item which has homebranch in CPL to FFL
106
my $datedue = C4::Circulation::AddIssue( $borrower, 'CPLFull')    or BAIL_OUT("Cannot check-out an Item!");
107
my ($returnOk, $errorMessage) = C4::Circulation::AddReturn('CPLFull', 'FFL', undef, undef, undef);
108
is( exists $errorMessage->{BranchTransferDenied}, 1, "Check-in failed because of a branch transfer limitation." );
183
109
184
### ccode tested
185
### Setting preferences for itemtype use-case ###
186
110
187
C4::Context->set_preference("BranchTransferLimitsType", 'itemtype');
111
#One can return an Item which has homebranch in FFL to CPL
112
($returnOk, $errorMessage) = C4::Circulation::AddReturn('CPLFull', 'CPL', undef, undef, undef);
113
is( $returnOk, 1, "Check-in succeeds." );
188
114
189
## Add the TransferLimit rules:
190
## IPT -> CPL -> FFL -> IPT
191
#                                            to     from
192
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $itemtype );
193
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $itemtype );
194
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $itemtype );
195
115
196
## Ready to start testing itemtype use-case ##
116
#One can override a denied branch transfer
117
$datedue = C4::Circulation::AddIssue( $borrower, 'CPLFull')    or BAIL_OUT("Cannot check-out an Item!");
118
($returnOk, $errorMessage) = C4::Circulation::AddReturn('CPLFull', 'FFL', undef, undef, {overrideBranchTransferDenied => 1});
119
is( $returnOk, 1, "Check-in succeeds because transfer limits are overridden." );
197
120
198
$itemCPLFull = C4::Items::GetItem($itemCPLFullId);
199
$itemCPLLite = C4::Items::GetItem($itemCPLLiteId);
200
$biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} );
201
121
122
#Failing a check-in regardless of override, since failure happens because Item's must be returned to their homebranches.
123
#Important to see that overriding BranchTransferDenied doesn't break other functionality.
124
C4::Context->set_preference("AllowReturnToBranch", 'homebranch');
125
$datedue = C4::Circulation::AddIssue( $borrower, 'CPLFull')    or BAIL_OUT("Cannot check-out an Item!");
126
($returnOk, $errorMessage) = C4::Circulation::AddReturn('CPLFull', 'FFL', undef, undef, {overrideBranchTransferDenied => 1});
127
is( $returnOk, 0, "Overridden check-in fails, because AllowReturnToBranch-check fails." );
202
128
203
runTestsForItype($itemCPLFull, $itemCPLLite, $biblioitem);
204
129
205
### itemtype tested
206
130
207
### Reset default preferences
131
### Reset default preferences
208
C4::Context->set_preference("BranchTransferLimitsType", $originalBranchTransferLimitsType);
132
C4::Context->set_preference("BranchTransferLimitsType", $originalBranchTransferLimitsType);
(-)a/t/db_dependent/UseBranchTransferLimits/PreparedTestEnvironment.pm (-1 / +151 lines)
Line 0 Link Here
0
- 
1
package UseBranchTransferLimits::PreparedTestEnvironment;
2
3
use Modern::Perl;
4
5
use C4::Circulation;
6
use C4::Context;
7
use C4::Record;
8
use C4::Members;
9
10
### Naming shared variables ###
11
use base 'Exporter';
12
our @EXPORT = qw($biblioitem $itemCPLFull $itemCPLLite $borrower);
13
14
my $dbh = C4::Context->dbh;
15
16
##########################################
17
### Preparing our generic testing data ###
18
##########################################
19
20
### Naming shared variables ###
21
our ($biblioitem, $itemCPLFull, $itemCPLLite, $borrower);
22
23
#Set the item variables
24
my $ccode = 'FANTASY';
25
my $itemtype = 'BK';
26
27
28
## Check if defaults already exist
29
my $itemnumber = C4::Items::GetItemnumberFromBarcode('CPLFull');
30
unless ($itemnumber) {
31
    
32
    ## Add a example Bibliographic record
33
    my $bibFramework = ''; #Using the default bibliographic framework.
34
    my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
35
    <record format="MARC21" type="Bibliographic">
36
      <leader>00000cim a22000004a 4500</leader>
37
      <controlfield tag="007">ss||||j|||||||</controlfield>
38
      <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
39
      <datafield tag="100" ind1="1" ind2=" ">
40
        <subfield code="a">SHAKESPEARE, WILLIAM.</subfield>
41
      </datafield>
42
      <datafield tag="245" ind1="1" ind2="4">
43
        <subfield code="a">THE TAMING OF THE SHREW /</subfield>
44
        <subfield code="c">WILLIAM SHAKESPEARE</subfield>
45
        <subfield code="h">[ÄÄNITE].</subfield>
46
      </datafield>
47
    </record>
48
    );
49
    my $record=C4::Record::marcxml2marc($marcxml);
50
    
51
    # Add an itemtype definition to the Record.
52
    my ( $biblioitemtypeTagid, $biblioitemtypeSubfieldid ) =
53
                C4::Biblio::GetMarcFromKohaField( 'biblioitems.itemtype', $bibFramework );
54
    my $itemtypeField = MARC::Field->new($biblioitemtypeTagid, '', '',
55
                                         $biblioitemtypeSubfieldid => $itemtype);
56
    $record->append_fields( $itemtypeField );
57
    
58
    my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
59
    
60
    ## Add an item with a ccode.
61
    my ($item_bibnum, $item_bibitemnum);
62
    my ($itemCPLFullId); #Item with a itemtype and ccode in its data.
63
    my ($itemCPLLiteId); #Item with no itemtype nor ccode in its data. Forces to look for it from the biblio.
64
    ($item_bibnum, $item_bibitemnum, $itemCPLFullId) = C4::Items::AddItem({ barcode => 'CPLFull', homebranch => 'CPL', holdingbranch => 'CPL', ccode => $ccode, itemtype => $itemtype}, $biblionumber);#, biblioitemnumber => $biblioitemnumber, biblionumber => $biblioitemnumber });
65
    ($item_bibnum, $item_bibitemnum, $itemCPLLiteId) = C4::Items::AddItem({ barcode => 'CPLLite', homebranch => 'CPL', holdingbranch => 'CPL'}, $biblionumber);# biblioitemnumber => $biblioitemnumber, biblionumber => $biblioitemnumber });
66
     
67
    $itemCPLFull = C4::Items::GetItem($itemCPLFullId);
68
    $itemCPLLite = C4::Items::GetItem($itemCPLLiteId);
69
    $biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} );   
70
}
71
else {
72
    $itemCPLFull = C4::Items::GetItem($itemnumber);
73
    
74
    $itemnumber = C4::Items::GetItemnumberFromBarcode('CPLLite');
75
    $itemCPLLite = C4::Items::GetItem($itemnumber);
76
    
77
    $biblioitem = C4::Biblio::GetBiblioFromItemNumber( $itemCPLFull->{itemnumber} );
78
}
79
80
81
82
83
### Created the generic testing material. ###
84
85
86
### Setting preferences for ccode use-case ###
87
C4::Context->set_preference("BranchTransferLimitsType", 'ccode');
88
## Add the TransferLimit rules:
89
## IPT -> CPL -> FFL -> IPT
90
#                                            to     from
91
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $ccode );
92
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $ccode );
93
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $ccode );
94
95
96
### Setting preferences for itemtype use-case ###
97
C4::Context->set_preference("BranchTransferLimitsType", 'itemtype');
98
## Add the TransferLimit rules:
99
## IPT -> CPL -> FFL -> IPT
100
#                                            to     from
101
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', $itemtype );
102
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', $itemtype );
103
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', $itemtype );
104
105
106
107
############################
108
### Testing checking-in! ###
109
############################
110
111
## Set up the user environment to a funky branch
112
C4::Context->_new_userenv('xxx');
113
C4::Context::set_userenv(0,0,0,'firstname','surname', 'CPL', 'Centerville', '', '', '');
114
(C4::Context->userenv->{branch} eq 'CPL') or BAIL_OUT("Unable to set the userenv!");
115
116
## Set a simple circ policy
117
$dbh->do('DELETE FROM issuingrules');
118
$dbh->do(
119
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
120
                                maxissueqty, issuelength, lengthunit,
121
                                renewalsallowed, renewalperiod,
122
                                fine, chargeperiod)
123
      VALUES (?, ?, ?, ?,
124
              ?, ?, ?,
125
              ?, ?,
126
              ?, ?
127
             )
128
    },
129
    {},
130
    '*', '*', '*', 25,
131
    20, 14, 'days',
132
    1, 7,
133
    .10, 1
134
);
135
136
## Add a Borrower
137
$borrower = C4::Members::GetMember(cardnumber => 'cardnumber1234');
138
unless ($borrower) {
139
    my %borrower_data = (
140
        firstname =>  'Katrin',
141
        surname => 'Reservation',
142
        categorycode => 'S',
143
        branchcode => 'CPL',
144
        cardnumber => 'cardnumber1234',
145
        userid => 'katrin.reservation',
146
        password => '1234',
147
    );
148
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
149
    $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
150
}
151

Return to bug 7376