Bugzilla – Attachment 168981 Details for
Bug 35026
Refactor addorderiso2709.pl to use object methods
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35026: (QA follow-up): Fix QA tests
Bug-35026-QA-follow-up-Fix-QA-tests.patch (text/plain), 11.56 KB, created by
Matt Blenkinsop
on 2024-07-15 11:48:40 UTC
(
hide
)
Description:
Bug 35026: (QA follow-up): Fix QA tests
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-07-15 11:48:40 UTC
Size:
11.56 KB
patch
obsolete
>From b14684b9fb036222be1b6675012d4eecb1be87c4 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Mon, 15 Jul 2024 11:17:59 +0000 >Subject: [PATCH] Bug 35026: (QA follow-up): Fix QA tests > >--- > Koha/MarcOrder.pm | 76 +++++++++++---------------------- > t/db_dependent/Koha/MarcOrder.t | 33 +++++++------- > 2 files changed, 42 insertions(+), 67 deletions(-) > >diff --git a/Koha/MarcOrder.pm b/Koha/MarcOrder.pm >index 2fa316d4465..4bb58c41cf0 100644 >--- a/Koha/MarcOrder.pm >+++ b/Koha/MarcOrder.pm >@@ -108,7 +108,7 @@ sub import_record_and_create_order_lines { > skip => $result->{skip} > } if $result->{skip}; > >- my $order_line_details = add_items_from_import_record( >+ my $itemnumbers = add_items_from_import_record( > { > record_result => $result->{record_result}, > basket_id => $basket_id, >@@ -119,8 +119,6 @@ sub import_record_and_create_order_lines { > } > ); > >- my $order_lines = create_order_lines( { order_line_details => $order_line_details } ); >- > return { > duplicates_in_batch => 0, > skip => 0 >@@ -136,7 +134,7 @@ sub import_record_and_create_order_lines { > =cut > > sub _get_syspref_mappings { >- my ($record, $syspref_to_read) = @_; >+ my ( $record, $syspref_to_read ) = @_; > my $syspref = C4::Context->yaml_preference($syspref_to_read); > my @result; > my @tags_list; >@@ -183,7 +181,7 @@ sub _get_syspref_mappings { > push @result, $r; > } > } >- return \@result if $syspref_to_read eq 'MarcItemFieldsToOrder'; >+ return \@result if $syspref_to_read eq 'MarcItemFieldsToOrder'; > return $result[0] if $syspref_to_read eq 'MarcFieldsToOrder'; > } > >@@ -370,7 +368,7 @@ sub add_items_from_import_record { > } > ); > >- my $order_line_details = create_items_and_generate_order_hash( >+ my $itemnumbers = create_items_and_generate_order_hash( > { > fields => $order_line_fields, > vendor => $vendor, >@@ -379,7 +377,7 @@ sub add_items_from_import_record { > } > ); > >- return $order_line_details; >+ return $itemnumbers; > } > > if ( $agent eq 'client' ) { >@@ -407,35 +405,6 @@ sub add_items_from_import_record { > } > } > >-=head3 create_order_lines >- >- my $order_lines = create_order_lines({ >- order_line_details => $order_line_details >- }); >- >- Creates order lines based on an array of order line details >- >-=cut >- >-sub create_order_lines { >- my ($args) = @_; >- >- my $order_line_details = $args->{order_line_details}; >- >- foreach my $order_detail ( @{$order_line_details} ) { >- my @itemnumbers = $order_detail->{itemnumbers} || (); >- delete( $order_detail->{itemnumbers} ); >- my $order = Koha::Acquisition::Order->new( \%{$order_detail} ); >- $order->populate_with_prices_for_ordering(); >- $order->populate_with_prices_for_receiving(); >- $order->store; >- foreach my $itemnumber (@itemnumbers) { >- $order->add_item($itemnumber); >- } >- } >- return; >-} >- > =head3 import_batches_list > > Fetches import batches matching the batch to be added to the basket and returns these to the template >@@ -563,13 +532,13 @@ sub import_biblios_list { > > my $infos = _get_syspref_mappings( $marcrecord, 'MarcFieldsToOrder' ); > >- my $price = $infos->{price} || undef; >+ my $price = $infos->{price} || undef; > my $replacementprice = $infos->{replacementprice} || undef; >- my $quantity = $infos->{quantity} || undef; >- my $budget_code = $infos->{budget_code} || undef; >- my $discount = $infos->{discount} || undef; >- my $sort1 = $infos->{sort1} || undef; >- my $sort2 = $infos->{sort2} || undef; >+ my $quantity = $infos->{quantity} || undef; >+ my $budget_code = $infos->{budget_code} || undef; >+ my $discount = $infos->{discount} || undef; >+ my $sort1 = $infos->{sort1} || undef; >+ my $sort2 = $infos->{sort2} || undef; > my $budget_id; > > if ($budget_code) { >@@ -582,10 +551,11 @@ sub import_biblios_list { > # Items > my @itemlist = (); > my $all_items_quantity = 0; >- my $alliteminfos = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' ); >+ my $alliteminfos = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' ); > > if ( $alliteminfos != -1 ) { > foreach my $iteminfos (@$alliteminfos) { >+ > # Quantity is required, default to one if not supplied > my $quantity = delete $iteminfos->{quantity} || 1; > >@@ -787,7 +757,7 @@ sub parse_input_into_order_line_fields { > marcrecord => $marcrecord, > }; > >- if($client) { >+ if ($client) { > $order_line_fields->{tags} = $fields->{tags}; > $order_line_fields->{subfields} = $fields->{subfields}; > $order_line_fields->{field_values} = $fields->{field_values}; >@@ -825,8 +795,7 @@ sub create_items_and_generate_order_hash { > my $budget_id = $fields->{budget_id}; > my $vendor = $args->{vendor}; > my $active_currency = $args->{active_currency}; >- my @order_line_details; >- my $itemcreation = 0; >+ my $itemcreation = 0; > my @itemnumbers; > > for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { >@@ -856,11 +825,12 @@ sub create_items_and_generate_order_hash { > } > > if ( $itemcreation == 1 ) { >+ > # Group orderlines from MarcItemFieldsToOrder > my $budget_hash; > my @budget_ids = @{ $fields->{budget_code} }; > for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { >- $budget_ids[$i] = $budget_id if !$budget_ids[$i]; # Use default budget if no budget provided >+ $budget_ids[$i] = $budget_id if !$budget_ids[$i]; # Use default budget if no budget provided > $budget_hash->{ $budget_ids[$i] }->{quantity} += 1; > $budget_hash->{ $budget_ids[$i] }->{price} = @{ $fields->{price} }[$i]; > $budget_hash->{ $budget_ids[$i] }->{replacementprice} = >@@ -911,6 +881,7 @@ sub create_items_and_generate_order_hash { > } > } > } else { >+ > # Add an orderline for each MARC record > # Get quantity in the MARC record (1 if none) > my $quantity = GetMarcQuantity( $fields->{marcrecord}, C4::Context->preference('marcflavour') ) || 1; >@@ -930,8 +901,8 @@ sub create_items_and_generate_order_hash { > ); > > # Get the price if there is one. >- if ($fields->{c_price}) { >- $fields->{c_price} = _format_price_to_CurrencyFormat_syspref($fields->{c_price}); >+ if ( $fields->{c_price} ) { >+ $fields->{c_price} = _format_price_to_CurrencyFormat_syspref( $fields->{c_price} ); > $fields->{c_price} = Koha::Number::Price->new( $fields->{c_price} )->unformat; > $orderinfo{tax_rate_on_ordering} = $vendor->tax_rate; > $orderinfo{tax_rate_on_receiving} = $vendor->tax_rate; >@@ -954,7 +925,7 @@ sub create_items_and_generate_order_hash { > $order->populate_with_prices_for_receiving(); > $order->store; > >- my $basket = Koha::Acquisition::Baskets->find( $basket_id ); >+ my $basket = Koha::Acquisition::Baskets->find($basket_id); > if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { > my @tags = @{ $fields->{tags} }; > my @subfields = @{ $fields->{subfields} }; >@@ -963,13 +934,14 @@ sub create_items_and_generate_order_hash { > my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values ); > my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); > for ( my $qtyloop = 1 ; $qtyloop <= $fields->{c_quantity} ; $qtyloop++ ) { >- my ( $biblionumber, undef, $itemnumber ) = AddItemFromMarc( $fields->{marcrecord}, $fields->{biblionumber} ); >+ my ( $biblionumber, undef, $itemnumber ) = >+ AddItemFromMarc( $fields->{marcrecord}, $fields->{biblionumber} ); > $order->add_item($itemnumber); > } > } > } > >- return \@order_line_details; >+ return \@itemnumbers; > } > > =head3 _format_price_to_CurrencyFormat_syspref >diff --git a/t/db_dependent/Koha/MarcOrder.t b/t/db_dependent/Koha/MarcOrder.t >index a69a501ce8e..91b95b2486d 100755 >--- a/t/db_dependent/Koha/MarcOrder.t >+++ b/t/db_dependent/Koha/MarcOrder.t >@@ -32,7 +32,7 @@ use t::lib::TestBuilder; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >-subtest '_get_MarcItemFieldsToOrder_syspref_data()' => sub { >+subtest '_get_syspref_mappings() MarcItemFieldsToOrder' => sub { > plan tests => 14; > > $schema->storage->txn_begin; >@@ -66,8 +66,8 @@ replacementprice: 975$v' > ); > > my $marc_item_fields_to_order = @{ >- Koha::MarcOrder::_get_MarcItemFieldsToOrder_syspref_data( >- $record, >+ Koha::MarcOrder::_get_syspref_mappings( >+ $record, 'MarcItemFieldsToOrder', > ) > }[0]; > >@@ -131,7 +131,7 @@ replacementprice: 975$v' > $schema->storage->txn_rollback; > }; > >-subtest '_get_MarcFieldsToOrder_syspref_data()' => sub { >+subtest '_get_syspref_mappings() MarcFieldsToOrder' => sub { > plan tests => 3; > > $schema->storage->txn_begin; >@@ -149,9 +149,8 @@ budget_code: 975$h' > [ '975', ' ', ' ', p => 10, q => 1, h => 1 ], > ); > >- my $marc_fields_to_order = Koha::MarcOrder::_get_MarcFieldsToOrder_syspref_data( >- 'MarcFieldsToOrder', $record, >- [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2' ] >+ my $marc_fields_to_order = Koha::MarcOrder::_get_syspref_mappings( >+ $record, 'MarcFieldsToOrder', > ); > > is( >@@ -381,10 +380,13 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { > 'itypes' => [ > 'BK', > 'BK' >- ] >+ ], >+ 'coded_location_qualifiers' => [], >+ 'barcodes' => [], >+ 'enumchrons' => [] > }; > >- my $order_line_details = Koha::MarcOrder::add_items_from_import_record( >+ my $itemnumbers = Koha::MarcOrder::add_items_from_import_record( > { > record_result => $result->{record_result}, > basket_id => 1, >@@ -395,25 +397,26 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { > } > ); > >+ my $orders = Koha::Acquisition::Orders->search()->unblessed; >+ > is( >- @{$order_line_details}[0]->{rrp}, '10.00', >+ @{$orders}[0]->{rrp} + 0, '10', > "Price has been read correctly" > ); > is( >- @{$order_line_details}[0]->{listprice}, '10', >+ @{$orders}[0]->{listprice} + 0, '10', > "Listprice has been created successfully" > ); > is( >- @{$order_line_details}[0]->{quantity}, 1, >+ @{$orders}[0]->{quantity}, 2, > "Quantity has been read correctly" > ); > is( >- @{$order_line_details}[0]->{budget_id}, $budgetid, >+ @{$orders}[0]->{budget_id}, $budgetid, > "Budget code has been read correctly" > ); > >- my @created_items = @{$order_line_details}[0]->{itemnumbers}; >- my $new_item = Koha::Items->find( $created_items[0] ); >+ my $new_item = Koha::Items->find( ${$itemnumbers}[0] ); > > isnt( > $new_item, undef, >-- >2.39.3 (Apple Git-146)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35026
:
157050
|
157051
|
157052
|
157056
|
157057
|
157058
|
159305
|
159306
|
159969
|
159970
|
159971
|
159972
|
159973
|
160833
|
160834
|
160835
|
160836
|
160837
|
160838
|
162647
|
162648
|
162649
|
162650
|
162651
|
162652
|
162653
|
162654
|
163787
|
163788
|
163789
|
163790
|
163791
|
163792
|
163793
|
163794
|
163819
|
163820
|
163835
|
163836
|
163838
|
163839
|
163840
|
163841
|
163842
|
163843
|
163844
|
163845
|
164695
|
164937
|
165378
|
165681
|
168123
|
168124
|
168125
|
168126
|
168127
|
168128
|
168129
|
168130
|
168131
|
168132
|
168971
|
168972
|
168973
|
168974
|
168975
|
168976
|
168977
|
168978
|
168979
|
168980
|
168981
|
169475
|
169476
|
169477
|
169478
|
169479
|
169480
|
169481
|
169482
|
169483
|
169484
|
169485
|
170504