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

(-)a/C4/HoldsQueue.pm (-8 / +45 lines)
Lines 90-96 sub UpdateTransportCostMatrix { Link Here
90
90
91
    my $sth = $dbh->prepare("INSERT INTO transport_cost (frombranch, tobranch, cost, disable_transfer) VALUES (?, ?, ?, ?)");
91
    my $sth = $dbh->prepare("INSERT INTO transport_cost (frombranch, tobranch, cost, disable_transfer) VALUES (?, ?, ?, ?)");
92
92
93
    $dbh->do("TRUNCATE TABLE transport_cost");
93
    $dbh->do("DELETE FROM transport_cost"); #Deleting is slower than TRUNCATE, but using TRUNCATE screws up $dbh->{AutoCommit} in unit tests
94
    foreach (@$records) {
94
    foreach (@$records) {
95
        my $cost = $_->{cost};
95
        my $cost = $_->{cost};
96
        my $from = $_->{frombranch};
96
        my $from = $_->{frombranch};
Lines 306-312 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
306
    my ($biblionumber, $branches_to_use) = @_;
306
    my ($biblionumber, $branches_to_use) = @_;
307
307
308
    my $dbh = C4::Context->dbh;
308
    my $dbh = C4::Context->dbh;
309
    my $items_query = "SELECT itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype
309
    my $items_query = "SELECT itemnumber, homebranch, holdingbranch, ccode, itemtypes.itemtype AS itype
310
                       FROM items ";
310
                       FROM items ";
311
311
312
    if (C4::Context->preference('item-level_itypes')) {
312
    if (C4::Context->preference('item-level_itypes')) {
Lines 386-392 sub MapItemsToHoldRequests { Link Here
386
            # fill it if possible; if not skip it
386
            # fill it if possible; if not skip it
387
            if (exists $items_by_itemnumber{$request->{itemnumber}} and
387
            if (exists $items_by_itemnumber{$request->{itemnumber}} and
388
                not exists $allocated_items{$request->{itemnumber}}) {
388
                not exists $allocated_items{$request->{itemnumber}}) {
389
                $item_map{$request->{itemnumber}} = {
389
390
                #Dereferencing variables for sanitys sake, and because it is faster when repeatedly called.
391
                my $holdingBranch = $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch};
392
                my $pickupBranch = $request->{branchcode} || $request->{borrowerbranch};
393
394
                my ($transferOk, $errorMsg) = CheckBranchTransferAllowed( $pickupBranch, $holdingBranch, $items_by_itemnumber{$request->{itemnumber}}, undef);
395
                if (! $transferOk) {
396
                    #UseBranchTransfer check failed, gosh damn how can this be! It should be blocked in the UI for item level holds!
397
                    warn "HoldsQueue.pm:> Branch transfer failed for pickup branch $pickupBranch, holding branch $holdingBranch, itemnumber $request->{itemnumber}\n" .
398
                         "This should be impossible because branch transfer limits for item level holds must be checked when placing holds!";
399
                }
400
                else {
401
                    $item_map{$request->{itemnumber}} = {
390
                    borrowernumber => $request->{borrowernumber},
402
                    borrowernumber => $request->{borrowernumber},
391
                    biblionumber => $request->{biblionumber},
403
                    biblionumber => $request->{biblionumber},
392
                    holdingbranch =>  $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch},
404
                    holdingbranch =>  $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch},
Lines 394-402 sub MapItemsToHoldRequests { Link Here
394
                    item_level => 1,
406
                    item_level => 1,
395
                    reservedate => $request->{reservedate},
407
                    reservedate => $request->{reservedate},
396
                    reservenotes => $request->{reservenotes},
408
                    reservenotes => $request->{reservenotes},
397
                };
409
                    };
398
                $allocated_items{$request->{itemnumber}}++;
410
                    $allocated_items{$request->{itemnumber}}++;
399
                $num_items_remaining--;
411
                    $num_items_remaining--;
412
                }
400
            }
413
            }
401
        } else {
414
        } else {
402
            # it's title-level request that will take up one item
415
            # it's title-level request that will take up one item
Lines 425-430 sub MapItemsToHoldRequests { Link Here
425
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
438
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
426
        my ($itemnumber, $holdingbranch);
439
        my ($itemnumber, $holdingbranch);
427
440
441
        # Used to detect if no Items can be transferred to the pickup location.
442
        my $branchTransfersAllowedCount = 1; #Default this to 1. It is decremented when branchTransfers fail.
443
428
        my $holding_branch_items = $items_by_branch{$pickup_branch};
444
        my $holding_branch_items = $items_by_branch{$pickup_branch};
429
        if ( $holding_branch_items ) {
445
        if ( $holding_branch_items ) {
430
            foreach my $item (@$holding_branch_items) {
446
            foreach my $item (@$holding_branch_items) {
Lines 442-461 sub MapItemsToHoldRequests { Link Here
442
            if ( $holdingbranch ) {
458
            if ( $holdingbranch ) {
443
459
444
                my $holding_branch_items = $items_by_branch{$holdingbranch};
460
                my $holding_branch_items = $items_by_branch{$holdingbranch};
461
                $branchTransfersAllowedCount = @$holding_branch_items;
462
                # Making sure to put preference to the Item, which is originally from the Borrowers homebranch.
445
                foreach my $item (@$holding_branch_items) {
463
                foreach my $item (@$holding_branch_items) {
446
                    next if $request->{borrowerbranch} ne $item->{homebranch};
464
                    next if $request->{borrowerbranch} ne $item->{homebranch};
447
465
448
                    $itemnumber = $item->{itemnumber};
466
                    $itemnumber = $item->{itemnumber};
449
                    last;
467
                    last;
450
                }
468
                }
469
                # Checking if the Item can be Transferred to the pickup library
470
                if (! $itemnumber && C4::Context->preference("UseBranchTransferLimits") == 1 ) {
471
                    foreach my $item (@$holding_branch_items) {
472
                        my ($transferOk, $errorMsg) = C4::Circulation::CanItemBeTransferred($pickup_branch, $item->{holdingbranch}, $item, undef);
473
                        if (! $transferOk) {
474
                            $branchTransfersAllowedCount--;
475
                            next;
476
                        }
477
478
                        $itemnumber = $item->{itemnumber};
479
                        last;
480
                    }
481
                }
482
                # If one is not using UseBranchTransferLimits, then revert to the default setting.
483
                elsif (! $itemnumber) {
484
                    # FIXME Choosing the Item based on the first available, even if it could be on hold.
485
                    #  Problematic since holds tend to stack on this first item then.
486
                    $itemnumber ||= $holding_branch_items->[0]->{itemnumber};
487
                }
451
            }
488
            }
452
            else {
489
            else {
453
                warn "No transport costs for $pickup_branch";
490
                warn "No transport costs for $pickup_branch";
454
            }
491
            }
455
        }
492
        }
456
493
457
        unless ($itemnumber) {
494
        if ((! $itemnumber) && $branchTransfersAllowedCount > 0) {
458
            # not found yet, fall back to basics
495
            # not found yet and branchTransfers are not blocking, fall back to basics
459
            if ($branches_to_use) {
496
            if ($branches_to_use) {
460
                $pull_branches = $branches_to_use;
497
                $pull_branches = $branches_to_use;
461
            } else {
498
            } else {
(-)a/t/db_dependent/HoldsQueue_UseBranchTransferLimits.t (-1 / +326 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
=head TESTING PLAN
4
5
PRECONDITIONS|
6
-------------+
7
UseBranchTranferLimits itemtype DVD
8
IPT -> CPL -> FFL -> IPT
9
no transfers into LPL
10
11
TransportCostMatrix in use
12
Allow all, cost 1
13
14
->  pickup branch IPT  <-
15
->  Borrowers homebranch LPL <-
16
17
18
Biblio1 Items
19
Item barcode	holdingbranch	transferOK?	itemtype
20
cpl11		    CPL		        0	    	DVD
21
cpl12		    CPL		        1	    	BK
22
ffl11	    	FFL		        1	    	DVD
23
ffl12	    	FFL		        1	    	BK
24
25
Biblio2 Items
26
Item barcode	holdingbranch	transferOK?	itemtype
27
cpl21	    	CPL		        0		    DVD
28
cpl22	    	CPL		        0		    DVD
29
30
Biblio3 Items
31
Item barcode	holdingbranch	transferOK?	itemtype
32
ffl31	       	FFL     		1	    	DVD
33
ffl32	    	FFL	        	1	    	BK
34
35
---------------------
36
--- HoldsQueue.pm ---
37
---------------------
38
39
CASE1:		Title-level multi_hold on all Biblios, pickup location IPT
40
41
Expected:
42
Hold for Biblio1 gets satisfied with Items cpl12, ipt11, ipt12 or ffl1.
43
Hold for Biblio2 fails to satisfy, no messages given.
44
Hold for Biblio3 is satisfied with ffl31.
45
46
47
CASE2:		Item-level holds, pickup location IPT
48
49
Expected:
50
Item to hold	hold satisfied?
51
cpl1	    	0
52
cpl12	    	1
53
ipt11	    	1
54
ipt12	    	1
55
ffl1	    	1
56
cpl21	    	0
57
cpl22	    	0
58
cpl23	    	1
59
ffl31	    	1
60
ffl32	    	1
61
62
63
=cut
64
65
use Modern::Perl;
66
67
use C4::Context;
68
69
use Test::More tests => 9;
70
71
use C4::Circulation;
72
use C4::Record;
73
use C4::HoldsQueue;
74
use C4::Reserves;
75
use C4::HoldsQueue;
76
77
# Start transaction
78
my $dbh = C4::Context->dbh;
79
$dbh->{AutoCommit} = 0;
80
$dbh->{RaiseError} = 1;
81
82
83
##########################xxxxxxxxxxxxxxxxxxxxxxxxx###########################
84
### xxxxxxxxxxxxxxxxxxxxxxxxxx Set up the stage xxxxxxxxxxxxxxxxxxxxxxxxxx ###
85
##########################xxxxxxxxxxxxxxxxxxxxxxxxx###########################
86
87
## Set branches
88
my $desiredBranches = ['IPT', 'CPL', 'FFL', 'LPL'];
89
my $branches = C4::Branch::GetBranches;
90
91
foreach my $branchCode (@$desiredBranches) {
92
    if (exists $branches->{$branchCode}) {
93
        #Alls well and the library is here yay!
94
    }
95
    else {
96
        #le fuu! who is not using the default libraries?
97
        my $branchwhatever = C4::SQLHelper::InsertInTable("branches",{branchcode=>"$branchCode",branchname=>"Yet another branch",city=>" ",zipcode=>" "},1);
98
        print $branchwhatever;
99
    }
100
}
101
102
my %data = (
103
    cardnumber => 'CARDNUMBER42',
104
    firstname =>  'my firstname',
105
    surname => 'my surname',
106
    categorycode => 'S',
107
    branchcode => 'LPL',
108
);
109
110
my $borrowernumber = C4::Members::AddMember(%data);
111
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
112
113
114
## Itemtypes
115
my $itemTypes = {  map {$_->{itemtype} => 1} C4::ItemType->all()  };
116
if (! (exists $itemTypes->{'BK'})) {
117
    $dbh->do("INSERT INTO `kohadata`.`itemtypes` (`itemtype`, `description`, `rentalcharge`, `notforloan`, `imageurl`, `summary`, `checkinmsg`, `checkinmsgtype`) VALUES ('BK', NULL, '0', NULL, NULL, NULL, NULL, 'message');");
118
}
119
if (! (exists $itemTypes->{'DVD'})) {
120
    $dbh->do("INSERT INTO `kohadata`.`itemtypes` (`itemtype`, `description`, `rentalcharge`, `notforloan`, `imageurl`, `summary`, `checkinmsg`, `checkinmsgtype`) VALUES ('DVD', NULL, '0', NULL, NULL, NULL, NULL, 'message');");
121
}
122
123
124
125
## Add example Bibliographic records
126
127
my ( $biblioNumber1, $biblioNumber2, $biblioNumber3, $discardBiblioitemnumber);
128
my $bibFramework = ''; #Using the default bibliographic framework.
129
130
my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
131
<record format="MARC21" type="Bibliographic">
132
  <leader>00000cim a22000004a 4500</leader>
133
  <controlfield tag="007">ss||||j|||||||</controlfield>
134
  <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
135
  <datafield tag="245" ind1="1" ind2="4">
136
    <subfield code="a">BIBLIO1</subfield>
137
  </datafield>
138
</record>
139
);
140
my $record=C4::Record::marcxml2marc($marcxml);
141
( $biblioNumber1, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
142
143
$marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
144
<record format="MARC21" type="Bibliographic">
145
  <leader>00000cim a22000004a 4500</leader>
146
  <controlfield tag="007">ss||||j|||||||</controlfield>
147
  <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
148
  <datafield tag="245" ind1="1" ind2="4">
149
    <subfield code="a">BIBLIO2</subfield>
150
  </datafield>
151
</record>
152
);
153
$record=C4::Record::marcxml2marc($marcxml);
154
( $biblioNumber2, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
155
156
$marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
157
<record format="MARC21" type="Bibliographic">
158
  <leader>00000cim a22000004a 4500</leader>
159
  <controlfield tag="007">ss||||j|||||||</controlfield>
160
  <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
161
  <datafield tag="245" ind1="1" ind2="4">
162
    <subfield code="a">BIBLIO3</subfield>
163
  </datafield>
164
</record>
165
);
166
$record=C4::Record::marcxml2marc($marcxml);
167
( $biblioNumber3, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
168
169
## Add items to the mix
170
my ($discardThis, $discardThat); # Not needing biblionumber or biblioitemnumber for the added items
171
my ($cpl11, $cpl12, $ffl11, $ffl12, $cpl21, $cpl22, $ffl31, $ffl32);
172
173
($discardThis, $discardThat, $cpl11) = C4::Items::AddItem({ barcode => 'cpl11', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber1);
174
($discardThis, $discardThat, $cpl12) = C4::Items::AddItem({ barcode => 'cpl12', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'BK' , notforloan => '0' }, $biblioNumber1);
175
($discardThis, $discardThat, $ffl11) = C4::Items::AddItem({ barcode => 'ffl11', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'DVD', notforloan => '0' }, $biblioNumber1);
176
($discardThis, $discardThat, $ffl12) = C4::Items::AddItem({ barcode => 'ffl12', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'BK' , notforloan => '0' }, $biblioNumber1);
177
178
($discardThis, $discardThat, $cpl21) = C4::Items::AddItem({ barcode => 'cpl21', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber2);
179
($discardThis, $discardThat, $cpl22) = C4::Items::AddItem({ barcode => 'cpl22', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber2);
180
181
($discardThis, $discardThat, $ffl31) = C4::Items::AddItem({ barcode => 'ffl31', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'DVD', notforloan => '0' }, $biblioNumber3);
182
($discardThis, $discardThat, $ffl32) = C4::Items::AddItem({ barcode => 'ffl32', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'BK' , notforloan => '0' }, $biblioNumber3);
183
184
185
## Sysprefs and cost matrix
186
C4::Context->set_preference('UseTransportCostMatrix', 1);
187
C4::Context->set_preference('item-level_itypes', 1);
188
C4::Context->set_preference("BranchTransferLimitsType", 'itemtype');
189
C4::Context->set_preference('StaticHoldsQueueWeight', 0);
190
C4::Context->set_preference('RandomizeHoldsQueueWeight', 0);
191
192
193
C4::HoldsQueue::UpdateTransportCostMatrix( [
194
            {frombranch => 'IPT', tobranch => 'CPL', cost => 1, disable_transfer => 0},
195
            {frombranch => 'IPT', tobranch => 'FFL', cost => 1, disable_transfer => 0},
196
            {frombranch => 'IPT', tobranch => 'LPL', cost => 1, disable_transfer => 0},
197
            {frombranch => 'CPL', tobranch => 'FFL', cost => 1, disable_transfer => 0},
198
            {frombranch => 'CPL', tobranch => 'IPT', cost => 0.2, disable_transfer => 0},
199
            {frombranch => 'CPL', tobranch => 'LPL', cost => 1, disable_transfer => 0},
200
            {frombranch => 'FFL', tobranch => 'IPT', cost => 1, disable_transfer => 0},
201
            {frombranch => 'FFL', tobranch => 'CPL', cost => 1, disable_transfer => 0},
202
            {frombranch => 'FFL', tobranch => 'LPL', cost => 1, disable_transfer => 0},
203
] );
204
205
206
C4::Circulation::DeleteBranchTransferLimits( 'IPT' );
207
C4::Circulation::DeleteBranchTransferLimits( 'CPL' );
208
C4::Circulation::DeleteBranchTransferLimits( 'FFL' );
209
C4::Circulation::DeleteBranchTransferLimits( 'LPL' );
210
#                CreateBranchTransferLimit(  to  ,  from,  code ); Block these transfers!
211
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', 'DVD' );
212
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', 'DVD' );
213
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', 'DVD' );
214
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'IPT', 'DVD' );
215
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'CPL', 'DVD' );
216
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'FFL', 'DVD' );
217
218
219
#############################xxxxxxxxxxxxxxxxxxxxxxxxx###########################
220
### xxxxxxxxxxxxxxxxxxxxxxxxxx Start running tests xxxxxxxxxxxxxxxxxxxxxxxxxx ###
221
#############################xxxxxxxxxxxxxxxxxxxxxxxxx###########################
222
223
224
   #############
225
### CASE1: Title-level multi_hold on all Biblios, pickup location IPT ###
226
   #############
227
228
## Remove existing reserves, makes debugging easier
229
$dbh->do("DELETE FROM reserves");
230
231
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, 'a', '',  '1' );
232
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, 'a', '',  '1' );
233
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, 'a', '',  '1' );
234
235
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
236
237
## Item cpl11 is a DVD and transferring it from CPL to IPT is strictly forbidden.
238
## Transport matrix favours CPL -> IPT transports, so we should get either the BK or DVD.
239
my $testOk = 0;
240
my $branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
241
my $transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
242
my $hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber1);
243
my $available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber1, $branches_to_use);
244
my $item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
245
my $rib = (C4::Items::GetItem(  (keys %$item_map)[0]  ))->{barcode}; #Reserved Item's barcode
246
$testOk = 1 if ($rib eq 'cpl12');
247
is($testOk, 1, 'Title-level hold, mixed material, Biblio1');
248
=head
249
## Should fail, requesting DVD's from a transfer-denied branch.
250
$testOk = 0;
251
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
252
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
253
$hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber2);
254
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber2, $branches_to_use);
255
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
256
$testOk = %$item_map; #This time we should have no results
257
is($testOk, 0, 'Title-level hold, transfer denied, Biblio2');
258
259
## Should succeed, no transfer blocks
260
$testOk = 0;
261
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
262
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
263
$hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber3);
264
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber3, $branches_to_use);
265
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
266
$testOk = keys %$item_map; #This time any result will do
267
is($testOk, 1, 'Title-level hold, transfer allowed, Biblio3');
268
=cut
269
270
271
272
   #############
273
### CASE2: Item-level holds, pickup location IPT ###
274
   #############
275
276
## Remove existing reserves, makes debugging easier
277
$dbh->do("DELETE FROM reserves");
278
279
#$branch, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority, $resdate, $expdate, $notes, $title, $checkitem, $found
280
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef,  '1', undef, undef, undef, undef, $cpl11, undef );
281
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef,  '1', undef, undef, undef, undef, $cpl12, undef );
282
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef,  '1', undef, undef, undef, undef, $ffl11, undef );
283
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef,  '1', undef, undef, undef, undef, $ffl12, undef );
284
285
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, undef, undef,  '1', undef, undef, undef, undef, $cpl21, undef );
286
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, undef, undef,  '1', undef, undef, undef, undef, $cpl22, undef );
287
288
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, undef, undef,  '1', undef, undef, undef, undef, $ffl31, undef );
289
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, undef, undef,  '1', undef, undef, undef, undef, $ffl32, undef );
290
291
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
292
293
## Transfer of cpl11 should be blocked, other 3 Items are mapped
294
$testOk = 0;
295
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
296
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
297
$hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber1);
298
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber1, $branches_to_use);
299
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
300
is( (exists $item_map->{$cpl11}) , '', 'Item cpl11 transfer denied');
301
is( (exists $item_map->{$cpl12}) , 1, 'Item cpl12 transfer allowed');
302
is( (exists $item_map->{$ffl11}) , 1, 'Item cpl11 transfer allowed');
303
is( (exists $item_map->{$ffl12}) , 1, 'Item cpl11 transfer allowed');
304
305
## All items should fail their transfer
306
$testOk = 0;
307
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
308
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
309
$hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber2);
310
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber2, $branches_to_use);
311
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
312
is( (exists $item_map->{$cpl21}) , '', 'Item cpl21 transfer denied');
313
is( (exists $item_map->{$cpl22}) , '', 'Item cpl22 transfer denied');
314
315
## Should succeed, no transfer blocks
316
$testOk = 0;
317
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future!
318
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix();
319
$hold_requests   = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber3);
320
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber3, $branches_to_use);
321
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
322
is( (exists $item_map->{$ffl31}) , 1, 'Item ffl31 transfer allowed');
323
is( (exists $item_map->{$ffl32}) , 1, 'Item ffl32 transfer allowed');
324
325
# Cleanup
326
$dbh->rollback();

Return to bug 11024