From 3e6b6ec2f082de7c1989a92b915d52bafad06e2b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 13 Jan 2015 17:03:04 +0100 Subject: [PATCH] Bug 13321: Fix unitprice rounding We need to display the rounded value, but insert the exact value. The unit price can be change on receiving, so the input value can be modified. But if it's not, we must insert the exact (not rounded) unit price, which is the ecost value. --- C4/Acquisition.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 2e1c761..e7769b3 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2875,6 +2875,12 @@ sub populate_order_with_prices { if ($receiving) { if ( $bookseller->{invoiceincgst} ) { + # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value + # we need to keep the exact ecost value + if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) { + $order->{unitprice} = $order->{ecost_tax_included}; + } + # The user entered the unit price tax included $order->{unitprice_tax_included} = $order->{unitprice}; @@ -2882,6 +2888,12 @@ sub populate_order_with_prices { $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ); } else { + # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value + # we need to keep the exact ecost value + if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_excluded} )->round ) { + $order->{unitprice} = $order->{ecost_tax_excluded}; + } + # The user entered the unit price tax excluded $order->{unitprice_tax_excluded} = $order->{unitprice}; -- 2.1.0