View | Details | Raw Unified | Return to bug 26584
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-23 / +1 lines)
Lines 53-59 BEGIN { Link Here
53
    require Exporter;
53
    require Exporter;
54
    @ISA    = qw(Exporter);
54
    @ISA    = qw(Exporter);
55
    @EXPORT = qw(
55
    @EXPORT = qw(
56
        &GetBasket &NewBasket &CloseBasket &ReopenBasket &ModBasket
56
        &GetBasket &NewBasket &ReopenBasket &ModBasket
57
        &GetBasketAsCSV &GetBasketGroupAsCSV
57
        &GetBasketAsCSV &GetBasketGroupAsCSV
58
        &GetBasketsByBookseller &GetBasketsByBasketgroup
58
        &GetBasketsByBookseller &GetBasketsByBasketgroup
59
        &GetBasketsInfosByBookseller
59
        &GetBasketsInfosByBookseller
Lines 206-233 sub NewBasket { Link Here
206
    return $basket;
206
    return $basket;
207
}
207
}
208
208
209
#------------------------------------------------------------#
210
211
=head3 CloseBasket
212
213
  &CloseBasket($basketno);
214
215
close a basket (becomes unmodifiable, except for receives)
216
217
=cut
218
219
sub CloseBasket {
220
    my ($basketno) = @_;
221
    my $dbh        = C4::Context->dbh;
222
    $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno );
223
224
    $dbh->do(
225
q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus NOT IN ( 'complete', 'cancelled')},
226
        {}, $basketno
227
    );
228
    return;
229
}
230
231
=head3 ReopenBasket
209
=head3 ReopenBasket
232
210
233
  &ReopenBasket($basketno);
211
  &ReopenBasket($basketno);
(-)a/Koha/EDI.pm (-2 / +2 lines)
Lines 28-34 use DateTime; Link Here
28
use C4::Context;
28
use C4::Context;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::DateUtils;
30
use Koha::DateUtils;
31
use C4::Acquisition qw( NewBasket CloseBasket ModOrder);
31
use C4::Acquisition qw( NewBasket ModOrder);
32
use C4::Suggestions qw( ModSuggestion );
32
use C4::Suggestions qw( ModSuggestion );
33
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
33
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
34
use Koha::Edifact::Order;
34
use Koha::Edifact::Order;
Lines 592-598 sub process_quote { Link Here
592
                    basketno => $b,
592
                    basketno => $b,
593
                }
593
                }
594
            );
594
            );
595
            CloseBasket($b);
595
            Koha::Acquisition::Baskets->find($b)->close;
596
        }
596
        }
597
    }
597
    }
598
598
(-)a/acqui/basket.pl (-14 / +17 lines)
Lines 191-199 if ( $op eq 'delete_confirm' ) { Link Here
191
} elsif ($op eq 'close') {
191
} elsif ($op eq 'close') {
192
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
192
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
193
    if ($confirm) {
193
    if ($confirm) {
194
        my $basketno = $query->param('basketno');
194
195
        my $booksellerid = $query->param('booksellerid');
195
        # close the basket
196
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
196
        # FIXME: we should fetch the object at the beginning of this script
197
        #        and get rid of the hash that is passed around
198
        Koha::Acquisition::Baskets->find($basketno)->close;
199
197
        # if requested, create basket group, close it and attach the basket
200
        # if requested, create basket group, close it and attach the basket
198
        if ($query->param('createbasketgroup')) {
201
        if ($query->param('createbasketgroup')) {
199
            my $branchcode;
202
            my $branchcode;
Lines 524-540 sub get_order_infos { Link Here
524
sub edi_close_and_order {
527
sub edi_close_and_order {
525
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
528
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
526
    if ($confirm) {
529
    if ($confirm) {
527
            my $edi_params = {
530
        my $edi_params = {
528
                basketno => $basketno,
531
            basketno => $basketno,
529
                ean    => $ean,
532
            ean    => $ean,
530
            };
533
        };
531
            if ( $basket->{branch} ) {
534
        if ( $basket->{branch} ) {
532
                $edi_params->{branchcode} = $basket->{branch};
535
            $edi_params->{branchcode} = $basket->{branch};
533
            }
536
        }
534
            if ( create_edi_order($edi_params) ) {
537
        if ( create_edi_order($edi_params) ) {
535
                #$template->param( edifile => 1 );
538
            #$template->param( edifile => 1 );
536
            }
539
        }
537
        CloseBasket($basketno);
540
        Koha::Acquisition::Baskets->find($basketno)->close;
538
541
539
        # if requested, create basket group, close it and attach the basket
542
        # if requested, create basket group, close it and attach the basket
540
        if ( $query->param('createbasketgroup') ) {
543
        if ( $query->param('createbasketgroup') ) {
(-)a/t/db_dependent/Acquisition.t (-1 / +1 lines)
Lines 394-400 ok( GetBudgetByOrderNumber( $ordernumbers[0] )->{'budget_id'} eq $budgetid, Link Here
394
my $lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
394
my $lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
395
is( $lateorders->search({ 'me.basketno' => $basketno })->count,
395
is( $lateorders->search({ 'me.basketno' => $basketno })->count,
396
    0, "GetLateOrders does not get orders from opened baskets" );
396
    0, "GetLateOrders does not get orders from opened baskets" );
397
C4::Acquisition::CloseBasket($basketno);
397
Koha::Acquisition::Baskets->find($basketno)->close;
398
$lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
398
$lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
399
isnt( $lateorders->search({ 'me.basketno' => $basketno })->count,
399
isnt( $lateorders->search({ 'me.basketno' => $basketno })->count,
400
    0, "GetLateOrders gets orders from closed baskets" );
400
    0, "GetLateOrders gets orders from closed baskets" );
(-)a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t (-2 / +2 lines)
Lines 103-109 is( $basket->{total_items_cancelled}, 6, 'Both orders deleted, 6 items cancelled Link Here
103
is( $basket->{expected_items}, 0, 'Both orders delete, now 0 items are expected' );
103
is( $basket->{expected_items}, 0, 'Both orders delete, now 0 items are expected' );
104
is( $basket->{total_biblios_cancelled}, 2, 'Both orders deleted, 2 biblios cancelled' );
104
is( $basket->{total_biblios_cancelled}, 2, 'Both orders deleted, 2 biblios cancelled' );
105
105
106
C4::Acquisition::CloseBasket( $basketno );
106
Koha::Acquisition::Baskets->find( $basketno )->close;
107
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
107
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
108
is( scalar(@$baskets), 0, 'Basket is closed, 0 basket opened' );
108
is( scalar(@$baskets), 0, 'Basket is closed, 0 basket opened' );
109
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid, 1 );
109
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid, 1 );
Lines 120-126 my $order3 = Koha::Acquisition::Order->new( Link Here
120
)->store;
120
)->store;
121
my $ordernumber3 = $order3->ordernumber;
121
my $ordernumber3 = $order3->ordernumber;
122
122
123
C4::Acquisition::CloseBasket( $basketno );
123
Koha::Acquisition::Baskets->find( $basketno )->close;
124
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
124
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
125
is( scalar(@$baskets), 1, 'Basket is closed and has items to receive' );
125
is( scalar(@$baskets), 1, 'Basket is closed and has items to receive' );
126
$basket = $baskets->[0];
126
$basket = $baskets->[0];
(-)a/t/db_dependent/Acquisition/close_reopen_basket.t (-3 / +3 lines)
Lines 72-78 my @orders = C4::Acquisition::GetOrders( $basketno ); Link Here
72
is( scalar(@orders), 2, "2 orders are created" );
72
is( scalar(@orders), 2, "2 orders are created" );
73
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new before closing the basket" );
73
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new before closing the basket" );
74
74
75
C4::Acquisition::CloseBasket( $basketno );
75
Koha::Acquisition::Baskets->find( $basketno )->close;
76
@orders = C4::Acquisition::GetOrders( $basketno );
76
@orders = C4::Acquisition::GetOrders( $basketno );
77
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
77
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
78
78
Lines 86-95 my ( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} ); Link Here
86
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
86
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
87
is( $order->{orderstatus}, 'cancelled', 'cancelling the order should have set status to cancelled' );
87
is( $order->{orderstatus}, 'cancelled', 'cancelling the order should have set status to cancelled' );
88
88
89
C4::Acquisition::CloseBasket( $basketno );
89
Koha::Acquisition::Baskets->find( $basketno )->close;
90
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
90
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
91
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
91
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
92
is( $order->{orderstatus}, 'cancelled', 'CloseBasket should not reset the status to ordered for cancelled orders' );
92
is( $order->{orderstatus}, 'cancelled', '$basket->close should not reset the status to ordered for cancelled orders' );
93
93
94
C4::Acquisition::ReopenBasket( $basketno );
94
C4::Acquisition::ReopenBasket( $basketno );
95
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
95
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
(-)a/t/db_dependent/Letters.t (-2 / +1 lines)
Lines 436-442 my $order = Koha::Acquisition::Order->new( Link Here
436
)->store;
436
)->store;
437
my $ordernumber = $order->ordernumber;
437
my $ordernumber = $order->ordernumber;
438
438
439
C4::Acquisition::CloseBasket( $basketno );
439
Koha::Acquisition::Baskets->find( $basketno )->close;
440
my $err;
440
my $err;
441
warning_like {
441
warning_like {
442
    $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }
442
    $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }
443
- 

Return to bug 26584