2 use strict; use warnings;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
7 my $script = OpenILS::Utils::TestUtils->new();
8 my $U = 'OpenILS::Application::AppUtils';
10 diag('LP1883171&1940663 Copy Inventory Date');
16 SYS1_FGROUP => "Sys1 Floating Group",
17 CIRC_USER => 'br1mtownsend',
18 CIRC_USER_PWD => 'maryt1234',
19 CIRC_WORKSTATION => 'BR1-lp1883171-live_t',
24 username => CIRC_USER,
25 password => CIRC_USER_PWD,
28 my $authtoken = $script->authenticate($credentials);
32 ) or BAIL_OUT('Must log in');
34 # Find or register the workstation:
35 my $ws = $script->find_or_register_workstation(CIRC_WORKSTATION, BR1_ID);
38 'Found or registered workstation'
39 ) or BAIL_OUT('Need workstation');
41 # Logout so we can use the workstation.
48 # Login with workstation
49 $credentials->{workstation} = CIRC_WORKSTATION;
50 $credentials->{password} = CIRC_USER_PWD; # Have to reset the password.
51 $authtoken = $script->authenticate($credentials);
54 'Logged in with workstation'
55 ) or BAIL_OUT('Must log in with workstation');
57 # Create an cstore editor with our current authtoken
58 my $editor = $script->editor(authtoken=>$authtoken);
60 # Create a floating group for SYS1:
61 my $cfg = Fieldmapper::config::floating_group->new;
62 $cfg->name(SYS1_FGROUP);
64 $editor->xact_begin();
65 $cfg = $editor->create_config_floating_group($cfg);
68 'Floating Group created successfully'
69 ) or BAIL_OUT('Need Floating Group');
70 $cfg = $editor->search_config_floating_group({name=>SYS1_FGROUP})->[0];
71 # Add SYS1 as a member:
72 my $cfgm = Fieldmapper::config::floating_group_member->new;
73 $cfgm->floating_group($cfg->id());
74 $cfgm->org_unit(SYS1_ID);
76 $cfgm = $editor->create_config_floating_group_member($cfgm);
79 'Floating group member created successfully'
80 ) or BAIL_OUT('Need floating group member');
83 # find 2 BR1 copies checked out at BR1:
84 my $copies = $editor->search_asset_copy([
94 checkin_scan_time => undef
102 $copies && scalar(@$copies) == 2,
103 'Got two checked out copies'
105 # Check first in without inventory update and the other with:
106 my $do_inventory = 0;
107 foreach my $copy (@$copies) {
109 barcode => $copy->barcode,
110 do_inventory_update => $do_inventory
112 my $resp = $script->do_checkin($args);
118 my $circ = $resp->{payload}->{circ};
121 'Fieldmapper::action::circulation'
123 my $scan_time = substr($circ->checkin_scan_time, 0, 19);
124 $copy = $resp->{payload}->{copy};
127 'Fieldmapper::asset::copy'
129 my $inventory = $copy->latest_inventory();
131 my $inv_time = substr($inventory->inventory_date(), 0, 19);
136 'Inventory date equals checkin scan time'
142 'Inventory date does not equal checkin scan time'
147 BAIL_OUT('Inventory not created on checkin');
154 # Find 2 BR2 copies checked out at BR1:
155 $copies = $editor->search_asset_copy([
164 checkin_scan_time => undef
171 $copies && scalar(@$copies) == 2,
172 'Got two checked out copies'
174 # Set the first one to floating:
175 my $fcopy = $copies->[0];
176 $fcopy->floating($cfg->id());
178 $fcopy = $editor->update_asset_copy($fcopy);
179 $editor->xact_commit;
182 'First BR2 copy set to floating group'
184 # Check them both in with inventory update.
185 for (my $i = 0; $i < scalar(@$copies); $i++) {
186 my $copy = $copies->[$i];
188 barcode => $copy->barcode,
189 do_inventory_update => $do_inventory
191 my $resp = $script->do_checkin($args);
194 ($i == 0) ? 'SUCCESS' : 'ROUTE_ITEM',
197 my $circ = $resp->{payload}->{circ};
200 'Fieldmapper::action::circulation'
202 my $scan_time = substr($circ->checkin_scan_time, 0, 19);
203 $copy = $resp->{payload}->{copy};
206 'Fieldmapper::asset::copy'
208 my $inventory = $copy->latest_inventory();
211 my $inv_time = substr($inventory->inventory_date(), 0, 19);
215 'Inventory date equals checkin scan time'
218 BAIL_OUT('Inventory not created on checkin');
222 my $inv_time = substr($inventory->inventory_date(), 0, 19);
226 'Inventory date does not equal checkin scan time'
229 pass('Second copy does not have inventory');
234 # Find an available copy at BR1:
235 $copies = $editor->search_asset_copy([
243 $copies && scalar(@$copies) == 1,
244 'Got an available copy'
245 ) or BAIL_OUT('Need an available copy');
247 my $resp = $U->simplereq(
249 'open-ils.circ.circulation.update_copy_inventory',
251 {copy_list=>[$copies->[0]->id()]}
256 'Update copy inventory succeeded'
259 my $inventories = $editor->search_asset_copy_inventory([
261 copy => $copies->[0]->id
267 field => 'inventory_date',
274 $inventories && scalar(@$inventories),
276 ) or BAIL_OUT('Need copy inventory');
278 my $aci = $inventories->[0];
280 my $alci = $editor->retrieve_asset_latest_inventory($aci->id());
283 'Got latest inventory for copy'
288 'Inventory IDs match'
291 $alci->inventory_date(),
292 $aci->inventory_date(),
293 'Inventory dates match'
296 $alci->inventory_workstation(),
297 $aci->inventory_workstation(),
298 'Inventory workstations match'
303 'Inventory copies match'
306 # Now, try 2 copies at BR2
307 $copies = $editor->search_asset_copy([
315 $copies && scalar(@$copies) == 2,
317 ) or BAIL_OUT('Need 2 copies');
319 $resp = $U->simplereq(
321 'open-ils.circ.circulation.update_copy_inventory',
323 {copy_list=>[$copies->[0]->id()]}
328 'Update copy inventory should have 0 success'
333 'Update copy inventory should have 1 failure'
335 # Make the second one float and it should succeed.
336 $fcopy = $copies->[1];
337 $fcopy->floating($cfg->id());
339 if ($editor->update_asset_copy($fcopy)) {
340 $editor->xact_commit;
341 $resp = $U->simplereq(
343 'open-ils.circ.circulation.update_copy_inventory',
345 {copy_list=>[$fcopy->id()]}
350 'Update inventory for floating copy'
353 $editor->xact_rollback;
354 BAIL_OUT('Set copy floating failed');
357 # Test a batch update where some succeed and some fail.
358 $resp = $editor->search_asset_copy([
359 {circ_lib => BR2_ID, status => 0, floating => undef},
360 {limit => 5, idlist => 1}
363 $resp && scalar(@{$resp}) == 5,
364 'Got 5 copies from branch 2'
367 push(@{$copies}, @{$resp});
368 $resp = $editor->search_asset_copy([
369 {circ_lib => BR1_ID, status => 0},
370 {limit => 5, idlist => 1}
373 $resp && scalar(@{$resp}) == 5,
374 'Got 5 copies from branch 1'
376 push(@{$copies}, @{$resp});
377 $resp = $U->simplereq(
379 'open-ils.circ.circulation.update_copy_inventory',
386 'Updated inventory on 5 copies'
391 'Did not update inventory on 5 copies'
394 # We could run 36 or more tests depending on what we find in the
395 # database, so we don't specify a number of tests.
398 # Just to make sure we're done.
399 $editor->disconnect();