Bugzilla – Attachment 174408 Details for
Bug 38423
EDIFACT invoice files should skip orders that cannot be receipted rather than failing to complete
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38423: Code more defensively in process_invoice
Bug-38423-Code-more-defensively-in-processinvoice.patch (text/plain), 9.72 KB, created by
Martin Renvoize (ashimema)
on 2024-11-12 12:57:50 UTC
(
hide
)
Description:
Bug 38423: Code more defensively in process_invoice
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-11-12 12:57:50 UTC
Size:
9.72 KB
patch
obsolete
>From 1ef082ac00f7e181c4cfeaea4738332dc60951d1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 12 Nov 2024 12:42:32 +0000 >Subject: [PATCH] Bug 38423: Code more defensively in process_invoice > >We re-arrange the logic of process_invoice a little here to ensure we >skip order lines in invoices that do not have corresponding bib records. >--- > Koha/EDI.pm | 163 ++++++++++++++++++++++++++-------------------------- > 1 file changed, 81 insertions(+), 82 deletions(-) > >diff --git a/Koha/EDI.pm b/Koha/EDI.pm >index 7b0eeb3657d..91f687e7b0b 100644 >--- a/Koha/EDI.pm >+++ b/Koha/EDI.pm >@@ -290,8 +290,7 @@ sub process_invoice { > )->single; > } > if ( !$vendor_acct ) { >- carp >-"Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in $invoice_message->filename"; >+ carp "Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in $invoice_message->filename"; > next; > } > $invoice_message->edi_acct( $vendor_acct->id ); >@@ -313,100 +312,100 @@ sub process_invoice { > > foreach my $line ( @{$lines} ) { > my $ordernumber = $line->ordernumber; >- if (!$ordernumber ) { >- $logger->trace( "Skipping invoice line, no associated ordernumber" ); >- next; >+ if ( !$ordernumber ) { >+ $logger->error("Skipping invoice line, no associated ordernumber"); >+ next; > } > >- $logger->trace( "Receipting order:$ordernumber Qty: ", >- $line->quantity ); >- >+ # ModReceiveOrder does not validate that $ordernumber exists validate here > my $order = $schema->resultset('Aqorder')->find($ordernumber); >- if (my $bib = $order->biblionumber) { >- my $b = $bib->biblionumber; >- my $id = $line->item_number_id; >- $logger->trace("Updating bib:$b id:$id"); >+ if ( !$order ) { >+ $logger->error("Skipping invoice line, no order found for $ordernumber, invoice:$invoicenumber"); >+ next; > } > >- # ModReceiveOrder does not validate that $ordernumber exists validate here >- if ($order) { >+ my $bib = $order->biblionumber; >+ if ( !$bib ) { >+ $logger->error( >+ "Skipping invoice line, no bibliographic record found for $ordernumber, invoice:$invoicenumber" >+ ); >+ next; >+ } >+ >+ $logger->trace( "Receipting order:$ordernumber Qty: " . $line->quantity ); >+ $logger->trace( "Updating bib:" . $bib->biblionumber . " id:" . $line->item_number_id ); > >- # check suggestions >- my $s = $schema->resultset('Suggestion')->search( >+ # check suggestions >+ my $s = $schema->resultset('Suggestion')->search( >+ { >+ biblionumber => $bib->biblionumber, >+ } >+ )->single; >+ if ($s) { >+ ModSuggestion( > { >- biblionumber => $order->biblionumber->biblionumber, >+ suggestionid => $s->suggestionid, >+ STATUS => 'AVAILABLE', > } >- )->single; >- if ($s) { >- ModSuggestion( >- { >- suggestionid => $s->suggestionid, >- STATUS => 'AVAILABLE', >- } >- ); >- } >- # If quantity_invoiced is present use it in preference >- my $quantity = $line->quantity_invoiced; >- if (!$quantity) { >- $quantity = $line->quantity; >- } >+ ); >+ } > >- my ( $price, $price_excl_tax ) = _get_invoiced_price($line, $quantity); >- my $tax_rate = $line->tax_rate; >- if ($tax_rate && $tax_rate->{rate} != 0) { >- $tax_rate->{rate} /= 100; >- } >+ # If quantity_invoiced is present use it in preference >+ my $quantity = $line->quantity_invoiced; >+ if ( !$quantity ) { >+ $quantity = $line->quantity; >+ } > >- if ( $order->quantity > $quantity ) { >- my $ordered = $order->quantity; >- >- # part receipt >- $order->orderstatus('partial'); >- $order->quantity( $ordered - $quantity ); >- $order->update; >- my $received_order = $order->copy( >- { >- ordernumber => undef, >- quantity => $quantity, >- quantityreceived => $quantity, >- orderstatus => 'complete', >- unitprice => $price, >- unitprice_tax_included => $price, >- unitprice_tax_excluded => $price_excl_tax, >- invoiceid => $invoiceid, >- datereceived => $msg_date, >- tax_rate_on_receiving => $tax_rate->{rate}, >- tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, >- } >- ); >- transfer_items( $schema, $line, $order, >- $received_order, $quantity ); >- receipt_items( $schema, $line, >- $received_order->ordernumber, $quantity ); >- } >- else { # simple receipt all copies on order >- $order->quantityreceived( $quantity ); >- $order->datereceived($msg_date); >- $order->invoiceid($invoiceid); >- $order->unitprice($price); >- $order->unitprice_tax_excluded($price_excl_tax); >- $order->unitprice_tax_included($price); >- $order->tax_rate_on_receiving($tax_rate->{rate}); >- $order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate}); >- $order->orderstatus('complete'); >- $order->update; >- receipt_items( $schema, $line, $ordernumber, $quantity ); >- } >+ my ( $price, $price_excl_tax ) = _get_invoiced_price( $line, $quantity ); >+ my $tax_rate = $line->tax_rate; >+ if ( $tax_rate && $tax_rate->{rate} != 0 ) { >+ $tax_rate->{rate} /= 100; > } >- else { >- $logger->error( >- "No order found for $ordernumber Invoice:$invoicenumber" >+ >+ if ( $order->quantity > $quantity ) { >+ my $ordered = $order->quantity; >+ >+ # part receipt >+ $order->orderstatus('partial'); >+ $order->quantity( $ordered - $quantity ); >+ $order->update; >+ my $received_order = $order->copy( >+ { >+ ordernumber => undef, >+ quantity => $quantity, >+ quantityreceived => $quantity, >+ orderstatus => 'complete', >+ unitprice => $price, >+ unitprice_tax_included => $price, >+ unitprice_tax_excluded => $price_excl_tax, >+ invoiceid => $invoiceid, >+ datereceived => $msg_date, >+ tax_rate_on_receiving => $tax_rate->{rate}, >+ tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, >+ } > ); >- next; >+ transfer_items( >+ $schema, $line, $order, >+ $received_order, $quantity >+ ); >+ receipt_items( >+ $schema, $line, >+ $received_order->ordernumber, $quantity >+ ); >+ } else { # simple receipt all copies on order >+ $order->quantityreceived($quantity); >+ $order->datereceived($msg_date); >+ $order->invoiceid($invoiceid); >+ $order->unitprice($price); >+ $order->unitprice_tax_excluded($price_excl_tax); >+ $order->unitprice_tax_included($price); >+ $order->tax_rate_on_receiving( $tax_rate->{rate} ); >+ $order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate} ); >+ $order->orderstatus('complete'); >+ $order->update; >+ receipt_items( $schema, $line, $ordernumber, $quantity ); > } >- > } >- > } > } > >-- >2.47.0
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 38423
:
174406
| 174408