Merge branch 'bug_7593' into 3.14-master

This commit is contained in:
Jared Camins-Esakov 2013-05-12 10:30:57 -04:00
commit 7ad69f58e8
3 changed files with 66 additions and 2 deletions

View file

@ -53,7 +53,7 @@ BEGIN {
&ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
&GetBasketgroups &ReOpenBasketgroup
&NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders
&NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders &GetOrdersByBiblionumber
&GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
&SearchOrder &GetHistory &GetRecentAcqui
&ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber
@ -949,6 +949,41 @@ sub GetOrders {
return @$results;
}
#------------------------------------------------------------#
=head3 GetOrdersByBiblionumber
@orders = &GetOrdersByBiblionumber($biblionumber);
Looks up the orders with linked to a specific $biblionumber, including
cancelled orders and received orders.
return :
C<@orders> is an array of references-to-hash, whose keys are the
fields from the aqorders, biblio, and biblioitems tables in the Koha database.
=cut
sub GetOrdersByBiblionumber {
my $biblionumber = shift;
return unless $biblionumber;
my $dbh = C4::Context->dbh;
my $query ="
SELECT biblio.*,biblioitems.*,
aqorders.*,
aqbudgets.*
FROM aqorders
LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber
WHERE aqorders.biblionumber=?
";
my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
my $results = $sth->fetchall_arrayref({});
$sth->finish;
return @$results;
}
#------------------------------------------------------------#
=head3 GetOrderNumber

View file

@ -29,6 +29,7 @@ use C4::Biblio;
use C4::Serials;
use C4::Koha;
use C4::Reserves qw/MergeHolds/;
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
my $input = new CGI;
my @biblionumber = $input->param('biblionumber');
@ -69,6 +70,7 @@ if ($merge) {
ModBiblio($record, $tobiblio, $frameworkcode);
# Moving items from the other record to the reference record
# Also moving orders from the other record to the reference record, only if the order is linked to an item of the other record
my $itemnumbers = get_itemnumbers_of($frombiblio);
foreach my $itloop ($itemnumbers->{$frombiblio}) {
foreach my $itemnumber (@$itloop) {
@ -101,6 +103,16 @@ if ($merge) {
# TODO : Moving reserves
# Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
my @allorders = GetOrdersByBiblionumber($frombiblio);
my @tobiblioitem = GetBiblioItemByBiblioNumber ($tobiblio);
my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber };
foreach my $myorder (@allorders) {
$myorder->{'biblionumber'} = $tobiblio;
ModOrder ($myorder);
# TODO : add error control (in ModOrder?)
}
# Deleting the other record
if (scalar(@errors) == 0) {
# Move holds

View file

@ -10,7 +10,7 @@ use POSIX qw(strftime);
use C4::Bookseller qw( GetBookSellerFromId );
use Test::More tests => 37;
use Test::More tests => 42;
BEGIN {
use_ok('C4::Acquisition');
@ -32,6 +32,23 @@ my $grouped = 0;
my $orders = GetPendingOrders( $supplierid, $grouped );
isa_ok( $orders, 'ARRAY' );
# testing GetOrdersByBiblionumber
# result should be undef if no params
my @ordersbybiblionumber = GetOrdersByBiblionumber();
is(@ordersbybiblionumber,0,'GetOrdersByBiblionumber : no argument, return undef');
# TODO : create 2 orders using the same biblionumber, and check the result of GetOrdersByBiblionumber
# if a record is used in at least one order, result should be an array with at least one element
SKIP: {
skip 'No Orders, cannot test GetOrdersByBiblionumber', 3 unless( scalar @$orders );
my $testorder = @$orders[0];
my $testbiblio = $testorder->{'biblionumber'};
my @listorders = GetOrdersByBiblionumber($testbiblio);
isa_ok( ref @listorders, 'ARRAY','GetOrdersByBiblionumber : result is an array' );
ok( scalar (@listorders) >0,'GetOrdersByBiblionumber : result contains at least one element' );
my @matched_biblios = grep {$_->{biblionumber} == $testbiblio} @listorders;
ok ( @matched_biblios == @listorders, "all orders match");
}
my @lateorders = GetLateOrders(0);
SKIP: {
skip 'No Late Orders, cannot test AddClaim', 1 unless @lateorders;