From 878f645c5dd6433cb78402b0658cca75e1b4e561 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Jun 2018 13:12:25 -0300 Subject: [PATCH] Bug 20922: Remove use of Koha::Number::Price in updatedatabase.pl Koha::Number::Format->round use Number::Format->round with a precision=2 We should use it directly instead of Koha::* modules. It will avoid the DB entry to fail because schema changes. From the koha-devel list: http://lists.koha-community.org/pipermail/koha-devel/2018-June/044608.html 16.06.00.042 Upgrade to 16.06.00.041 done (Bug 14629 - Add aggressive ISSN matching feature equivalent to the aggressive ISBN matcher) DBD::mysql::st execute failed: Unknown column 'me.p_sep_by_space' in 'field list' [for Statement "SELECT `me`.`currency`, `me`.`symbol`, `me`.`isocode`, `me`.`timestamp`, `me`.`rate`, `me`.`active`, `me`.`archived`, `me`.`p_sep_by_space` FROM `currency` `me` WHERE ( `active` = ? )" with ParamValues: 0=1] at /usr/local/share/perl/5.24.1/DBIx/Class/Storage/DBI.pm line 1836. DBIx::Class::Storage::DBI::_dbh_execute(): Unknown column 'me.p_sep_by_space' in 'field list' at /inlibro/git/koha-csf-prod-inlibro/Koha/Objects.pm line 209 Basically, the update code uses Koha::Number::Price, which in full modern object mode goes for its newly added *p_sep_by_space* _in the 18.05 code_. But the DB doesn't have it yet (it comes with 17.12.00.022). Signed-off-by: Blou Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit 93de5885098b9982a3ab9ad73ff73111d71ac3ef) Signed-off-by: Fridolin Somers --- installer/data/mysql/updatedatabase.pl | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 30225abc22..fed02651c4 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -13519,53 +13519,55 @@ if ( CheckVersion($DBversion) ) { WHERE ordernumber = ? |); - require Koha::Number::Price; + require Number::Format; + my $format = Number::Format->new; + my $precision = 2; for my $order ( @$orders ) { $sth_get_bookseller->execute( $order->{ordernumber} ); my ( $bookseller ) = $sth_get_bookseller->fetchrow_hashref; - $order->{rrp} = Koha::Number::Price->new( $order->{rrp} )->round; - $order->{ecost} = Koha::Number::Price->new( $order->{ecost} )->round; + $order->{rrp} = $format->round( $order->{rrp}, $precision ); + $order->{ecost} = $format->round( $order->{ecost}, $precision ); $order->{tax_rate} ||= 0 ; # tax_rate can be NULL in DB # Ordering if ( $bookseller->{listincgst} ) { $order->{rrp_tax_included} = $order->{rrp}; - $order->{rrp_tax_excluded} = Koha::Number::Price->new( - $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ) )->round; + $order->{rrp_tax_excluded} = $format->round( + $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ), $precision ); $order->{ecost_tax_included} = $order->{ecost}; - $order->{ecost_tax_excluded} = Koha::Number::Price->new( - $order->{ecost} / ( 1 + $order->{tax_rate} ) )->round; + $order->{ecost_tax_excluded} = $format->round( + $order->{ecost} / ( 1 + $order->{tax_rate} ), $precision ); } else { $order->{rrp_tax_excluded} = $order->{rrp}; - $order->{rrp_tax_included} = Koha::Number::Price->new( - $order->{rrp} * ( 1 + $order->{tax_rate} ) )->round; + $order->{rrp_tax_included} = $format->round( + $order->{rrp} * ( 1 + $order->{tax_rate} ), $precision ); $order->{ecost_tax_excluded} = $order->{ecost}; - $order->{ecost_tax_included} = Koha::Number::Price->new( - $order->{ecost} * ( 1 + $order->{tax_rate} ) )->round; + $order->{ecost_tax_included} = $format->round( + $order->{ecost} * ( 1 + $order->{tax_rate} ), $precision ); } #receiving if ( $bookseller->{listincgst} ) { - $order->{unitprice_tax_included} = Koha::Number::Price->new( $order->{unitprice} )->round; - $order->{unitprice_tax_excluded} = Koha::Number::Price->new( - $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ) )->round; + $order->{unitprice_tax_included} = $format->round( $order->{unitprice}, $precision ); + $order->{unitprice_tax_excluded} = $format->round( + $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ), $precision ); } else { - $order->{unitprice_tax_excluded} = Koha::Number::Price->new( $order->{unitprice} )->round; - $order->{unitprice_tax_included} = Koha::Number::Price->new( - $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ) )->round; + $order->{unitprice_tax_excluded} = $format->round( $order->{unitprice}, $precision ); + $order->{unitprice_tax_included} = $format->round( + $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ), $precision ); } # If the order is received, the tax is calculated from the unit price if ( $order->{orderstatus} eq 'complete' ) { - $order->{tax_value} = Koha::Number::Price->new( + $order->{tax_value} = $format->round( ( $order->{unitprice_tax_included} - $order->{unitprice_tax_excluded} ) - * $order->{quantity} )->round; + * $order->{quantity}, $precision ); } else { # otherwise the ecost is used - $order->{tax_value} = Koha::Number::Price->new( + $order->{tax_value} = $format->round( ( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) * - $order->{quantity} )->round; + $order->{quantity}, $precision ); } $sth_update_order->execute( @@ -13608,7 +13610,6 @@ if ( CheckVersion($DBversion) ) { WHERE ordernumber = ? |); - require Koha::Number::Price; for my $order (@$orders) { my $tax_value_on_ordering = $order->{quantity} * -- 2.39.5