| Lines 17-26
          
      
      
        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 => 10; | 
        
          | 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 253-260
          subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
      
      
        Link Here | 
        
          | 253 |     my $bpid = C4::Budgets::AddBudgetPeriod( | 253 |     my $bpid = C4::Budgets::AddBudgetPeriod( | 
        
          | 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 |  | 
            
              |  |  | 258 |                 # , budget_period_description => "MAPERI" | 
        
          | 258 |         } | 259 |         } | 
        
          | 259 |     ); | 260 |     ); | 
        
          | 260 |     my $budgetid = C4::Budgets::AddBudget( | 261 |     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); | 305 |     my $import_record             = Koha::Import::Records->find($import_record_id); | 
        
          | 305 |     my @import_record_id_selected = ($import_record_id); | 306 |     my @import_record_id_selected = ($import_record_id); | 
        
          | 306 |  | 307 |  | 
          
            
              | 307 |     my $result = Koha::MarcOrder::add_biblio_from_import_record( | 308 |     my $result = Koha::Acquisition::MarcOrder::add_biblio_from_import_record( | 
        
          | 308 |         { | 309 |         { | 
        
          | 309 |             import_record             => $import_record, | 310 |             import_record             => $import_record, | 
        
          | 310 |             matcher_id                => $sample_import_batch->{matcher_id}, | 311 |             matcher_id                => $sample_import_batch->{matcher_id}, | 
  
    | Lines 395-401
          subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
      
      
        Link Here | 
        
          | 395 |             'barcodes'                  => [], | 396 |             'barcodes'                  => [], | 
        
          | 396 |             'enumchrons'                => [] | 397 |             'enumchrons'                => [] | 
        
          | 397 |         }; | 398 |         }; | 
          
            
              | 398 |         my $itemnumbers = Koha::MarcOrder::add_items_from_import_record( | 399 |  | 
            
              |  |  | 400 |         my $itemnumbers = Koha::Acquisition::MarcOrder::add_items_from_import_record( | 
        
          | 399 |             { | 401 |             { | 
        
          | 400 |                 record_result      => $result->{record_result}, | 402 |                 record_result      => $result->{record_result}, | 
        
          | 401 |                 basket_id          => $basket->basketno, | 403 |                 basket_id          => $basket->basketno, | 
  
    | Lines 510-516
          subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub {
      
      
        Link Here | 
        
          | 510 |             'barcodes'                  => [], | 512 |             'barcodes'                  => [], | 
        
          | 511 |             'enumchrons'                => [] | 513 |             'enumchrons'                => [] | 
        
          | 512 |         }; | 514 |         }; | 
          
            
              | 513 |         my $itemnumbers = Koha::MarcOrder::add_items_from_import_record( | 515 |         my $itemnumbers = Koha::Acquisition::MarcOrder::add_items_from_import_record( | 
        
          | 514 |             { | 516 |             { | 
        
          | 515 |                 record_result      => $result->{record_result}, | 517 |                 record_result      => $result->{record_result}, | 
        
          | 516 |                 basket_id          => $basket->basketno, | 518 |                 basket_id          => $basket->basketno, | 
  
    | Lines 587-593
          subtest 'match_file_to_account' => sub {
      
      
        Link Here | 
        
          | 587 |  | 589 |  | 
        
          | 588 |     close $fh; | 590 |     close $fh; | 
        
          | 589 |  | 591 |  | 
          
            
              | 590 |     my $account1 = Koha::MarcOrderAccount->new( | 592 |     my $account1 = Koha::Acquisition::MarcOrderAccount->new( | 
        
          | 591 |         { | 593 |         { | 
        
          | 592 |             match_field => '975$p', | 594 |             match_field => '975$p', | 
        
          | 593 |             match_value => '12345', | 595 |             match_value => '12345', | 
  
    | Lines 596-602
          subtest 'match_file_to_account' => sub {
      
      
        Link Here | 
        
          | 596 |         } | 598 |         } | 
        
          | 597 |     )->store; | 599 |     )->store; | 
        
          | 598 |  | 600 |  | 
          
            
              | 599 |     my $file_match = Koha::MarcOrder->match_file_to_account( | 601 |     my $file_match = Koha::Acquisition::MarcOrder->match_file_to_account( | 
        
          | 600 |         { | 602 |         { | 
        
          | 601 |             filename => $name, | 603 |             filename => $name, | 
        
          | 602 |             filepath => $name, | 604 |             filepath => $name, | 
  
    | Lines 606-612
          subtest 'match_file_to_account' => sub {
      
      
        Link Here | 
        
          | 606 |  | 608 |  | 
        
          | 607 |     is( $file_match, 1, 'File matched correctly to the account' ); | 609 |     is( $file_match, 1, 'File matched correctly to the account' ); | 
        
          | 608 |  | 610 |  | 
          
            
              | 609 |     my $account2 = Koha::MarcOrderAccount->new( | 611 |     my $account2 = Koha::Acquisition::MarcOrderAccount->new( | 
        
          | 610 |         { | 612 |         { | 
        
          | 611 |             match_field => '975$p', | 613 |             match_field => '975$p', | 
        
          | 612 |             match_value => 'abcde', | 614 |             match_value => 'abcde', | 
  
    | Lines 615-621
          subtest 'match_file_to_account' => sub {
      
      
        Link Here | 
        
          | 615 |         } | 617 |         } | 
        
          | 616 |     )->store; | 618 |     )->store; | 
        
          | 617 |  | 619 |  | 
          
            
              | 618 |     my $file_match2 = Koha::MarcOrder->match_file_to_account( | 620 |     my $file_match2 = Koha::Acquisition::MarcOrder->match_file_to_account( | 
        
          | 619 |         { | 621 |         { | 
        
          | 620 |             filename => $name, | 622 |             filename => $name, | 
        
          | 621 |             filepath => $name, | 623 |             filepath => $name, | 
  
    | Lines 644-650
          subtest '_check_file_for_basket_name' => sub {
      
      
        Link Here | 
        
          | 644 |  | 646 |  | 
        
          | 645 |     close $fh; | 647 |     close $fh; | 
        
          | 646 |  | 648 |  | 
          
            
              | 647 |     my $account1 = Koha::MarcOrderAccount->new( | 649 |     my $account1 = Koha::Acquisition::MarcOrderAccount->new( | 
        
          | 648 |         { | 650 |         { | 
        
          | 649 |             basket_name_field => '975$p', | 651 |             basket_name_field => '975$p', | 
        
          | 650 |             encoding          => 'UTF-8', | 652 |             encoding          => 'UTF-8', | 
  
    | Lines 652-658
          subtest '_check_file_for_basket_name' => sub {
      
      
        Link Here | 
        
          | 652 |         } | 654 |         } | 
        
          | 653 |     )->store; | 655 |     )->store; | 
        
          | 654 |  | 656 |  | 
          
            
              | 655 |     my $basket_name = Koha::MarcOrder::_check_file_for_basket_name( | 657 |     my $basket_name = Koha::Acquisition::MarcOrder::_check_file_for_basket_name( | 
        
          | 656 |         { | 658 |         { | 
        
          | 657 |             filename => $name, | 659 |             filename => $name, | 
        
          | 658 |             filepath => $name, | 660 |             filepath => $name, | 
  
    | Lines 662-668
          subtest '_check_file_for_basket_name' => sub {
      
      
        Link Here | 
        
          | 662 |  | 664 |  | 
        
          | 663 |     is( $basket_name, "This is a basket", 'Basket name identified correctly' ); | 665 |     is( $basket_name, "This is a basket", 'Basket name identified correctly' ); | 
        
          | 664 |  | 666 |  | 
          
            
              | 665 |     my $account2 = Koha::MarcOrderAccount->new( | 667 |     my $account2 = Koha::Acquisition::MarcOrderAccount->new( | 
        
          | 666 |         { | 668 |         { | 
        
          | 667 |             basket_name_field => '975$z', | 669 |             basket_name_field => '975$z', | 
        
          | 668 |             encoding          => 'UTF-8', | 670 |             encoding          => 'UTF-8', | 
  
    | Lines 670-676
          subtest '_check_file_for_basket_name' => sub {
      
      
        Link Here | 
        
          | 670 |         } | 672 |         } | 
        
          | 671 |     )->store; | 673 |     )->store; | 
        
          | 672 |  | 674 |  | 
          
            
              | 673 |     my $basket_name2 = Koha::MarcOrder::_check_file_for_basket_name( | 675 |     my $basket_name2 = Koha::Acquisition::MarcOrder::_check_file_for_basket_name( | 
        
          | 674 |         { | 676 |         { | 
        
          | 675 |             filename => $name, | 677 |             filename => $name, | 
        
          | 676 |             filepath => $name, | 678 |             filepath => $name, | 
  
    | Lines 682-684
          subtest '_check_file_for_basket_name' => sub {
      
      
        Link Here | 
        
          | 682 |  | 684 |  | 
        
          | 683 |     $schema->storage->txn_rollback; | 685 |     $schema->storage->txn_rollback; | 
        
          | 684 | }; | 686 | }; | 
          
            
              | 685 | -  | 687 |  | 
            
              |  |  | 688 | subtest '_create_basket_for_file' => sub { | 
            
              | 689 |     plan tests => 2; | 
            
              | 690 |  | 
            
              | 691 |     $schema->storage->txn_begin; | 
            
              | 692 |  | 
            
              | 693 |     my $bookseller = Koha::Acquisition::Bookseller->new( | 
            
              | 694 |         { | 
            
              | 695 |             name         => "my vendor", | 
            
              | 696 |             address1     => "bookseller's address", | 
            
              | 697 |             phone        => "0123456", | 
            
              | 698 |             active       => 1, | 
            
              | 699 |             deliverytime => 5, | 
            
              | 700 |         } | 
            
              | 701 |     )->store; | 
            
              | 702 |  | 
            
              | 703 |     my $basket_count = Koha::Acquisition::Baskets->count; | 
            
              | 704 |  | 
            
              | 705 |     my $account1 = Koha::Acquisition::MarcOrderAccount->new( | 
            
              | 706 |         { | 
            
              | 707 |             match_field       => '975$p', | 
            
              | 708 |             match_value       => '12345', | 
            
              | 709 |             encoding          => 'UTF-8', | 
            
              | 710 |             description       => 'test', | 
            
              | 711 |             basket_name_field => undef | 
            
              | 712 |         } | 
            
              | 713 |     )->store; | 
            
              | 714 |  | 
            
              | 715 |     my $basketno = Koha::Acquisition::MarcOrder::_create_basket_for_file( | 
            
              | 716 |         { | 
            
              | 717 |             filename  => 'test_marc_file.marcxml', | 
            
              | 718 |             vendor_id => $bookseller->id, | 
            
              | 719 |             profile   => $account1 | 
            
              | 720 |         } | 
            
              | 721 |     ); | 
            
              | 722 |  | 
            
              | 723 |     my $new_basket_count = Koha::Acquisition::Baskets->count; | 
            
              | 724 |  | 
            
              | 725 |     is( $new_basket_count, $basket_count + 1, 'Basket was successfully created' ); | 
            
              | 726 |  | 
            
              | 727 |     my $basket = Koha::Acquisition::Baskets->find($basketno); | 
            
              | 728 |  | 
            
              | 729 |     is( $basket->basketname, 'test_marc_file.marcxml', 'Basket was successfully created' ); | 
            
              | 730 |  | 
            
              | 731 |     $schema->storage->txn_rollback; | 
            
              | 732 | }; | 
            
              | 733 |  | 
            
              | 734 | subtest 'parse_input_into_order_line_fields' => sub { | 
            
              | 735 |     plan tests => 8; | 
            
              | 736 |  | 
            
              | 737 |     $schema->storage->txn_begin; | 
            
              | 738 |  | 
            
              | 739 |     my $bpid = C4::Budgets::AddBudgetPeriod( | 
            
              | 740 |         { | 
            
              | 741 |             budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' | 
            
              | 742 |             , budget_period_active => 1 | 
            
              | 743 |         } | 
            
              | 744 |     ); | 
            
              | 745 |     my $budgetid = C4::Budgets::AddBudget( | 
            
              | 746 |         { | 
            
              | 747 |             budget_code      => "BC_1", | 
            
              | 748 |             budget_name      => "budget_name_test_1", | 
            
              | 749 |             budget_period_id => $bpid, | 
            
              | 750 |         } | 
            
              | 751 |     ); | 
            
              | 752 |     my $budgetid2 = C4::Budgets::AddBudget( | 
            
              | 753 |         { | 
            
              | 754 |             budget_code      => "BC_2", | 
            
              | 755 |             budget_name      => "budget_name_test_2", | 
            
              | 756 |             budget_period_id => $bpid, | 
            
              | 757 |         } | 
            
              | 758 |     ); | 
            
              | 759 |     my $fund1         = C4::Budgets::GetBudget($budgetid); | 
            
              | 760 |     my $fund2         = C4::Budgets::GetBudget($budgetid2); | 
            
              | 761 |     my $budget_code_1 = $fund1->{budget_code}; | 
            
              | 762 |     my $budget_code_2 = $fund2->{budget_code}; | 
            
              | 763 |  | 
            
              | 764 |     my $order_line_fields = Koha::Acquisition::MarcOrder::parse_input_into_order_line_fields( | 
            
              | 765 |         { | 
            
              | 766 |             agent        => 'cron', | 
            
              | 767 |             biblionumber => 1, | 
            
              | 768 |             budget_id    => 100, | 
            
              | 769 |             basket_id    => 101, | 
            
              | 770 |             fields       => { | 
            
              | 771 |                 quantity        => 2, | 
            
              | 772 |                 c_quantity      => 1, | 
            
              | 773 |                 homebranches    => [ 1, 2 ], | 
            
              | 774 |                 holdingbranches => undef, | 
            
              | 775 |                 budget_codes    => [ $budget_code_1, $budget_code_2 ], | 
            
              | 776 |             } | 
            
              | 777 |         } | 
            
              | 778 |     ); | 
            
              | 779 |  | 
            
              | 780 |     is( | 
            
              | 781 |         $order_line_fields->{loop_limit}, 2, | 
            
              | 782 |         "Quantity has been read correctly" | 
            
              | 783 |     ); | 
            
              | 784 |     is( scalar( @{ $order_line_fields->{homebranch} } ),    2, "Home branches have been read correctly" ); | 
            
              | 785 |     is( @{ $order_line_fields->{homebranch} }[0],           1, "Home branches has been read correctly" ); | 
            
              | 786 |     is( scalar( @{ $order_line_fields->{holdingbranch} } ), 0, "Holding branches have been read correctly" ); | 
            
              | 787 |     is( scalar( @{ $order_line_fields->{budget_code} } ),   2, "Budget codes have been read correctly" ); | 
            
              | 788 |     is( @{ $order_line_fields->{budget_code} }[0],          $budget_code_1, "Budget codes has been read correctly" ); | 
            
              | 789 |  | 
            
              | 790 |     # Test with no budget codes to check account budget_id assigned correctly | 
            
              | 791 |     $order_line_fields = Koha::Acquisition::MarcOrder::parse_input_into_order_line_fields( | 
            
              | 792 |         { | 
            
              | 793 |             agent        => 'cron', | 
            
              | 794 |             biblionumber => 1, | 
            
              | 795 |             budget_id    => 100, | 
            
              | 796 |             basket_id    => 101, | 
            
              | 797 |             fields       => { | 
            
              | 798 |                 quantity        => 2, | 
            
              | 799 |                 c_quantity      => 1, | 
            
              | 800 |                 homebranches    => [ 1, 2 ], | 
            
              | 801 |                 holdingbranches => undef, | 
            
              | 802 |                 budget_codes    => [], | 
            
              | 803 |             } | 
            
              | 804 |         } | 
            
              | 805 |     ); | 
            
              | 806 |  | 
            
              | 807 |     is( scalar( @{ $order_line_fields->{budget_code} } ), 2,   "Budget codes have been read correctly" ); | 
            
              | 808 |     is( @{ $order_line_fields->{budget_code} }[0],        100, "Budget codes has been read correctly" ); | 
            
              | 809 |  | 
            
              | 810 |     $schema->storage->txn_rollback; | 
            
              | 811 | }; | 
            
              | 812 |  | 
            
              | 813 | subtest 'create_items_and_generate_order_hash' => sub { | 
            
              | 814 |     plan tests => 6; | 
            
              | 815 |  | 
            
              | 816 |     $schema->storage->txn_begin; | 
            
              | 817 |  | 
            
              | 818 |     my $bpid = C4::Budgets::AddBudgetPeriod( | 
            
              | 819 |         { | 
            
              | 820 |             budget_period_startdate => '2008-01-01', budget_period_enddate => '2008-12-31' | 
            
              | 821 |             , budget_period_active => 1 | 
            
              | 822 |         } | 
            
              | 823 |     ); | 
            
              | 824 |     my $budgetid = C4::Budgets::AddBudget( | 
            
              | 825 |         { | 
            
              | 826 |             budget_code      => "BC_1", | 
            
              | 827 |             budget_name      => "budget_name_test_1", | 
            
              | 828 |             budget_period_id => $bpid, | 
            
              | 829 |         } | 
            
              | 830 |     ); | 
            
              | 831 |     my $budgetid2 = C4::Budgets::AddBudget( | 
            
              | 832 |         { | 
            
              | 833 |             budget_code      => "BC_2", | 
            
              | 834 |             budget_name      => "budget_name_test_2", | 
            
              | 835 |             budget_period_id => $bpid, | 
            
              | 836 |         } | 
            
              | 837 |     ); | 
            
              | 838 |     my $fund1       = C4::Budgets::GetBudget($budgetid); | 
            
              | 839 |     my $fund2       = C4::Budgets::GetBudget($budgetid2); | 
            
              | 840 |     my $budget_id_1 = $fund1->{budget_id}; | 
            
              | 841 |     my $budget_id_2 = $fund2->{budget_id}; | 
            
              | 842 |  | 
            
              | 843 |     my $bookseller = Koha::Acquisition::Bookseller->new( | 
            
              | 844 |         { | 
            
              | 845 |             name         => "my vendor", | 
            
              | 846 |             address1     => "bookseller's address", | 
            
              | 847 |             phone        => "0123456", | 
            
              | 848 |             active       => 1, | 
            
              | 849 |             deliverytime => 5, | 
            
              | 850 |         } | 
            
              | 851 |     )->store; | 
            
              | 852 |  | 
            
              | 853 |     my $basket = $builder->build_object( | 
            
              | 854 |         { | 
            
              | 855 |             class => "Koha::Acquisition::Baskets", | 
            
              | 856 |             value => { | 
            
              | 857 |                 booksellerid => $bookseller->id, | 
            
              | 858 |                 create_items => 'ordering', | 
            
              | 859 |                 is_standing  => 0, | 
            
              | 860 |                 closedate    => undef | 
            
              | 861 |             } | 
            
              | 862 |         } | 
            
              | 863 |     ); | 
            
              | 864 |  | 
            
              | 865 |     my $biblio     = $builder->build_sample_biblio; | 
            
              | 866 |     my $library    = $builder->build( { source => 'Branch' } ); | 
            
              | 867 |     my $branchcode = $library->{branchcode}; | 
            
              | 868 |  | 
            
              | 869 |     my $fields = { | 
            
              | 870 |         loop_limit   => 2, | 
            
              | 871 |         budget_code  => [ $budget_id_1, $budget_id_2 ], | 
            
              | 872 |         budget_id    => $budget_id_1, | 
            
              | 873 |         basket_id    => $basket->basketno, | 
            
              | 874 |         biblionumber => $biblio->biblionumber, | 
            
              | 875 |         homebranch   => [ $branchcode, $branchcode ], | 
            
              | 876 |         price        => [ 10,          8 ], | 
            
              | 877 |     }; | 
            
              | 878 |  | 
            
              | 879 |     t::lib::Mocks::mock_preference( 'AcqCreateItem', 'ordering' ); | 
            
              | 880 |  | 
            
              | 881 |     my $items_count  = Koha::Items->count; | 
            
              | 882 |     my $orders_count = Koha::Acquisition::Orders->count; | 
            
              | 883 |  | 
            
              | 884 |     my $order_line_details = Koha::Acquisition::MarcOrder::create_items_and_generate_order_hash( | 
            
              | 885 |         { | 
            
              | 886 |             agent           => 'cron', | 
            
              | 887 |             fields          => $fields, | 
            
              | 888 |             vendor          => $bookseller, | 
            
              | 889 |             active_currency => Koha::Acquisition::Currencies->get_active, | 
            
              | 890 |         } | 
            
              | 891 |     ); | 
            
              | 892 |     my $new_items_count  = Koha::Items->count; | 
            
              | 893 |     my $new_orders_count = Koha::Acquisition::Orders->count; | 
            
              | 894 |  | 
            
              | 895 |     is( $new_items_count,  $items_count + 2,  'Items were successfully created' ); | 
            
              | 896 |     is( $new_orders_count, $orders_count + 2, 'Orders were successfully created' ); | 
            
              | 897 |  | 
            
              | 898 |     my @items = Koha::Items->search( { biblionumber => $biblio->biblionumber } )->as_list; | 
            
              | 899 |  | 
            
              | 900 |     foreach my $item (@items) { | 
            
              | 901 |         is( $item->homebranch, $branchcode, 'Item was created in correct branch' ); | 
            
              | 902 |     } | 
            
              | 903 |  | 
            
              | 904 |     my @orderlines = sort { $a->budget_id <=> $b->budget_id } | 
            
              | 905 |         Koha::Acquisition::Orders->search( { biblionumber => $biblio->biblionumber } )->as_list; | 
            
              | 906 |  | 
            
              | 907 |     for ( my $i = 0 ; $i < ( scalar(@orderlines) ) ; $i++ ) { | 
            
              | 908 |         is( $orderlines[$i]->budget_id, @{ $fields->{budget_code} }[$i], 'Orderline was created with correct budget' ); | 
            
              | 909 |     } | 
            
              | 910 |  | 
            
              | 911 |     $schema->storage->txn_rollback; | 
            
              | 912 | }; | 
            
              | 913 |  | 
            
              | 914 | subtest '_create_item_fields_from_syspref' => sub { | 
            
              | 915 |     plan tests => 4; | 
            
              | 916 |  | 
            
              | 917 |     $schema->storage->txn_begin; | 
            
              | 918 |  | 
            
              | 919 |     t::lib::Mocks::mock_preference( | 
            
              | 920 |         'MarcItemFieldsToOrder', 'homebranch: 975$a | 
            
              | 921 | holdingbranch: 975$b | 
            
              | 922 | itype: 975$y | 
            
              | 923 | nonpublic_note: 975$x | 
            
              | 924 | public_note: 975$z | 
            
              | 925 | loc: 975$c | 
            
              | 926 | ccode: 975$8 | 
            
              | 927 | notforloan: 975$7 | 
            
              | 928 | uri: 975$u | 
            
              | 929 | copyno: 975$n | 
            
              | 930 | quantity: 975$q | 
            
              | 931 | budget_code: 975$h | 
            
              | 932 | price: 975$p | 
            
              | 933 | replacementprice: 975$v' | 
            
              | 934 |     ); | 
            
              | 935 |  | 
            
              | 936 |     t::lib::Mocks::mock_preference( | 
            
              | 937 |         'MarcFieldsToOrder', 'price: 949$p | 
            
              | 938 | quantity: 949$q | 
            
              | 939 | budget_code: 949$h' | 
            
              | 940 |     ); | 
            
              | 941 |  | 
            
              | 942 |     my $record = MARC::Record->new(); | 
            
              | 943 |  | 
            
              | 944 |     $record->add_fields( | 
            
              | 945 |         [ '001', '1234' ], | 
            
              | 946 |         [ | 
            
              | 947 |             '975', ' ', ' ', p => 10, q => 1, h => 1, a => 'CPL', b => 'CPL', y => 'Book', | 
            
              | 948 |             x => 'Private note', z => 'Public note', c => 'Shelf', 8 => 'ccode', 7 => 0, | 
            
              | 949 |             u => '12345abcde',   n => '12345',       v => 10 | 
            
              | 950 |         ], | 
            
              | 951 |     ); | 
            
              | 952 |     $record->add_fields( | 
            
              | 953 |         [ '001', '1234' ], | 
            
              | 954 |  | 
            
              | 955 |         [ '949', ' ', ' ', p => 10, q => 1, h => 1 ], | 
            
              | 956 |     ); | 
            
              | 957 |  | 
            
              | 958 |     my $marc_item_fields_to_order = Koha::Acquisition::MarcOrder::_get_syspref_mappings( | 
            
              | 959 |         $record, 'MarcItemFieldsToOrder', | 
            
              | 960 |     ); | 
            
              | 961 |  | 
            
              | 962 |     my $marc_fields_to_order = Koha::Acquisition::MarcOrder::_get_syspref_mappings( | 
            
              | 963 |         $record, 'MarcFieldsToOrder', | 
            
              | 964 |     ); | 
            
              | 965 |  | 
            
              | 966 |     my $item_fields = Koha::Acquisition::MarcOrder::_create_item_fields_from_syspref( | 
            
              | 967 |         { | 
            
              | 968 |             marc_fields_to_order      => $marc_fields_to_order, | 
            
              | 969 |             marc_item_fields_to_order => $marc_item_fields_to_order | 
            
              | 970 |         } | 
            
              | 971 |     ); | 
            
              | 972 |  | 
            
              | 973 |     is( | 
            
              | 974 |         @{ $item_fields->{itemprices} }[0], 10, | 
            
              | 975 |         "Price has been read correctly" | 
            
              | 976 |     ); | 
            
              | 977 |     is( | 
            
              | 978 |         @{ $item_fields->{itypes} }[0], "Book", | 
            
              | 979 |         "Itypes has been read correctly" | 
            
              | 980 |     ); | 
            
              | 981 |     is( $item_fields->{quantity}, 1,  "Quantity has been read correctly" ); | 
            
              | 982 |     is( $item_fields->{c_price},  10, "MarcFieldsToOrder price has been read correctly" ); | 
            
              | 983 |  | 
            
              | 984 |     $schema->storage->txn_rollback; | 
            
              | 985 |  | 
            
              | 986 |     } |