Bug 40387: Fix undefined tax rate warnings in EDI invoice processing

When processing EDI invoices without TAX segments, warnings were
generated due to undefined tax rates in multiplication operations.

The tax_rate() method in Koha::Edifact::Line correctly returns undef
when no TAX segments are present in the EDI message. However, the
invoice processing code in Koha::EDI didn't handle this case properly.

This patch fixes the issue by:
- Adding checks for undefined tax rates before using them in calculations
- Defaulting to 0 tax rate when no tax information is present
- Ensuring tax_value calculations use 0 instead of undefined values

This eliminates "Use of uninitialized value in multiplication" warnings
while maintaining correct processing of invoices without tax information.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 68aa216317)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Martin Renvoize 2025-07-18 13:55:42 +01:00 committed by Paul Derscheid
parent 3f5a42a7d0
commit ece12b3373
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 7 additions and 4 deletions

View File

@ -414,8 +414,10 @@ sub process_invoice {
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},
tax_rate_on_receiving => $tax_rate ? $tax_rate->{rate} : 0,
tax_value_on_receiving => $quantity *
$price_excl_tax *
( $tax_rate ? $tax_rate->{rate} : 0 ),
}
);
transfer_items( $schema, $line, $order, $received_order, $quantity );
@ -430,8 +432,9 @@ sub process_invoice {
$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->tax_rate_on_receiving( $tax_rate ? $tax_rate->{rate} : 0 );
$order->tax_value_on_receiving(
$quantity * $price_excl_tax * ( $tax_rate ? $tax_rate->{rate} : 0 ) );
$order->orderstatus('complete');
$order->update;
receipt_items( $schema, $line, $ordernumber, $quantity, $invoice_message );