|
Lines 17-26
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 5; |
20 |
use Test::More tests => 9; |
| 21 |
|
21 |
|
| 22 |
use Koha::MarcOrder; |
22 |
use Koha::Acquisition::MarcOrder; |
| 23 |
use Koha::MarcOrderAccount; |
23 |
use Koha::Acquisition::MarcOrderAccount; |
| 24 |
use Koha::Acquisition::Baskets; |
24 |
use Koha::Acquisition::Baskets; |
| 25 |
use Koha::Acquisition::Bookseller; |
25 |
use Koha::Acquisition::Bookseller; |
| 26 |
use MARC::Record; |
26 |
use MARC::Record; |
|
Lines 71-77
replacementprice: 975$v'
Link Here
|
| 71 |
); |
71 |
); |
| 72 |
|
72 |
|
| 73 |
my $marc_item_fields_to_order = @{ |
73 |
my $marc_item_fields_to_order = @{ |
| 74 |
Koha::MarcOrder::_get_syspref_mappings( |
74 |
Koha::Acquisition::MarcOrder::_get_syspref_mappings( |
| 75 |
$record, 'MarcItemFieldsToOrder', |
75 |
$record, 'MarcItemFieldsToOrder', |
| 76 |
) |
76 |
) |
| 77 |
}[0]; |
77 |
}[0]; |
|
Lines 154-160
budget_code: 975$h'
Link Here
|
| 154 |
[ '975', ' ', ' ', p => 10, q => 1, h => 1 ], |
154 |
[ '975', ' ', ' ', p => 10, q => 1, h => 1 ], |
| 155 |
); |
155 |
); |
| 156 |
|
156 |
|
| 157 |
my $marc_fields_to_order = Koha::MarcOrder::_get_syspref_mappings( |
157 |
my $marc_fields_to_order = Koha::Acquisition::MarcOrder::_get_syspref_mappings( |
| 158 |
$record, 'MarcFieldsToOrder', |
158 |
$record, 'MarcFieldsToOrder', |
| 159 |
); |
159 |
); |
| 160 |
|
160 |
|
|
Lines 206-212
subtest 'add_biblio_from_import_record()' => sub {
Link Here
|
| 206 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
206 |
my $import_record_id = C4::ImportBatch::AddBiblioToBatch( $import_batch_id, 0, $record, 'utf8', 0 ); |
| 207 |
my $import_record = Koha::Import::Records->find($import_record_id); |
207 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 208 |
|
208 |
|
| 209 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
209 |
my $result = Koha::Acquisition::MarcOrder::add_biblio_from_import_record( |
| 210 |
{ |
210 |
{ |
| 211 |
import_record => $import_record, |
211 |
import_record => $import_record, |
| 212 |
matcher_id => $sample_import_batch->{matcher_id}, |
212 |
matcher_id => $sample_import_batch->{matcher_id}, |
|
Lines 224-230
subtest 'add_biblio_from_import_record()' => sub {
Link Here
|
| 224 |
# Check that records are skipped if not selected when called from addorderiso2709.pl |
224 |
# Check that records are skipped if not selected when called from addorderiso2709.pl |
| 225 |
# Pass in an empty array and the record should be skipped |
225 |
# Pass in an empty array and the record should be skipped |
| 226 |
my @import_record_id_selected = (); |
226 |
my @import_record_id_selected = (); |
| 227 |
my $result2 = Koha::MarcOrder::add_biblio_from_import_record( |
227 |
my $result2 = Koha::Acquisition::MarcOrder::add_biblio_from_import_record( |
| 228 |
{ |
228 |
{ |
| 229 |
import_record => $import_record, |
229 |
import_record => $import_record, |
| 230 |
matcher_id => $sample_import_batch->{matcher_id}, |
230 |
matcher_id => $sample_import_batch->{matcher_id}, |
|
Lines 254-260
subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
Link Here
|
| 254 |
{ |
254 |
{ |
| 255 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
255 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
| 256 |
, budget_period_active => 1 |
256 |
, budget_period_active => 1 |
| 257 |
, budget_period_description => "MAPERI" |
257 |
# , budget_period_description => "MAPERI" |
| 258 |
} |
258 |
} |
| 259 |
); |
259 |
); |
| 260 |
my $budgetid = C4::Budgets::AddBudget( |
260 |
my $budgetid = C4::Budgets::AddBudget( |
|
Lines 304-310
subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
Link Here
|
| 304 |
my $import_record = Koha::Import::Records->find($import_record_id); |
304 |
my $import_record = Koha::Import::Records->find($import_record_id); |
| 305 |
my @import_record_id_selected = ($import_record_id); |
305 |
my @import_record_id_selected = ($import_record_id); |
| 306 |
|
306 |
|
| 307 |
my $result = Koha::MarcOrder::add_biblio_from_import_record( |
307 |
my $result = Koha::Acquisition::MarcOrder::add_biblio_from_import_record( |
| 308 |
{ |
308 |
{ |
| 309 |
import_record => $import_record, |
309 |
import_record => $import_record, |
| 310 |
matcher_id => $sample_import_batch->{matcher_id}, |
310 |
matcher_id => $sample_import_batch->{matcher_id}, |
|
Lines 393-399
subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
Link Here
|
| 393 |
'enumchrons' => [] |
393 |
'enumchrons' => [] |
| 394 |
}; |
394 |
}; |
| 395 |
|
395 |
|
| 396 |
my $itemnumbers = Koha::MarcOrder::add_items_from_import_record( |
396 |
my $itemnumbers = Koha::Acquisition::MarcOrder::add_items_from_import_record( |
| 397 |
{ |
397 |
{ |
| 398 |
record_result => $result->{record_result}, |
398 |
record_result => $result->{record_result}, |
| 399 |
basket_id => $basket->basketno, |
399 |
basket_id => $basket->basketno, |
|
Lines 456-462
subtest 'match_file_to_account' => sub {
Link Here
|
| 456 |
|
456 |
|
| 457 |
close $fh; |
457 |
close $fh; |
| 458 |
|
458 |
|
| 459 |
my $account1 = Koha::MarcOrderAccount->new( |
459 |
my $account1 = Koha::Acquisition::MarcOrderAccount->new( |
| 460 |
{ |
460 |
{ |
| 461 |
match_field => '975$p', |
461 |
match_field => '975$p', |
| 462 |
match_value => '12345', |
462 |
match_value => '12345', |
|
Lines 465-471
subtest 'match_file_to_account' => sub {
Link Here
|
| 465 |
} |
465 |
} |
| 466 |
)->store; |
466 |
)->store; |
| 467 |
|
467 |
|
| 468 |
my $file_match = Koha::MarcOrder->match_file_to_account( |
468 |
my $file_match = Koha::Acquisition::MarcOrder->match_file_to_account( |
| 469 |
{ |
469 |
{ |
| 470 |
filename => $name, |
470 |
filename => $name, |
| 471 |
filepath => $name, |
471 |
filepath => $name, |
|
Lines 475-481
subtest 'match_file_to_account' => sub {
Link Here
|
| 475 |
|
475 |
|
| 476 |
is( $file_match, 1, 'File matched correctly to the account' ); |
476 |
is( $file_match, 1, 'File matched correctly to the account' ); |
| 477 |
|
477 |
|
| 478 |
my $account2 = Koha::MarcOrderAccount->new( |
478 |
my $account2 = Koha::Acquisition::MarcOrderAccount->new( |
| 479 |
{ |
479 |
{ |
| 480 |
match_field => '975$p', |
480 |
match_field => '975$p', |
| 481 |
match_value => 'abcde', |
481 |
match_value => 'abcde', |
|
Lines 484-490
subtest 'match_file_to_account' => sub {
Link Here
|
| 484 |
} |
484 |
} |
| 485 |
)->store; |
485 |
)->store; |
| 486 |
|
486 |
|
| 487 |
my $file_match2 = Koha::MarcOrder->match_file_to_account( |
487 |
my $file_match2 = Koha::Acquisition::MarcOrder->match_file_to_account( |
| 488 |
{ |
488 |
{ |
| 489 |
filename => $name, |
489 |
filename => $name, |
| 490 |
filepath => $name, |
490 |
filepath => $name, |
|
Lines 496-498
subtest 'match_file_to_account' => sub {
Link Here
|
| 496 |
|
496 |
|
| 497 |
$schema->storage->txn_rollback; |
497 |
$schema->storage->txn_rollback; |
| 498 |
}; |
498 |
}; |
| 499 |
- |
499 |
|
|
|
500 |
subtest '_create_basket_for_file' => sub { |
| 501 |
plan tests => 2; |
| 502 |
|
| 503 |
$schema->storage->txn_begin; |
| 504 |
|
| 505 |
my $bookseller = Koha::Acquisition::Bookseller->new( |
| 506 |
{ |
| 507 |
name => "my vendor", |
| 508 |
address1 => "bookseller's address", |
| 509 |
phone => "0123456", |
| 510 |
active => 1, |
| 511 |
deliverytime => 5, |
| 512 |
} |
| 513 |
)->store; |
| 514 |
|
| 515 |
my $basket_count = Koha::Acquisition::Baskets->count; |
| 516 |
|
| 517 |
my $basketno = Koha::Acquisition::MarcOrder::_create_basket_for_file( |
| 518 |
{ |
| 519 |
filename => 'test_marc_file.marcxml', |
| 520 |
vendor_id => $bookseller->id, |
| 521 |
} |
| 522 |
); |
| 523 |
|
| 524 |
my $new_basket_count = Koha::Acquisition::Baskets->count; |
| 525 |
|
| 526 |
is( $new_basket_count, $basket_count + 1, 'Basket was successfully created' ); |
| 527 |
|
| 528 |
my $basket = Koha::Acquisition::Baskets->find($basketno); |
| 529 |
|
| 530 |
is( $basket->basketname, 'test_marc_file.marcxml', 'Basket was successfully created' ); |
| 531 |
|
| 532 |
$schema->storage->txn_rollback; |
| 533 |
}; |
| 534 |
|
| 535 |
subtest 'parse_input_into_order_line_fields' => sub { |
| 536 |
plan tests => 8; |
| 537 |
|
| 538 |
$schema->storage->txn_begin; |
| 539 |
|
| 540 |
my $bpid = C4::Budgets::AddBudgetPeriod( |
| 541 |
{ |
| 542 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
| 543 |
, budget_period_active => 1 |
| 544 |
} |
| 545 |
); |
| 546 |
my $budgetid = C4::Budgets::AddBudget( |
| 547 |
{ |
| 548 |
budget_code => "BC_1", |
| 549 |
budget_name => "budget_name_test_1", |
| 550 |
budget_period_id => $bpid, |
| 551 |
} |
| 552 |
); |
| 553 |
my $budgetid2 = C4::Budgets::AddBudget( |
| 554 |
{ |
| 555 |
budget_code => "BC_2", |
| 556 |
budget_name => "budget_name_test_2", |
| 557 |
budget_period_id => $bpid, |
| 558 |
} |
| 559 |
); |
| 560 |
my $fund1 = C4::Budgets::GetBudget($budgetid); |
| 561 |
my $fund2 = C4::Budgets::GetBudget($budgetid2); |
| 562 |
my $budget_code_1 = $fund1->{budget_code}; |
| 563 |
my $budget_code_2 = $fund2->{budget_code}; |
| 564 |
|
| 565 |
my $order_line_fields = Koha::Acquisition::MarcOrder::parse_input_into_order_line_fields( |
| 566 |
{ |
| 567 |
agent => 'cron', |
| 568 |
biblionumber => 1, |
| 569 |
budget_id => 100, |
| 570 |
basket_id => 101, |
| 571 |
fields => { |
| 572 |
quantity => 2, |
| 573 |
c_quantity => 1, |
| 574 |
homebranches => [ 1, 2 ], |
| 575 |
holdingbranches => undef, |
| 576 |
budget_codes => [ $budget_code_1, $budget_code_2 ], |
| 577 |
} |
| 578 |
} |
| 579 |
); |
| 580 |
|
| 581 |
is( |
| 582 |
$order_line_fields->{loop_limit}, 2, |
| 583 |
"Quantity has been read correctly" |
| 584 |
); |
| 585 |
is( scalar( @{ $order_line_fields->{homebranch} } ), 2, "Home branches have been read correctly" ); |
| 586 |
is( @{ $order_line_fields->{homebranch} }[0], 1, "Home branches has been read correctly" ); |
| 587 |
is( scalar( @{ $order_line_fields->{holdingbranch} } ), 0, "Holding branches have been read correctly" ); |
| 588 |
is( scalar( @{ $order_line_fields->{budget_code} } ), 2, "Budget codes have been read correctly" ); |
| 589 |
is( @{ $order_line_fields->{budget_code} }[0], $budget_code_1, "Budget codes has been read correctly" ); |
| 590 |
|
| 591 |
# Test with no budget codes to check account budget_id assigned correctly |
| 592 |
$order_line_fields = Koha::Acquisition::MarcOrder::parse_input_into_order_line_fields( |
| 593 |
{ |
| 594 |
agent => 'cron', |
| 595 |
biblionumber => 1, |
| 596 |
budget_id => 100, |
| 597 |
basket_id => 101, |
| 598 |
fields => { |
| 599 |
quantity => 2, |
| 600 |
c_quantity => 1, |
| 601 |
homebranches => [ 1, 2 ], |
| 602 |
holdingbranches => undef, |
| 603 |
budget_codes => [], |
| 604 |
} |
| 605 |
} |
| 606 |
); |
| 607 |
|
| 608 |
is( scalar( @{ $order_line_fields->{budget_code} } ), 2, "Budget codes have been read correctly" ); |
| 609 |
is( @{ $order_line_fields->{budget_code} }[0], 100, "Budget codes has been read correctly" ); |
| 610 |
|
| 611 |
$schema->storage->txn_rollback; |
| 612 |
}; |
| 613 |
|
| 614 |
subtest 'create_items_and_generate_order_hash' => sub { |
| 615 |
plan tests => 6; |
| 616 |
|
| 617 |
$schema->storage->txn_begin; |
| 618 |
|
| 619 |
my $bpid = C4::Budgets::AddBudgetPeriod( |
| 620 |
{ |
| 621 |
budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' |
| 622 |
, budget_period_active => 1 |
| 623 |
} |
| 624 |
); |
| 625 |
my $budgetid = C4::Budgets::AddBudget( |
| 626 |
{ |
| 627 |
budget_code => "BC_1", |
| 628 |
budget_name => "budget_name_test_1", |
| 629 |
budget_period_id => $bpid, |
| 630 |
} |
| 631 |
); |
| 632 |
my $budgetid2 = C4::Budgets::AddBudget( |
| 633 |
{ |
| 634 |
budget_code => "BC_2", |
| 635 |
budget_name => "budget_name_test_2", |
| 636 |
budget_period_id => $bpid, |
| 637 |
} |
| 638 |
); |
| 639 |
my $fund1 = C4::Budgets::GetBudget($budgetid); |
| 640 |
my $fund2 = C4::Budgets::GetBudget($budgetid2); |
| 641 |
my $budget_id_1 = $fund1->{budget_id}; |
| 642 |
my $budget_id_2 = $fund2->{budget_id}; |
| 643 |
|
| 644 |
my $bookseller = Koha::Acquisition::Bookseller->new( |
| 645 |
{ |
| 646 |
name => "my vendor", |
| 647 |
address1 => "bookseller's address", |
| 648 |
phone => "0123456", |
| 649 |
active => 1, |
| 650 |
deliverytime => 5, |
| 651 |
} |
| 652 |
)->store; |
| 653 |
|
| 654 |
my $basket = $builder->build_object( |
| 655 |
{ |
| 656 |
class => "Koha::Acquisition::Baskets", |
| 657 |
value => { |
| 658 |
booksellerid => $bookseller->id, |
| 659 |
create_items => 'ordering', |
| 660 |
is_standing => 0, |
| 661 |
closedate => undef |
| 662 |
} |
| 663 |
} |
| 664 |
); |
| 665 |
|
| 666 |
my $biblio = $builder->build_sample_biblio; |
| 667 |
my $library = $builder->build( { source => 'Branch' } ); |
| 668 |
my $branchcode = $library->{branchcode}; |
| 669 |
|
| 670 |
my $fields = { |
| 671 |
loop_limit => 2, |
| 672 |
budget_code => [ $budget_id_1, $budget_id_2 ], |
| 673 |
budget_id => $budget_id_1, |
| 674 |
basket_id => $basket->basketno, |
| 675 |
biblionumber => $biblio->biblionumber, |
| 676 |
homebranch => [ $branchcode, $branchcode ], |
| 677 |
price => [ 10, 8 ], |
| 678 |
}; |
| 679 |
|
| 680 |
t::lib::Mocks::mock_preference( |
| 681 |
'AcqCreateItem', 'ordering' |
| 682 |
); |
| 683 |
|
| 684 |
my $items_count = Koha::Items->count; |
| 685 |
my $orders_count = Koha::Acquisition::Orders->count; |
| 686 |
|
| 687 |
my $order_line_details = Koha::Acquisition::MarcOrder::create_items_and_generate_order_hash( |
| 688 |
{ |
| 689 |
agent => 'cron', |
| 690 |
fields => $fields, |
| 691 |
vendor => $bookseller, |
| 692 |
active_currency => Koha::Acquisition::Currencies->get_active, |
| 693 |
} |
| 694 |
); |
| 695 |
my $new_items_count = Koha::Items->count; |
| 696 |
my $new_orders_count = Koha::Acquisition::Orders->count; |
| 697 |
|
| 698 |
is( $new_items_count, $items_count + 2, 'Items were successfully created' ); |
| 699 |
is( $new_orders_count, $orders_count + 2, 'Orders were successfully created' ); |
| 700 |
|
| 701 |
my @items = Koha::Items->search( { biblionumber => $biblio->biblionumber } )->as_list; |
| 702 |
|
| 703 |
foreach my $item (@items) { |
| 704 |
is( $item->homebranch, $branchcode, 'Item was created in correct branch' ); |
| 705 |
} |
| 706 |
|
| 707 |
my @orderlines = sort { $a->budget_id <=> $b->budget_id } Koha::Acquisition::Orders->search( { biblionumber => $biblio->biblionumber } )->as_list; |
| 708 |
|
| 709 |
for( my $i = 0; $i < (scalar(@orderlines)); $i++ ) { |
| 710 |
is( $orderlines[$i]->budget_id, @{$fields->{budget_code}}[$i], 'Orderline was created with correct budget' ); |
| 711 |
} |
| 712 |
|
| 713 |
$schema->storage->txn_rollback; |
| 714 |
}; |
| 715 |
|
| 716 |
subtest '_create_item_fields_from_syspref' => sub { |
| 717 |
plan tests => 4; |
| 718 |
|
| 719 |
$schema->storage->txn_begin; |
| 720 |
|
| 721 |
t::lib::Mocks::mock_preference( |
| 722 |
'MarcItemFieldsToOrder', 'homebranch: 975$a |
| 723 |
holdingbranch: 975$b |
| 724 |
itype: 975$y |
| 725 |
nonpublic_note: 975$x |
| 726 |
public_note: 975$z |
| 727 |
loc: 975$c |
| 728 |
ccode: 975$8 |
| 729 |
notforloan: 975$7 |
| 730 |
uri: 975$u |
| 731 |
copyno: 975$n |
| 732 |
quantity: 975$q |
| 733 |
budget_code: 975$h |
| 734 |
price: 975$p |
| 735 |
replacementprice: 975$v' |
| 736 |
); |
| 737 |
|
| 738 |
t::lib::Mocks::mock_preference( |
| 739 |
'MarcFieldsToOrder', 'price: 949$p |
| 740 |
quantity: 949$q |
| 741 |
budget_code: 949$h' |
| 742 |
); |
| 743 |
|
| 744 |
my $record = MARC::Record->new(); |
| 745 |
|
| 746 |
$record->add_fields( |
| 747 |
[ '001', '1234' ], |
| 748 |
[ |
| 749 |
'975', ' ', ' ', p => 10, q => 1, h => 1, a => 'CPL', b => 'CPL', y => 'Book', |
| 750 |
x => 'Private note', z => 'Public note', c => 'Shelf', 8 => 'ccode', 7 => 0, |
| 751 |
u => '12345abcde', n => '12345', v => 10 |
| 752 |
], |
| 753 |
); |
| 754 |
$record->add_fields( |
| 755 |
[ '001', '1234' ], |
| 756 |
|
| 757 |
[ '949', ' ', ' ', p => 10, q => 1, h => 1 ], |
| 758 |
); |
| 759 |
|
| 760 |
my $marc_item_fields_to_order = Koha::Acquisition::MarcOrder::_get_syspref_mappings( |
| 761 |
$record, 'MarcItemFieldsToOrder', |
| 762 |
); |
| 763 |
|
| 764 |
my $marc_fields_to_order = Koha::Acquisition::MarcOrder::_get_syspref_mappings( |
| 765 |
$record, 'MarcFieldsToOrder', |
| 766 |
); |
| 767 |
|
| 768 |
my $item_fields = Koha::Acquisition::MarcOrder::_create_item_fields_from_syspref( |
| 769 |
{ |
| 770 |
marc_fields_to_order => $marc_fields_to_order, |
| 771 |
marc_item_fields_to_order => $marc_item_fields_to_order |
| 772 |
} |
| 773 |
); |
| 774 |
|
| 775 |
is( |
| 776 |
@{$item_fields->{itemprices}}[0], 10, |
| 777 |
"Price has been read correctly" |
| 778 |
); |
| 779 |
is( |
| 780 |
@{$item_fields->{itypes}}[0], "Book", |
| 781 |
"Itypes has been read correctly" |
| 782 |
); |
| 783 |
is($item_fields->{quantity}, 1, "Quantity has been read correctly"); |
| 784 |
is($item_fields->{c_price}, 10, "MarcFieldsToOrder price has been read correctly"); |
| 785 |
|
| 786 |
$schema->storage->txn_rollback; |
| 787 |
|
| 788 |
} |
| 789 |
|