|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 6; |
20 |
use Test::More tests => 4; |
| 21 |
|
21 |
|
| 22 |
use Koha::MarcOrder; |
22 |
use Koha::MarcOrder; |
| 23 |
use Koha::Acquisition::Baskets; |
23 |
use Koha::Acquisition::Baskets; |
|
Lines 32-44
use t::lib::TestBuilder;
Link Here
|
| 32 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
| 33 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
| 34 |
|
34 |
|
| 35 |
|
|
|
| 36 |
subtest '_get_MarcItemFieldsToOrder_syspref_data()' => sub { |
35 |
subtest '_get_MarcItemFieldsToOrder_syspref_data()' => sub { |
| 37 |
plan tests => 14; |
36 |
plan tests => 14; |
| 38 |
|
37 |
|
| 39 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
| 40 |
|
39 |
|
| 41 |
t::lib::Mocks::mock_preference( 'MarcItemFieldsToOrder', 'homebranch: 975$a |
40 |
t::lib::Mocks::mock_preference( |
|
|
41 |
'MarcItemFieldsToOrder', 'homebranch: 975$a |
| 42 |
holdingbranch: 975$b |
42 |
holdingbranch: 975$b |
| 43 |
itype: 975$y |
43 |
itype: 975$y |
| 44 |
nonpublic_note: 975$x |
44 |
nonpublic_note: 975$x |
|
Lines 51-57
copyno: 975$n
Link Here
|
| 51 |
quantity: 975$q |
51 |
quantity: 975$q |
| 52 |
budget_code: 975$h |
52 |
budget_code: 975$h |
| 53 |
price: 975$p |
53 |
price: 975$p |
| 54 |
replacementprice: 975$v' ); |
54 |
replacementprice: 975$v' |
|
|
55 |
); |
| 55 |
|
56 |
|
| 56 |
my $record = MARC::Record->new(); |
57 |
my $record = MARC::Record->new(); |
| 57 |
|
58 |
|
|
Lines 64-73
replacementprice: 975$v' );
Link Here
|
| 64 |
], |
65 |
], |
| 65 |
); |
66 |
); |
| 66 |
|
67 |
|
| 67 |
my $marc_item_fields_to_order = Koha::MarcOrder::_get_MarcItemFieldsToOrder_syspref_data( |
68 |
my $marc_item_fields_to_order = @{ |
| 68 |
$record, |
69 |
Koha::MarcOrder::_get_MarcItemFieldsToOrder_syspref_data( |
| 69 |
); |
70 |
$record, |
| 70 |
|
71 |
) |
|
|
72 |
}[0]; |
| 71 |
|
73 |
|
| 72 |
is( |
74 |
is( |
| 73 |
$marc_item_fields_to_order->{price}, 10, |
75 |
$marc_item_fields_to_order->{price}, 10, |
|
Lines 134-142
subtest '_get_MarcFieldsToOrder_syspref_data()' => sub {
Link Here
|
| 134 |
|
136 |
|
| 135 |
$schema->storage->txn_begin; |
137 |
$schema->storage->txn_begin; |
| 136 |
|
138 |
|
| 137 |
t::lib::Mocks::mock_preference( 'MarcFieldsToOrder', 'price: 975$p |
139 |
t::lib::Mocks::mock_preference( |
|
|
140 |
'MarcFieldsToOrder', 'price: 975$p |
| 138 |
quantity: 975$q |
141 |
quantity: 975$q |
| 139 |
budget_code: 975$h' ); |
142 |
budget_code: 975$h' |
|
|
143 |
); |
| 140 |
|
144 |
|
| 141 |
my $record = MARC::Record->new(); |
145 |
my $record = MARC::Record->new(); |
| 142 |
|
146 |
|
|
Lines 191-202
subtest 'add_biblio_from_import_record()' => sub {
Link Here
|
| 191 |
|
195 |
|
| 192 |
$record->add_fields( |
196 |
$record->add_fields( |
| 193 |
[ '001', '1234' ], |
197 |
[ '001', '1234' ], |
| 194 |
[ '020', ' ', ' ', a => '9780596004931'], |
198 |
[ '020', ' ', ' ', a => '9780596004931' ], |
| 195 |
[ '975', ' ', ' ', p => 10, q => 1, h => 1 ], |
199 |
[ '975', ' ', ' ', p => 10, q => 1, h => 1 ], |
| 196 |
); |
200 |
); |
| 197 |
|
201 |
|
| 198 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
202 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
| 199 |
my $import_record = Koha::Import::Records->find($import_record_id); |
203 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 200 |
|
204 |
|
| 201 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
205 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
| 202 |
{ |
206 |
{ |
|
Lines 216-222
subtest 'add_biblio_from_import_record()' => sub {
Link Here
|
| 216 |
# Check that records are skipped if not selected when called from addorderiso2709.pl |
220 |
# Check that records are skipped if not selected when called from addorderiso2709.pl |
| 217 |
# Pass in an empty array and the record should be skipped |
221 |
# Pass in an empty array and the record should be skipped |
| 218 |
my @import_record_id_selected = (); |
222 |
my @import_record_id_selected = (); |
| 219 |
my $result2 = Koha::MarcOrder::add_biblio_from_import_record( |
223 |
my $result2 = Koha::MarcOrder::add_biblio_from_import_record( |
| 220 |
{ |
224 |
{ |
| 221 |
import_record => $import_record, |
225 |
import_record => $import_record, |
| 222 |
matcher_id => $sample_import_batch->{matcher_id}, |
226 |
matcher_id => $sample_import_batch->{matcher_id}, |
|
Lines 227-399
subtest 'add_biblio_from_import_record()' => sub {
Link Here
|
| 227 |
} |
231 |
} |
| 228 |
); |
232 |
); |
| 229 |
|
233 |
|
| 230 |
is( $result2->{skip}, 1, 'Record was skipped'); |
234 |
is( $result2->{skip}, 1, 'Record was skipped' ); |
| 231 |
is( $result2->{duplicates_in_batch}, 0, 'Record was skipped - no duplicate checking needed' ); |
235 |
is( $result2->{duplicates_in_batch}, 0, 'Record was skipped - no duplicate checking needed' ); |
| 232 |
is( $result2->{record_result}, 0, 'Record was skipped'); |
236 |
is( $result2->{record_result}, 0, 'Record was skipped' ); |
| 233 |
|
|
|
| 234 |
$schema->storage->txn_rollback; |
| 235 |
}; |
| 236 |
|
| 237 |
subtest 'add_items_from_import_record() - cronjob' => sub { |
| 238 |
plan tests => 9; |
| 239 |
|
| 240 |
$schema->storage->txn_begin; |
| 241 |
|
| 242 |
my $bpid = C4::Budgets::AddBudgetPeriod( |
| 243 |
{ |
| 244 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
| 245 |
, budget_period_active => 1 |
| 246 |
, budget_period_description => "MAPERI" |
| 247 |
} |
| 248 |
); |
| 249 |
my $budgetid = C4::Budgets::AddBudget( |
| 250 |
{ |
| 251 |
budget_code => "BC_1", |
| 252 |
budget_name => "budget_name_test_1", |
| 253 |
budget_period_id => $bpid, |
| 254 |
} |
| 255 |
); |
| 256 |
my $budgetid2 = C4::Budgets::AddBudget( |
| 257 |
{ |
| 258 |
budget_code => "BC_2", |
| 259 |
budget_name => "budget_name_test_2", |
| 260 |
budget_period_id => $bpid, |
| 261 |
} |
| 262 |
); |
| 263 |
my $fund1 = C4::Budgets::GetBudget($budgetid); |
| 264 |
my $fund2 = C4::Budgets::GetBudget($budgetid2); |
| 265 |
my $budget_code_1 = $fund1->{budget_code}; |
| 266 |
my $budget_code_2 = $fund2->{budget_code}; |
| 267 |
|
| 268 |
my $sample_import_batch = { |
| 269 |
matcher_id => 1, |
| 270 |
template_id => 1, |
| 271 |
branchcode => 'CPL', |
| 272 |
overlay_action => 'create_new', |
| 273 |
nomatch_action => 'create_new', |
| 274 |
item_action => 'always_add', |
| 275 |
import_status => 'staged', |
| 276 |
batch_type => 'z3950', |
| 277 |
file_name => 'test.mrc', |
| 278 |
comments => 'test', |
| 279 |
record_type => 'auth', |
| 280 |
}; |
| 281 |
|
| 282 |
my $import_batch_id = C4::ImportBatch::AddImportBatch($sample_import_batch); |
| 283 |
|
| 284 |
my $record = MARC::Record->new(); |
| 285 |
|
| 286 |
$record->add_fields( |
| 287 |
[ '001', '1234' ], |
| 288 |
[ '020', ' ', ' ', a => '9780596004931' ], |
| 289 |
[ '975', ' ', ' ', p => 10, q => 1, h => $budget_code_2 ], |
| 290 |
); |
| 291 |
|
| 292 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
| 293 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 294 |
|
| 295 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
| 296 |
{ |
| 297 |
import_record => $import_record, |
| 298 |
matcher_id => $sample_import_batch->{matcher_id}, |
| 299 |
overlay_action => $sample_import_batch->{overlay_action}, |
| 300 |
agent => 'cron', |
| 301 |
import_batch_id => $import_batch_id |
| 302 |
} |
| 303 |
); |
| 304 |
|
| 305 |
my $bookseller = Koha::Acquisition::Bookseller->new( |
| 306 |
{ |
| 307 |
name => "my vendor", |
| 308 |
address1 => "bookseller's address", |
| 309 |
phone => "0123456", |
| 310 |
active => 1, |
| 311 |
deliverytime => 5, |
| 312 |
} |
| 313 |
)->store; |
| 314 |
|
| 315 |
t::lib::Mocks::mock_preference('MarcItemFieldsToOrder', ''); |
| 316 |
t::lib::Mocks::mock_preference('MarcFieldsToOrder', ''); |
| 317 |
|
| 318 |
my $order_line_details = Koha::MarcOrder::add_items_from_import_record( |
| 319 |
{ |
| 320 |
record_result => $result->{record_result}, |
| 321 |
basket_id => 1, |
| 322 |
vendor => $bookseller, |
| 323 |
budget_id => $budgetid, |
| 324 |
agent => 'cron', |
| 325 |
} |
| 326 |
); |
| 327 |
|
| 328 |
is( |
| 329 |
@{$order_line_details}[0]->{rrp}, undef, |
| 330 |
"Price has been read correctly" |
| 331 |
); |
| 332 |
is( |
| 333 |
@{$order_line_details}[0]->{listprice}, 0, |
| 334 |
"Listprice has defaulted to 0" |
| 335 |
); |
| 336 |
is( |
| 337 |
@{$order_line_details}[0]->{quantity}, 1, |
| 338 |
"Quantity has been defaulted to 1 correctly" |
| 339 |
); |
| 340 |
is( |
| 341 |
@{$order_line_details}[0]->{budget_id}, $budgetid, |
| 342 |
"Budget code has been read correctly" |
| 343 |
); |
| 344 |
|
| 345 |
#test that when a budget is mapped it is correctly used in the order line |
| 346 |
t::lib::Mocks::mock_preference( |
| 347 |
'MarcItemFieldsToOrder', 'homebranch: 975$a |
| 348 |
holdingbranch: 975$b |
| 349 |
itype: 975$y |
| 350 |
nonpublic_note: 975$x |
| 351 |
public_note: 975$z |
| 352 |
loc: 975$c |
| 353 |
ccode: 975$8 |
| 354 |
notforloan: 975$7 |
| 355 |
uri: 975$u |
| 356 |
copyno: 975$n |
| 357 |
quantity: 975$q |
| 358 |
budget_code: 975$h |
| 359 |
price: 975$p |
| 360 |
replacementprice: 975$v' |
| 361 |
); |
| 362 |
|
| 363 |
my $order_line_details2 = Koha::MarcOrder::add_items_from_import_record( |
| 364 |
{ |
| 365 |
record_result => $result->{record_result}, |
| 366 |
basket_id => 1, |
| 367 |
vendor => $bookseller, |
| 368 |
budget_id => $budgetid, |
| 369 |
agent => 'cron', |
| 370 |
} |
| 371 |
); |
| 372 |
|
| 373 |
is( |
| 374 |
@{$order_line_details2}[0]->{budget_id}, $budgetid2, |
| 375 |
"Budget code has been read correctly from the syspref mapping" |
| 376 |
); |
| 377 |
is( |
| 378 |
@{$order_line_details2}[0]->{rrp}, 10, |
| 379 |
"Price has been read correctly" |
| 380 |
); |
| 381 |
is( |
| 382 |
@{$order_line_details2}[0]->{quantity}, 1, |
| 383 |
"Quantity has been read correctly" |
| 384 |
); |
| 385 |
|
| 386 |
my @created_items = @{$order_line_details2}[0]->{itemnumbers}; |
| 387 |
my $new_item = Koha::Items->find($created_items[0]); |
| 388 |
|
| 389 |
isnt( |
| 390 |
$new_item, undef, |
| 391 |
'Item was successfully created' |
| 392 |
); |
| 393 |
is( |
| 394 |
$new_item->price, '10.00', |
| 395 |
'Item values mapped correctly' |
| 396 |
); |
| 397 |
|
237 |
|
| 398 |
$schema->storage->txn_rollback; |
238 |
$schema->storage->txn_rollback; |
| 399 |
}; |
239 |
}; |
|
Lines 453-461
subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
Link Here
|
| 453 |
[ '975', ' ', ' ', p => 10, q => 1, h => $budget_code_2 ], |
293 |
[ '975', ' ', ' ', p => 10, q => 1, h => $budget_code_2 ], |
| 454 |
); |
294 |
); |
| 455 |
|
295 |
|
| 456 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
296 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
| 457 |
my $import_record = Koha::Import::Records->find($import_record_id); |
297 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 458 |
my @import_record_id_selected = ( $import_record_id ); |
298 |
my @import_record_id_selected = ($import_record_id); |
| 459 |
|
299 |
|
| 460 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
300 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
| 461 |
{ |
301 |
{ |
|
Lines 587-701
subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
Link Here
|
| 587 |
$schema->storage->txn_rollback; |
427 |
$schema->storage->txn_rollback; |
| 588 |
}; |
428 |
}; |
| 589 |
|
429 |
|
| 590 |
|
|
|
| 591 |
subtest 'create_order_lines()' => sub { |
| 592 |
plan tests => 1; |
| 593 |
|
| 594 |
$schema->storage->txn_begin; |
| 595 |
|
| 596 |
my $quantity = 3; |
| 597 |
|
| 598 |
my $bpid = C4::Budgets::AddBudgetPeriod( |
| 599 |
{ |
| 600 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
| 601 |
, budget_period_active => 1 |
| 602 |
, budget_period_description => "MAPERI" |
| 603 |
} |
| 604 |
); |
| 605 |
my $budgetid = C4::Budgets::AddBudget( |
| 606 |
{ |
| 607 |
budget_code => "budget_code_test_1", |
| 608 |
budget_name => "budget_name_test_1", |
| 609 |
budget_period_id => $bpid, |
| 610 |
} |
| 611 |
); |
| 612 |
|
| 613 |
my $sample_import_batch = { |
| 614 |
matcher_id => 1, |
| 615 |
template_id => 1, |
| 616 |
branchcode => 'CPL', |
| 617 |
overlay_action => 'create_new', |
| 618 |
nomatch_action => 'create_new', |
| 619 |
item_action => 'always_add', |
| 620 |
import_status => 'staged', |
| 621 |
batch_type => 'z3950', |
| 622 |
file_name => 'test.mrc', |
| 623 |
comments => 'test', |
| 624 |
record_type => 'auth', |
| 625 |
}; |
| 626 |
|
| 627 |
my $import_batch_id = C4::ImportBatch::AddImportBatch($sample_import_batch); |
| 628 |
|
| 629 |
my $record = MARC::Record->new(); |
| 630 |
|
| 631 |
$record->add_fields( |
| 632 |
[ '001', '1234' ], |
| 633 |
[ '020', ' ', ' ', a => '9780596004931' ], |
| 634 |
[ |
| 635 |
'975', ' ', ' ', p => 10, q => $quantity, h => $budgetid, a => 'CPL', b => 'CPL', y => 'Book', |
| 636 |
x => 'Private note', z => 'Public note', c => 'Shelf', 8 => 'ccode', 7 => 0, |
| 637 |
u => '12345abcde', n => '12345', v => 10 |
| 638 |
] |
| 639 |
); |
| 640 |
|
| 641 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
| 642 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 643 |
|
| 644 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
| 645 |
{ |
| 646 |
import_record => $import_record, |
| 647 |
matcher_id => $sample_import_batch->{matcher_id}, |
| 648 |
overlay_action => $sample_import_batch->{overlay_action}, |
| 649 |
agent => 'cron', |
| 650 |
import_batch_id => $import_batch_id |
| 651 |
} |
| 652 |
); |
| 653 |
|
| 654 |
my $bookseller = Koha::Acquisition::Bookseller->new( |
| 655 |
{ |
| 656 |
name => "my vendor", |
| 657 |
address1 => "bookseller's address", |
| 658 |
phone => "0123456", |
| 659 |
active => 1, |
| 660 |
deliverytime => 5, |
| 661 |
} |
| 662 |
)->store; |
| 663 |
|
| 664 |
|
| 665 |
t::lib::Mocks::mock_preference( |
| 666 |
'MarcItemFieldsToOrder', 'homebranch: 975$a |
| 667 |
holdingbranch: 975$b |
| 668 |
itype: 975$y |
| 669 |
nonpublic_note: 975$x |
| 670 |
public_note: 975$z |
| 671 |
loc: 975$c |
| 672 |
ccode: 975$8 |
| 673 |
notforloan: 975$7 |
| 674 |
uri: 975$u |
| 675 |
copyno: 975$n |
| 676 |
quantity: 975$q |
| 677 |
budget_code: 975$h |
| 678 |
price: 975$p |
| 679 |
replacementprice: 975$v' |
| 680 |
); |
| 681 |
|
| 682 |
my $order_line_details = Koha::MarcOrder::add_items_from_import_record( |
| 683 |
{ |
| 684 |
record_result => $result->{record_result}, |
| 685 |
basket_id => 1, |
| 686 |
vendor => $bookseller, |
| 687 |
budget_id => $budgetid, |
| 688 |
agent => 'cron', |
| 689 |
} |
| 690 |
); |
| 691 |
|
| 692 |
my $nb_of_orders = Koha::Acquisition::Orders->count; |
| 693 |
|
| 694 |
my $order_lines = Koha::MarcOrder::create_order_lines( { order_line_details => $order_line_details } ); |
| 695 |
|
| 696 |
my $new_nb_of_orders = Koha::Acquisition::Orders->count; |
| 697 |
|
| 698 |
is($new_nb_of_orders, ( $nb_of_orders + $quantity ), 'Orders created successfully'); |
| 699 |
|
| 700 |
$schema->storage->txn_rollback; |
| 701 |
}; |
| 702 |
- |