@@ -, +, @@ --- Koha/EDI.pm | 20 ++++++++++---------- Koha/Edifact/Line.pm | 16 ++++++++++++++-- t/EdiInvoice.t | 4 +++- t/Edifact.t | 5 +++-- 4 files changed, 30 insertions(+), 15 deletions(-) --- a/Koha/EDI.pm +++ a/Koha/EDI.pm @@ -264,7 +264,7 @@ sub process_invoice { foreach my $line ( @{$lines} ) { my $ordernumber = $line->ordernumber; $logger->trace( "Receipting order:$ordernumber Qty: ", - $line->quantity ); + $line->quantity_invoiced ); my $order = $schema->resultset('Aqorder')->find($ordernumber); @@ -288,18 +288,18 @@ sub process_invoice { my $price = _get_invoiced_price($line); - if ( $order->quantity > $line->quantity ) { + if ( $order->quantity > $line->quantity_invoiced ) { my $ordered = $order->quantity; # part receipt $order->orderstatus('partial'); - $order->quantity( $ordered - $line->quantity ); + $order->quantity( $ordered - $line->quantity_invoiced ); $order->update; my $received_order = $order->copy( { ordernumber => undef, - quantity => $line->quantity, - quantityreceived => $line->quantity, + quantity => $line->quantity_invoiced, + quantityreceived => $line->quantity_invoiced, orderstatus => 'complete', unitprice => $price, invoiceid => $invoiceid, @@ -312,7 +312,7 @@ sub process_invoice { $received_order->ordernumber ); } else { # simple receipt all copies on order - $order->quantityreceived( $line->quantity ); + $order->quantityreceived( $line->quantity_invoiced ); $order->datereceived($msg_date); $order->invoiceid($invoiceid); $order->unitprice($price); @@ -343,8 +343,8 @@ sub _get_invoiced_price { my $price = $line->price_net; if ( !defined $price ) { # no net price so generate it from lineitem amount $price = $line->amt_lineitem; - if ( $price and $line->quantity > 1 ) { - $price /= $line->quantity; # div line cost by qty + if ( $price and $line->quantity_invoiced > 1 ) { + $price /= $line->quantity_invoiced; # div line cost by qty } } return $price; @@ -353,7 +353,7 @@ sub _get_invoiced_price { sub receipt_items { my ( $schema, $inv_line, $ordernumber ) = @_; my $logger = Log::Log4perl->get_logger(); - my $quantity = $inv_line->quantity; + my $quantity = $inv_line->quantity_invoiced; # itemnumber is not a foreign key ??? makes this a bit cumbersome my @item_links = $schema->resultset('AqordersItem')->search( @@ -413,7 +413,7 @@ sub transfer_items { my ( $schema, $inv_line, $order_from, $order_to ) = @_; # Transfer x items from the orig order to a completed partial order - my $quantity = $inv_line->quantity; + my $quantity = $inv_line->quantity_invoiced; my $gocc = 0; my %mapped_by_branch; while ( $gocc < $quantity ) { --- a/Koha/Edifact/Line.pm +++ a/Koha/Edifact/Line.pm @@ -64,7 +64,14 @@ sub _parse_lines { push @item_description, $s; } elsif ( $s->tag eq 'QTY' ) { - $d->{quantity} = $s->elem( 0, 1 ); + if ( $s->elem( 0, 0 ) eq '47' ) { + $d->{quantity_invoiced} = $s->elem( 0, 1 ); + } + elsif ( $s->elem( 0, 0 ) eq '1' ) + { # In quotes used for copies quoted + # Used elsewhere as well (e.g. credit notes ) + $d->{discrete_quantity} = $s->elem( 0, 1 ); + } } elsif ( $s->tag eq 'DTM' ) { if ( $s->elem( 0, 0 ) eq '44' ) { @@ -374,9 +381,14 @@ sub monetary_amount { return $self->{monetary_amount}; } +sub quantity_invoiced { + my $self = shift; + return $self->{quantity_invoiced}; +} + sub quantity { my $self = shift; - return $self->{quantity}; + return $self->{discrete_quantity}; } sub price { --- a/t/EdiInvoice.t +++ a/t/EdiInvoice.t @@ -3,7 +3,7 @@ use strict; use warnings; use FindBin qw( $Bin ); -use Test::More tests => 19; +use Test::More tests => 20; BEGIN { use_ok('Koha::Edifact') } @@ -73,3 +73,5 @@ is( $lineprice, 4.55, 'correct net line price returned' ); my $tax = $lines->[7]->tax; is( $tax, 0, 'correct tax amount returned' ); + +is( $lines->[7]->quantity_invoiced, 1, 'line quantity invoiced returned' ); --- a/t/Edifact.t +++ a/t/Edifact.t @@ -3,7 +3,7 @@ use strict; use warnings; use FindBin qw( $Bin ); -use Test::More tests => 34; +use Test::More tests => 35; BEGIN { use_ok('Koha::Edifact') } @@ -50,7 +50,8 @@ my $test_line = $lin->[-1]; is( $test_line->line_item_number, 18, 'correct line number returned' ); is( $test_line->item_number_id, '9780273761006', 'correct ean returned' ); -is( $test_line->quantity, 1, 'quantity returned' ); +is( $test_line->quantity_invoiced, undef, 'quantity invoiced not returned as expected' ); +is( $test_line->quantity, 1, 'discrete quantity returned' ); my $test_title = 'International business [electronic resource]'; my $marcrec = $test_line->marc_record; --