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

(-)a/C4/Acquisition.pm (-5 / +8 lines)
Lines 28-35 use C4::Contract; Link Here
28
use C4::Debug;
28
use C4::Debug;
29
use C4::Templates qw(gettemplate);
29
use C4::Templates qw(gettemplate);
30
use Koha::DateUtils qw( dt_from_string output_pref );
30
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::Acquisition::Order;
32
use Koha::Acquisition::Booksellers;
31
use Koha::Acquisition::Booksellers;
32
use Koha::Acquisition::Orders;
33
use Koha::Biblios;
33
use Koha::Biblios;
34
use Koha::Items;
34
use Koha::Items;
35
use Koha::Number::Price;
35
use Koha::Number::Price;
Lines 1485-1491 sub ModReceiveOrder { Link Here
1485
        $order->{datereceived} = $datereceived;
1485
        $order->{datereceived} = $datereceived;
1486
        $order->{invoiceid} = $invoice->{invoiceid};
1486
        $order->{invoiceid} = $invoice->{invoiceid};
1487
        $order->{orderstatus} = 'complete';
1487
        $order->{orderstatus} = 'complete';
1488
        $new_ordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber};
1488
        $new_ordernumber = Koha::Acquisition::Order->new($order)->store->ordernumber; # TODO What if the store fails?
1489
1489
1490
        if ($received_items) {
1490
        if ($received_items) {
1491
            foreach my $itemnumber (@$received_items) {
1491
            foreach my $itemnumber (@$received_items) {
Lines 1951-1958 sub TransferOrder { Link Here
1951
1951
1952
    return unless ($ordernumber and $basketno);
1952
    return unless ($ordernumber and $basketno);
1953
1953
1954
    my $order = GetOrder( $ordernumber );
1954
    my $order = Koha::Acquisition::Orders->find( $ordernumber ) or return;
1955
    return if $order->{datereceived};
1955
    return if $order->datereceived;
1956
1957
    $order = $order->unblessed;
1958
1956
    my $basket = GetBasket($basketno);
1959
    my $basket = GetBasket($basketno);
1957
    return unless $basket;
1960
    return unless $basket;
1958
1961
Lines 1971-1977 sub TransferOrder { Link Here
1971
    delete $order->{parent_ordernumber};
1974
    delete $order->{parent_ordernumber};
1972
    $order->{'basketno'} = $basketno;
1975
    $order->{'basketno'} = $basketno;
1973
1976
1974
    my $newordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber};
1977
    my $newordernumber = Koha::Acquisition::Order->new($order)->store->ordernumber;
1975
1978
1976
    $query = q{
1979
    $query = q{
1977
        UPDATE aqorders_items
1980
        UPDATE aqorders_items
(-)a/C4/Letters.pm (-1 / +1 lines)
Lines 1525-1531 sub _get_tt_params { Link Here
1525
            pk       => 'idnew',
1525
            pk       => 'idnew',
1526
        },
1526
        },
1527
        aqorders => {
1527
        aqorders => {
1528
            module   => 'Koha::Tmp::Orders', # Should Koha::Acquisition::Orders when will be based on Koha::Objects
1528
            module   => 'Koha::Acquisition::Orders',
1529
            singular => 'order',
1529
            singular => 'order',
1530
            plural   => 'orders',
1530
            plural   => 'orders',
1531
            pk       => 'ordernumber',
1531
            pk       => 'ordernumber',
(-)a/Koha/Acquisition/Order.pm (-55 / +59 lines)
Lines 1-95 Link Here
1
package Koha::Acquisition::Order;
1
package Koha::Acquisition::Order;
2
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
3
use Modern::Perl;
18
use Modern::Perl;
4
19
20
use Carp qw( croak );
21
5
use Koha::Database;
22
use Koha::Database;
6
use Koha::DateUtils qw( dt_from_string output_pref );
23
use Koha::DateUtils qw( dt_from_string output_pref );
7
24
8
use Carp qw( croak );
25
use base qw(Koha::Object);
9
26
10
use base qw( Class::Accessor );
27
=head1 NAME
11
28
12
# TODO fetch order from itemnumber (GetOrderFromItemnnumber)
29
Koha::Acquisition::Order Object class
13
# TODO Move code from GetOrder
30
14
sub fetch {
31
=head1 API
15
    my ( $class, $params ) = @_;
32
16
    my $ordernumber = $params->{ordernumber};
33
=head2 Class Methods
17
    return unless $ordernumber;
18
    my $schema = Koha::Database->new->schema;
19
34
20
    my $order =
35
=cut
21
      $schema->resultset('Aqorder')->find( { ordernumber => $ordernumber },
36
22
        { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } );
37
sub new {
23
    return $class->new( $order );
38
    my ( $self, $params ) = @_;
39
40
    my $schema  = Koha::Database->new->schema;
41
    my @columns = $schema->source('Aqorder')->columns;
42
43
    my $values =
44
      { map { exists $params->{$_} ? ( $_ => $params->{$_} ) : () } @columns };
45
    return $self->SUPER::new($values);
24
}
46
}
25
47
26
sub insert {
48
sub store {
27
    my ($self) = @_;
49
    my ($self) = @_;
28
50
29
    my $schema  = Koha::Database->new->schema;
51
    my $schema  = Koha::Database->new->schema;
30
    # Override quantity for standing orders
52
    # Override quantity for standing orders
31
    $self->{quantity} = 1 if ( $self->{basketno} && $schema->resultset('Aqbasket')->find( $self->{basketno} )->is_standing );
53
    $self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing );
32
54
33
    # if these parameters are missing, we can't continue
55
    # if these parameters are missing, we can't continue
34
    for my $key (qw( basketno quantity biblionumber budget_id )) {
56
    for my $key (qw( basketno quantity biblionumber budget_id )) {
35
        croak "Cannot insert order: Mandatory parameter $key is missing"
57
        croak "Cannot insert order: Mandatory parameter $key is missing"
36
          unless $self->{$key};
58
          unless $self->$key;
37
    }
59
    }
38
60
39
    $self->{quantityreceived} ||= 0;
61
    $self->quantityreceived(0) unless $self->quantityreceived;
40
    $self->{entrydate} ||=
62
    $self->entrydate(output_pref( { dt => dt_from_string, dateformat => 'iso' } )) unless $self->entrydate;
41
      output_pref( { dt => dt_from_string, dateformat => 'iso' } );
42
43
    my @columns = $schema->source('Aqorder')->columns;
44
45
    $self->{ordernumber} ||= undef;
46
63
47
    my $rs = $schema->resultset('Aqorder')->create(
64
    $self->ordernumber(undef) unless $self->ordernumber;
48
        {
65
    $self = $self->SUPER::store( $self );
49
            map {
50
                exists $self->{$_} ? ( $_ => $self->{$_} ) : ()
51
            } @columns
52
        }
53
    );
54
    $self->{ordernumber} = $rs->id;
55
66
56
    unless ( $self->{parent_ordernumber} ) {
67
    unless ( $self->parent_ordernumber ) {
57
        $self->{parent_ordernumber} = $self->{ordernumber};
68
        $self->set( { parent_ordernumber => $self->ordernumber } );
58
        $rs->update( { parent_ordernumber => $self->{parent_ordernumber} } );
69
        $self = $self->SUPER::store( $self );
59
    }
70
    }
60
71
61
    return $self;
72
    return $self;
62
}
73
}
63
74
75
=head3 add_item
76
77
  $order->add_item( $itemnumber );
78
79
Link an item to this order.
80
81
=cut
82
64
sub add_item {
83
sub add_item {
65
    my ( $self, $itemnumber )  = @_;
84
    my ( $self, $itemnumber )  = @_;
85
66
    my $schema = Koha::Database->new->schema;
86
    my $schema = Koha::Database->new->schema;
67
    my $rs = $schema->resultset('AqordersItem');
87
    my $rs = $schema->resultset('AqordersItem');
68
    $rs->create({ ordernumber => $self->{ordernumber}, itemnumber => $itemnumber });
88
    $rs->create({ ordernumber => $self->ordernumber, itemnumber => $itemnumber });
69
}
89
}
70
90
71
# TODO Move code from ModItemOrder
91
=head3 _type
72
sub update_item {
73
    die "not implemented yet";
74
}
75
76
sub del_item {
77
    die "not implemented yet";
78
}
79
92
80
# TODO Move code from ModOrder
93
=cut
81
sub update {
82
    die "not implemented yet";
83
}
84
85
# TODO Move code from DelOrder
86
sub delete {
87
    die "not implemented yet";
88
}
89
94
90
# TODO Move code from TransferOrder
95
sub _type {
91
sub transfer {
96
    return 'Aqorder';
92
    die "not implemented yet";
93
}
97
}
94
98
95
1;
99
1;
(-)a/Koha/Tmp/Orders.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::Tmp::Orders;
1
package Koha::Acquisition::Orders;
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
Lines 21-33 use Carp; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
23
24
use Koha::Tmp::Order;
24
use Koha::Acquisition::Order;
25
25
26
use base qw(Koha::Objects);
26
use base qw(Koha::Objects);
27
27
28
=head1 NAME
28
=head1 NAME
29
29
30
Koha::Tmp::Orders - This is a temporary class to make notices working with orders
30
Koha::Acquisition::Orders object set class
31
31
32
=head1 API
32
=head1 API
33
33
Lines 44-50 sub _type { Link Here
44
}
44
}
45
45
46
sub object_class {
46
sub object_class {
47
    return 'Koha::Tmp::Order';
47
    return 'Koha::Acquisition::Order';
48
}
48
}
49
49
50
1;
50
1;
(-)a/Koha/Tmp/Order.pm (-44 lines)
Lines 1-44 Link Here
1
package Koha::Tmp::Order;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Tmp::Order - This is a temporary class to make notices working with orders
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'Aqorder';
42
}
43
44
1;
(-)a/acqui/addorder.pl (-2 / +3 lines)
Lines 130-135 use C4::Budgets; Link Here
130
use C4::Items;
130
use C4::Items;
131
use C4::Output;
131
use C4::Output;
132
use Koha::Acquisition::Currencies;
132
use Koha::Acquisition::Currencies;
133
use Koha::Acquisition::Orders;
133
use C4::Barcodes;
134
use C4::Barcodes;
134
135
135
### "-------------------- addorder.pl ----------"
136
### "-------------------- addorder.pl ----------"
Lines 224-230 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
224
);
225
);
225
226
226
# get CGI parameters
227
# get CGI parameters
227
my $orderinfo					= $input->Vars;
228
my $orderinfo = $input->Vars;
228
$orderinfo->{'list_price'}    ||=  0;
229
$orderinfo->{'list_price'}    ||=  0;
229
$orderinfo->{'uncertainprice'} ||= 0;
230
$orderinfo->{'uncertainprice'} ||= 0;
230
$orderinfo->{subscriptionid} ||= undef;
231
$orderinfo->{subscriptionid} ||= undef;
Lines 286-292 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
286
        ModOrderUsers( $orderinfo->{ordernumber}, @order_users );
287
        ModOrderUsers( $orderinfo->{ordernumber}, @order_users );
287
    }
288
    }
288
    else { # else, it's a new line
289
    else { # else, it's a new line
289
        $order->insert;
290
        $order->store;
290
    }
291
    }
291
292
292
    # now, add items if applicable
293
    # now, add items if applicable
(-)a/acqui/addorderiso2709.pl (-3 / +3 lines)
Lines 45-51 use C4::Members; Link Here
45
use Koha::Number::Price;
45
use Koha::Number::Price;
46
use Koha::Libraries;
46
use Koha::Libraries;
47
use Koha::Acquisition::Currencies;
47
use Koha::Acquisition::Currencies;
48
use Koha::Acquisition::Order;
48
use Koha::Acquisition::Orders;
49
use Koha::Acquisition::Booksellers;
49
use Koha::Acquisition::Booksellers;
50
use Koha::Patrons;
50
use Koha::Patrons;
51
51
Lines 305-311 if ($op eq ""){ Link Here
305
                        )
305
                        )
306
                    };
306
                    };
307
307
308
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
308
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->store;
309
                    $order->add_item( $_ ) for @itemnumbers;
309
                    $order->add_item( $_ ) for @itemnumbers;
310
                }
310
                }
311
            }
311
            }
Lines 375-381 if ($op eq ""){ Link Here
375
            )
375
            )
376
        };
376
        };
377
377
378
        my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
378
        my $order = Koha::Acquisition::Order->new( \%orderinfo )->store;
379
379
380
        # 4th, add items if applicable
380
        # 4th, add items if applicable
381
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
381
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
(-)a/acqui/finishreceive.pl (-2 / +3 lines)
Lines 33-38 use C4::Search; Link Here
33
33
34
use Koha::Number::Price;
34
use Koha::Number::Price;
35
use Koha::Acquisition::Booksellers;
35
use Koha::Acquisition::Booksellers;
36
use Koha::Acquisition::Orders;
36
37
37
use List::MoreUtils qw/any/;
38
use List::MoreUtils qw/any/;
38
39
Lines 134-140 if ($quantityrec > $origquantityrec ) { Link Here
134
            push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
135
            push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
135
            push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
136
            push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
136
        }
137
        }
137
        my $order = Koha::Acquisition::Order->fetch({ ordernumber => $new_ordernumber });
138
        my $new_order = Koha::Acquisition::Orders->find( $new_ordernumber );
138
        foreach my $item (keys %itemhash){
139
        foreach my $item (keys %itemhash){
139
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
140
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
140
                                          $itemhash{$item}->{'subfields'},
141
                                          $itemhash{$item}->{'subfields'},
Lines 144-150 if ($quantityrec > $origquantityrec ) { Link Here
144
                                          'ITEM' );
145
                                          'ITEM' );
145
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
146
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
146
            my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
147
            my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
147
            $order->add_item( $itemnumber );
148
            $new_order->add_item( $itemnumber );
148
        }
149
        }
149
    }
150
    }
150
}
151
}
(-)a/admin/currency.pl (-4 / +2 lines)
Lines 26-33 use C4::Context; Link Here
26
use C4::Output;
26
use C4::Output;
27
27
28
use Koha::Acquisition::Booksellers;
28
use Koha::Acquisition::Booksellers;
29
use Koha::Acquisition::Currency;
30
use Koha::Acquisition::Currencies;
29
use Koha::Acquisition::Currencies;
30
use Koha::Acquisition::Orders;
31
31
32
my $input         = CGI->new;
32
my $input         = CGI->new;
33
my $searchfield   = $input->param('searchfield') || $input->param('description') || q{};
33
my $searchfield   = $input->param('searchfield') || $input->param('description') || q{};
Lines 92-100 if ( $op eq 'add_form' ) { Link Here
92
} elsif ( $op eq 'delete_confirm' ) {
92
} elsif ( $op eq 'delete_confirm' ) {
93
    my $currency = Koha::Acquisition::Currencies->find($currency_code);
93
    my $currency = Koha::Acquisition::Currencies->find($currency_code);
94
94
95
    # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects
95
    my $nb_of_orders = Koha::Acquisition::Orders->search( { currency => $currency->currency } )->count;
96
    my $schema = Koha::Database->schema;
97
    my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count;
98
    my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } })->count;
96
    my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } })->count;
99
    $template->param(
97
    $template->param(
100
        currency     => $currency,
98
        currency     => $currency,
(-)a/t/db_dependent/Acquisition.t (-11 / +7 lines)
Lines 26-32 BEGIN { Link Here
26
    use_ok('C4::Acquisition');
26
    use_ok('C4::Acquisition');
27
    use_ok('C4::Biblio');
27
    use_ok('C4::Biblio');
28
    use_ok('C4::Budgets');
28
    use_ok('C4::Budgets');
29
    use_ok('Koha::Acquisition::Order');
29
    use_ok('Koha::Acquisition::Orders');
30
    use_ok('Koha::Acquisition::Booksellers');
30
    use_ok('Koha::Acquisition::Booksellers');
31
}
31
}
32
32
Lines 188-194 my @order_content = ( Link Here
188
            ecost     => 38.15,
188
            ecost     => 38.15,
189
            rrp       => 40.15,
189
            rrp       => 40.15,
190
            discount  => 5.1111,
190
            discount  => 5.1111,
191
            tax_rate   => 0.0515
192
        }
191
        }
193
    },
192
    },
194
    {
193
    {
Lines 216-222 my @order_content = ( Link Here
216
            ecost     => 38.1,
215
            ecost     => 38.1,
217
            rrp       => 11.0,
216
            rrp       => 11.0,
218
            discount  => 5.1,
217
            discount  => 5.1,
219
            tax_rate   => 0.1
220
        }
218
        }
221
    },
219
    },
222
    {
220
    {
Lines 236-242 my @order_content = ( Link Here
236
            rrp            => 11.00,
234
            rrp            => 11.00,
237
            discount       => 0,
235
            discount       => 0,
238
            uncertainprice => 0,
236
            uncertainprice => 0,
239
            tax_rate        => 0
240
        }
237
        }
241
    },
238
    },
242
    {
239
    {
Lines 256-262 my @order_content = ( Link Here
256
            rrp            => 10,
253
            rrp            => 10,
257
            discount       => 0,
254
            discount       => 0,
258
            uncertainprice => 0,
255
            uncertainprice => 0,
259
            tax_rate        => 0
260
        }
256
        }
261
    },
257
    },
262
    {
258
    {
Lines 276-282 my @order_content = ( Link Here
276
            rrp            => 10,
272
            rrp            => 10,
277
            discount       => 0,
273
            discount       => 0,
278
            uncertainprice => 0,
274
            uncertainprice => 0,
279
            tax_rate        => 0
280
        }
275
        }
281
    }
276
    }
282
);
277
);
Lines 288-294 for ( 0 .. 5 ) { Link Here
288
      values %{ $order_content[$_]->{num} };
283
      values %{ $order_content[$_]->{num} };
289
    @ocontent{ keys %{ $order_content[$_]->{str} } } =
284
    @ocontent{ keys %{ $order_content[$_]->{str} } } =
290
      values %{ $order_content[$_]->{str} };
285
      values %{ $order_content[$_]->{str} };
291
    $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->insert->{ordernumber};
286
      use Data::Printer colored => 1; warn p %ocontent;
287
    $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->store->ordernumber;
292
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
288
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
293
}
289
}
294
290
Lines 305-311 my $invoice = GetInvoice( $invoiceid ); Link Here
305
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
301
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
306
    {
302
    {
307
        biblionumber      => $biblionumber4,
303
        biblionumber      => $biblionumber4,
308
        order             => GetOrder( $ordernumbers[4] ),
304
        order             => Koha::Acquisition::Orders->find( $ordernumbers[4] )->unblessed,
309
        quantityreceived  => 1,
305
        quantityreceived  => 1,
310
        invoice           => $invoice,
306
        invoice           => $invoice,
311
        budget_id          => $order_content[4]->{str}->{budget_id},
307
        budget_id          => $order_content[4]->{str}->{budget_id},
Lines 404-410 is( Link Here
404
    "AddClaim : Check claimed_date"
400
    "AddClaim : Check claimed_date"
405
);
401
);
406
402
407
my $order2 = GetOrder( $ordernumbers[1] );
403
my $order2 = Koha::Acquisition::Orders->find( $ordernumbers[1] )->unblessed;
408
$order2->{order_internalnote} = "my notes";
404
$order2->{order_internalnote} = "my notes";
409
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
405
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
410
    {
406
    {
Lines 445-451 my $budgetid2 = C4::Budgets::AddBudget( Link Here
445
    }
441
    }
446
);
442
);
447
443
448
my $order3 = GetOrder( $ordernumbers[2] );
444
my $order3 = Koha::Acquisition::Orders->find( $ordernumbers[2] )->unblessed;
449
$order3->{order_internalnote} = "my other notes";
445
$order3->{order_internalnote} = "my other notes";
450
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
446
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
451
    {
447
    {
Lines 472-478 is( $neworder->{'quantityreceived'}, Link Here
472
    2, 'Splitting up order received items on new order' );
468
    2, 'Splitting up order received items on new order' );
473
is( $neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed' );
469
is( $neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed' );
474
470
475
$order3 = GetOrder( $ordernumbers[2] );
471
$order3 = Koha::Acquisition::Orders->find( $ordernumbers[2] )->unblessed;
476
$order3->{order_internalnote} = "my third notes";
472
$order3->{order_internalnote} = "my third notes";
477
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
473
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
478
    {
474
    {
(-)a/t/db_dependent/Acquisition/CancelReceipt.t (-11 / +11 lines)
Lines 30-36 use t::lib::Mocks; Link Here
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::DateUtils;
31
use Koha::DateUtils;
32
use Koha::Acquisition::Booksellers;
32
use Koha::Acquisition::Booksellers;
33
use Koha::Acquisition::Order;
33
use Koha::Acquisition::Orders;
34
use MARC::Record;
34
use MARC::Record;
35
35
36
my $schema = Koha::Database->new()->schema();
36
my $schema = Koha::Database->new()->schema();
Lines 74-86 my $order = Koha::Acquisition::Order->new( Link Here
74
        biblionumber => $biblionumber,
74
        biblionumber => $biblionumber,
75
        budget_id => $budget->{budget_id},
75
        budget_id => $budget->{budget_id},
76
    }
76
    }
77
)->insert;
77
)->store;
78
my $ordernumber = $order->{ordernumber};
78
my $ordernumber = $order->ordernumber;
79
79
80
ModReceiveOrder(
80
ModReceiveOrder(
81
    {
81
    {
82
        biblionumber     => $biblionumber,
82
        biblionumber     => $biblionumber,
83
        order            => $order,
83
        order            => $order->unblessed,
84
        quantityreceived => 2,
84
        quantityreceived => 2,
85
    }
85
    }
86
);
86
);
Lines 103-112 $order = Koha::Acquisition::Order->new( Link Here
103
        biblionumber => $biblionumber,
103
        biblionumber => $biblionumber,
104
        budget_id => $budget->{budget_id},
104
        budget_id => $budget->{budget_id},
105
    }
105
    }
106
)->insert;
106
)->store;
107
$ordernumber = $order->{ordernumber};
107
$ordernumber = $order->ordernumber;
108
108
109
is( $order->{parent_ordernumber}, $order->{ordernumber},
109
is( $order->parent_ordernumber, $order->ordernumber,
110
    "Insert an order should set parent_order=ordernumber, if no parent_ordernumber given"
110
    "Insert an order should set parent_order=ordernumber, if no parent_ordernumber given"
111
);
111
);
112
112
Lines 114-120 $order->add_item( $itemnumber1 ); Link Here
114
$order->add_item( $itemnumber2 );
114
$order->add_item( $itemnumber2 );
115
115
116
is(
116
is(
117
    scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
117
    scalar( GetItemnumbersFromOrder( $order->ordernumber ) ),
118
    2,
118
    2,
119
    "Create items on ordering: 2 items should be linked to the order before receiving"
119
    "Create items on ordering: 2 items should be linked to the order before receiving"
120
);
120
);
Lines 122-128 is( Link Here
122
my ( undef, $new_ordernumber ) = ModReceiveOrder(
122
my ( undef, $new_ordernumber ) = ModReceiveOrder(
123
    {
123
    {
124
        biblionumber     => $biblionumber,
124
        biblionumber     => $biblionumber,
125
        order            => $order,
125
        order            => $order->unblessed,
126
        quantityreceived => 1,
126
        quantityreceived => 1,
127
        received_items   => [ $itemnumber1 ],
127
        received_items   => [ $itemnumber1 ],
128
    }
128
    }
Lines 139-145 is( $new_order->{parent_ordernumber}, $ordernumber, Link Here
139
);
139
);
140
140
141
is(
141
is(
142
    scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
142
    scalar( GetItemnumbersFromOrder( $order->ordernumber ) ),
143
    1,
143
    1,
144
    "Create items on ordering: 1 item should still be linked to the original order after receiving"
144
    "Create items on ordering: 1 item should still be linked to the original order after receiving"
145
);
145
);
Lines 157-163 is( Link Here
157
    "Create items on ordering: no item should be linked to the cancelled order"
157
    "Create items on ordering: no item should be linked to the cancelled order"
158
);
158
);
159
is(
159
is(
160
    scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
160
    scalar( GetItemnumbersFromOrder( $order->ordernumber ) ),
161
    2,
161
    2,
162
    "Create items on ordering: items are not deleted after cancelling a receipt"
162
    "Create items on ordering: items are not deleted after cancelling a receipt"
163
);
163
);
(-)a/t/db_dependent/Acquisition/GetBasketAsCSV.t (-3 / +3 lines)
Lines 11-17 use C4::Biblio; Link Here
11
use Koha::Database;
11
use Koha::Database;
12
use Koha::CsvProfile;
12
use Koha::CsvProfile;
13
13
14
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Orders;
15
15
16
my $schema = Koha::Database->new()->schema();
16
my $schema = Koha::Database->new()->schema();
17
$schema->storage->txn_begin();
17
$schema->storage->txn_begin();
Lines 61-67 my $order = Koha::Acquisition::Order->new({ Link Here
61
    biblionumber => $biblionumber,
61
    biblionumber => $biblionumber,
62
    budget_id => $budget_id,
62
    budget_id => $budget_id,
63
    entrydate => '2016-01-02',
63
    entrydate => '2016-01-02',
64
})->insert;
64
})->store;
65
65
66
# Use user CSV profile
66
# Use user CSV profile
67
my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id);
67
my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id);
Lines 72-78 is($basket_csv1, 'autor,title,quantity Link Here
72
# Use default template
72
# Use default template
73
my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query);
73
my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query);
74
is($basket_csv2, 'Contract name,Order number,Entry date,ISBN,Author,Title,Publication year,Publisher,Collection title,Note for vendor,Quantity,RRP,Delivery place,Billing place
74
is($basket_csv2, 'Contract name,Order number,Entry date,ISBN,Author,Title,Publication year,Publisher,Collection title,Note for vendor,Quantity,RRP,Delivery place,Billing place
75
"",' . $order->{ordernumber}  . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"",""
75
"",' . $order->ordernumber  . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"",""
76
', 'CSV should be generated with default template');
76
', 'CSV should be generated with default template');
77
77
78
my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id);
78
my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id);
(-)a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t (-5 / +5 lines)
Lines 9-15 use C4::Biblio qw( AddBiblio ); Link Here
9
use C4::Budgets qw( AddBudget );
9
use C4::Budgets qw( AddBudget );
10
use C4::Context;
10
use C4::Context;
11
use Koha::Database;
11
use Koha::Database;
12
use Koha::Acquisition::Order;
12
use Koha::Acquisition::Orders;
13
13
14
my $schema = Koha::Database->new()->schema();
14
my $schema = Koha::Database->new()->schema();
15
$schema->storage->txn_begin();
15
$schema->storage->txn_begin();
Lines 50-57 my $order1 = Koha::Acquisition::Order->new( Link Here
50
        biblionumber => $biblionumber1,
50
        biblionumber => $biblionumber1,
51
        budget_id => $budget->{budget_id},
51
        budget_id => $budget->{budget_id},
52
    }
52
    }
53
)->insert;
53
)->store;
54
my $ordernumber1 = $order1->{ordernumber};
54
my $ordernumber1 = $order1->ordernumber;
55
55
56
my $order2 = Koha::Acquisition::Order->new(
56
my $order2 = Koha::Acquisition::Order->new(
57
    {
57
    {
Lines 60-67 my $order2 = Koha::Acquisition::Order->new( Link Here
60
        biblionumber => $biblionumber2,
60
        biblionumber => $biblionumber2,
61
        budget_id => $budget->{budget_id},
61
        budget_id => $budget->{budget_id},
62
    }
62
    }
63
)->insert;
63
)->store;
64
my $ordernumber2 = $order2->{ordernumber};
64
my $ordernumber2 = $order2->ordernumber;
65
65
66
my $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
66
my $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
67
is( scalar(@$baskets), 1, 'Start: 1 basket' );
67
is( scalar(@$baskets), 1, 'Start: 1 basket' );
(-)a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t (-7 / +7 lines)
Lines 7-13 use C4::Acquisition; Link Here
7
use C4::Biblio;
7
use C4::Biblio;
8
use C4::Budgets;
8
use C4::Budgets;
9
use Koha::Database;
9
use Koha::Database;
10
use Koha::Acquisition::Order;
10
use Koha::Acquisition::Orders;
11
11
12
use MARC::Record;
12
use MARC::Record;
13
13
Lines 48-55 my $order1 = Koha::Acquisition::Order->new( Link Here
48
        biblionumber => $biblionumber1,
48
        biblionumber => $biblionumber1,
49
        budget_id => $budget->{budget_id},
49
        budget_id => $budget->{budget_id},
50
    }
50
    }
51
)->insert;
51
)->store;
52
my $ordernumber1 = $order1->{ordernumber};
52
my $ordernumber1 = $order1->ordernumber;
53
53
54
my $order2 = Koha::Acquisition::Order->new(
54
my $order2 = Koha::Acquisition::Order->new(
55
    {
55
    {
Lines 58-65 my $order2 = Koha::Acquisition::Order->new( Link Here
58
        biblionumber => $biblionumber2,
58
        biblionumber => $biblionumber2,
59
        budget_id => $budget->{budget_id},
59
        budget_id => $budget->{budget_id},
60
    }
60
    }
61
)->insert;
61
)->store;
62
my $ordernumber2 = $order1->{ordernumber};
62
my $ordernumber2 = $order2->ordernumber;
63
63
64
my $order3 = Koha::Acquisition::Order->new(
64
my $order3 = Koha::Acquisition::Order->new(
65
    {
65
    {
Lines 68-75 my $order3 = Koha::Acquisition::Order->new( Link Here
68
        biblionumber => $biblionumber2,
68
        biblionumber => $biblionumber2,
69
        budget_id => $budget->{budget_id},
69
        budget_id => $budget->{budget_id},
70
    }
70
    }
71
)->insert;
71
)->store;
72
my $ordernumber3 = $order1->{ordernumber};
72
my $ordernumber3 = $order3->ordernumber;
73
73
74
my @orders = GetOrdersByBiblionumber();
74
my @orders = GetOrdersByBiblionumber();
75
is(scalar(@orders), 0, 'GetOrdersByBiblionumber : no argument, return undef');
75
is(scalar(@orders), 0, 'GetOrdersByBiblionumber : no argument, return undef');
(-)a/t/db_dependent/Acquisition/Invoices.t (-10 / +10 lines)
Lines 4-11 use Modern::Perl; Link Here
4
4
5
use C4::Biblio qw( AddBiblio );
5
use C4::Biblio qw( AddBiblio );
6
6
7
use Koha::Acquisition::Order;
8
use Koha::Acquisition::Booksellers;
7
use Koha::Acquisition::Booksellers;
8
use Koha::Acquisition::Orders;
9
use Koha::Database;
9
use Koha::Database;
10
10
11
use Test::More tests => 24;
11
use Test::More tests => 24;
Lines 61-68 my $order1 = Koha::Acquisition::Order->new( Link Here
61
        biblionumber => $biblionumber1,
61
        biblionumber => $biblionumber1,
62
        budget_id => $budget->{budget_id},
62
        budget_id => $budget->{budget_id},
63
    }
63
    }
64
)->insert;
64
)->store;
65
my $ordernumber1 = $order1->{ordernumber};
65
my $ordernumber1 = $order1->ordernumber;
66
66
67
my $order2 = Koha::Acquisition::Order->new(
67
my $order2 = Koha::Acquisition::Order->new(
68
    {
68
    {
Lines 71-78 my $order2 = Koha::Acquisition::Order->new( Link Here
71
        biblionumber => $biblionumber2,
71
        biblionumber => $biblionumber2,
72
        budget_id => $budget->{budget_id},
72
        budget_id => $budget->{budget_id},
73
    }
73
    }
74
)->insert;
74
)->store;
75
my $ordernumber2 = $order2->{ordernumber};
75
my $ordernumber2 = $order2->ordernumber;
76
76
77
my $order3 = Koha::Acquisition::Order->new(
77
my $order3 = Koha::Acquisition::Order->new(
78
    {
78
    {
Lines 83-90 my $order3 = Koha::Acquisition::Order->new( Link Here
83
        ecost => 42,
83
        ecost => 42,
84
        rrp => 42,
84
        rrp => 42,
85
    }
85
    }
86
)->insert;
86
)->store;
87
my $ordernumber3 = $order3->{ordernumber};
87
my $ordernumber3 = $order3->ordernumber;
88
88
89
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
89
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
90
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown",
90
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown",
Lines 97-103 my $invoice2 = GetInvoice( $invoiceid2 ); Link Here
97
my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
97
my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
98
    {
98
    {
99
        biblionumber     => $biblionumber1,
99
        biblionumber     => $biblionumber1,
100
        order            => $order1,
100
        order            => $order1->unblessed,
101
        quantityreceived => 2,
101
        quantityreceived => 2,
102
        invoice          => $invoice1,
102
        invoice          => $invoice1,
103
    }
103
    }
Lines 106-112 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( Link Here
106
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
106
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
107
    {
107
    {
108
        biblionumber     => $biblionumber2,
108
        biblionumber     => $biblionumber2,
109
        order            => $order2,
109
        order            => $order2->unblessed,
110
        quantityreceived => 1,
110
        quantityreceived => 1,
111
        invoice          => $invoice2,
111
        invoice          => $invoice2,
112
        rrp              => 42
112
        rrp              => 42
Lines 116-122 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( Link Here
116
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
116
( $datereceived, $new_ordernumber ) = ModReceiveOrder(
117
    {
117
    {
118
        biblionumber     => $biblionumber3,
118
        biblionumber     => $biblionumber3,
119
        order            => $order3,
119
        order            => $order3->unblessed,
120
        quantityreceived => 1,
120
        quantityreceived => 1,
121
        invoice          => $invoice2,
121
        invoice          => $invoice2,
122
    }
122
    }
(-)a/t/db_dependent/Acquisition/NewOrder.t (-8 / +8 lines)
Lines 10-16 use MARC::Record; Link Here
10
use Koha::Database;
10
use Koha::Database;
11
use Koha::DateUtils qw( dt_from_string output_pref );
11
use Koha::DateUtils qw( dt_from_string output_pref );
12
use Koha::Acquisition::Booksellers;
12
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Order;
13
use Koha::Acquisition::Orders;
14
14
15
my $schema = Koha::Database->new()->schema();
15
my $schema = Koha::Database->new()->schema();
16
$schema->storage->txn_begin();
16
$schema->storage->txn_begin();
Lines 44-50 my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); Link Here
44
44
45
45
46
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
46
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
47
my $order = eval { Koha::Acquisition::Order->new->insert };
47
my $order = eval { Koha::Acquisition::Order->new->store };
48
my $return_error = $@;
48
my $return_error = $@;
49
ok(
49
ok(
50
    ( ! defined $order )
50
    ( ! defined $order )
Lines 63-69 foreach my $mandatoryparams_key (@mandatoryparams_keys) { Link Here
63
    my %test_missing_mandatoryparams = %$mandatoryparams;
63
    my %test_missing_mandatoryparams = %$mandatoryparams;
64
    delete $test_missing_mandatoryparams{$mandatoryparams_key};
64
    delete $test_missing_mandatoryparams{$mandatoryparams_key};
65
    $order = eval {
65
    $order = eval {
66
          Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->insert;
66
          Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->store;
67
    };
67
    };
68
    $return_error = $@;
68
    $return_error = $@;
69
    my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
69
    my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
Lines 81-90 $order = Koha::Acquisition::Order->new( Link Here
81
        biblionumber => $biblionumber1,
81
        biblionumber => $biblionumber1,
82
        budget_id => $budget->{budget_id},
82
        budget_id => $budget->{budget_id},
83
    }
83
    }
84
)->insert;
84
)->store;
85
my $ordernumber = $order->{ordernumber};
85
my $ordernumber = $order->ordernumber;
86
$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
86
$order = Koha::Acquisition::Orders->find( $ordernumber );
87
is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
87
is( $order->quantityreceived, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
88
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
88
is( $order->entrydate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->store set entrydate to today' );
89
89
90
$schema->storage->txn_rollback();
90
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Acquisition/OrderFromSubscription.t (-5 / +3 lines)
Lines 9-15 use_ok('C4::Biblio'); Link Here
9
use_ok('C4::Budgets');
9
use_ok('C4::Budgets');
10
use_ok('C4::Serials');
10
use_ok('C4::Serials');
11
11
12
use Koha::Acquisition::Order;
12
use Koha::Acquisition::Orders;
13
use Koha::Database;
13
use Koha::Database;
14
14
15
# Start transaction
15
# Start transaction
Lines 68-83 my $order = Koha::Acquisition::Order->new({ Link Here
68
    quantity => 1,
68
    quantity => 1,
69
    currency => $curcode,
69
    currency => $curcode,
70
    listprice => $cost,
70
    listprice => $cost,
71
    notes => "This is a note",
72
    basketno => $basketno,
71
    basketno => $basketno,
73
    rrp => $cost,
72
    rrp => $cost,
74
    ecost => $cost,
73
    ecost => $cost,
75
    tax_rate => 0.0500,
76
    orderstatus => 'new',
74
    orderstatus => 'new',
77
    subscriptionid => $subscription->{subscriptionid},
75
    subscriptionid => $subscription->{subscriptionid},
78
    budget_id => $budget_id,
76
    budget_id => $budget_id,
79
})->insert;
77
})->store;
80
my $ordernumber = $order->{ordernumber};
78
my $ordernumber = $order->ordernumber;
81
79
82
my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
80
my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
83
is ( $is_currently_on_order, 1, "The subscription is currently on order");
81
is ( $is_currently_on_order, 1, "The subscription is currently on order");
(-)a/t/db_dependent/Acquisition/OrderUsers.t (-8 / +7 lines)
Lines 5-12 use C4::Acquisition; Link Here
5
use C4::Biblio;
5
use C4::Biblio;
6
use C4::Letters;
6
use C4::Letters;
7
use Koha::Database;
7
use Koha::Database;
8
use Koha::Acquisition::Order;
9
use Koha::Acquisition::Booksellers;
8
use Koha::Acquisition::Booksellers;
9
use Koha::Acquisition::Orders;
10
10
11
use t::lib::TestBuilder;
11
use t::lib::TestBuilder;
12
12
Lines 51-64 my $order = Koha::Acquisition::Order->new( Link Here
51
        budget_id        => $budgetid,
51
        budget_id        => $budgetid,
52
        entrydate        => '01-01-2014',
52
        entrydate        => '01-01-2014',
53
        currency         => $currency->{currency},
53
        currency         => $currency->{currency},
54
        notes            => "This is a note1",
55
        orderstatus      => 1,
54
        orderstatus      => 1,
56
        quantityreceived => 0,
55
        quantityreceived => 0,
57
        rrp              => 10,
56
        rrp              => 10,
58
        ecost            => 10,
57
        ecost            => 10,
59
    }
58
    }
60
)->insert;
59
)->store;
61
my $ordernumber = $order->{ordernumber};
60
my $ordernumber = $order->ordernumber;
62
61
63
my $invoiceid = AddInvoice(
62
my $invoiceid = AddInvoice(
64
    invoicenumber => 'invoice',
63
    invoicenumber => 'invoice',
Lines 82-92 C4::Acquisition::ModOrderUsers( $ordernumber, $borrowernumber ); Link Here
82
my $is_added = grep { /^$borrowernumber$/ } C4::Acquisition::GetOrderUsers( $ordernumber );
81
my $is_added = grep { /^$borrowernumber$/ } C4::Acquisition::GetOrderUsers( $ordernumber );
83
is( $is_added, 1, 'ModOrderUsers should link patrons to an order' );
82
is( $is_added, 1, 'ModOrderUsers should link patrons to an order' );
84
83
85
$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
84
$order = Koha::Acquisition::Orders->find( $ordernumber );
86
ModReceiveOrder(
85
ModReceiveOrder(
87
    {
86
    {
88
        biblionumber      => $biblionumber,
87
        biblionumber      => $biblionumber,
89
        order             => $order,
88
        order             => $order->unblessed,
90
        quantityreceived  => 1,
89
        quantityreceived  => 1,
91
        cost              => 10,
90
        cost              => 10,
92
        ecost             => 10,
91
        ecost             => 10,
Lines 99-109 ModReceiveOrder( Link Here
99
my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
98
my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
100
is( scalar( @$messages ), 0, 'The letter has not been sent to message queue on receiving the order, the order is not entire received');
99
is( scalar( @$messages ), 0, 'The letter has not been sent to message queue on receiving the order, the order is not entire received');
101
100
102
$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
101
$order = Koha::Acquisition::Orders->find( $ordernumber );
103
ModReceiveOrder(
102
ModReceiveOrder(
104
    {
103
    {
105
        biblionumber      => $biblionumber,
104
        biblionumber      => $biblionumber,
106
        order             => $order,
105
        order             => $order->unblessed,
107
        quantityreceived  => 1,
106
        quantityreceived  => 1,
108
        cost              => 10,
107
        cost              => 10,
109
        ecost             => 10,
108
        ecost             => 10,
(-)a/t/db_dependent/Acquisition/StandingOrders.t (-15 / +14 lines)
Lines 8-14 use C4::Acquisition; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Budgets;
10
use C4::Budgets;
11
use Koha::Acquisition::Order;
11
use Koha::Acquisition::Orders;
12
use t::lib::Mocks;
12
use t::lib::Mocks;
13
use t::lib::TestBuilder;
13
use t::lib::TestBuilder;
14
14
Lines 73-83 my $ordernumber = Koha::Acquisition::Order->new( Link Here
73
        unitprice                => 12,
73
        unitprice                => 12,
74
        unitprice_tax_included   => 12,
74
        unitprice_tax_included   => 12,
75
        unitprice_tax_excluded   => 12,
75
        unitprice_tax_excluded   => 12,
76
        tax_rate                 => 0,
77
        tax_rate_on_ordering     => 0,
76
        tax_rate_on_ordering     => 0,
78
        tax_rate_on_receiving    => 0,
77
        tax_rate_on_receiving    => 0,
79
    }
78
    }
80
)->insert->{ordernumber};
79
)->store->ordernumber;
81
80
82
isnt( $ordernumber, undef, 'standing order successfully created' );
81
isnt( $ordernumber, undef, 'standing order successfully created' );
83
82
Lines 98-109 my $invoiceid = AddInvoice( Link Here
98
    unknown       => "unknown"
97
    unknown       => "unknown"
99
);
98
);
100
99
101
my $order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } );
100
my $order = Koha::Acquisition::Orders->find( $ordernumber );
102
101
103
my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
102
my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
104
    {
103
    {
105
        biblionumber     => $biblionumber,
104
        biblionumber     => $biblionumber,
106
        order            => $order,
105
        order            => $order->unblessed,
107
        quantityreceived => 2,
106
        quantityreceived => 2,
108
        invoiceid        => $invoiceid,
107
        invoiceid        => $invoiceid,
109
    }
108
    }
Lines 112-127 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( Link Here
112
isnt( $ordernumber, $new_ordernumber, "standing order split on receive" );
111
isnt( $ordernumber, $new_ordernumber, "standing order split on receive" );
113
112
114
#order has been updated, refetch
113
#order has been updated, refetch
115
$order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } );
114
$order = Koha::Acquisition::Orders->find( $ordernumber );
116
my $neworder = Koha::Acquisition::Order->fetch( { ordernumber => $new_ordernumber } );
115
my $neworder = Koha::Acquisition::Orders->find( $new_ordernumber );
117
116
118
is( $order->{orderstatus}, 'partial', 'original order set to partially received' );
117
is( $order->orderstatus, 'partial', 'original order set to partially received' );
119
is( $order->{quantity}, 1, 'original order quantity unchanged' );
118
is( $order->quantity, 1, 'original order quantity unchanged' );
120
is( $order->{quantityreceived}, 0, 'original order has no received items' );
119
is( $order->quantityreceived, 0, 'original order has no received items' );
121
isnt( $order->{unitprice}, 12, 'original order does not get cost' );
120
isnt( $order->unitprice, 12, 'original order does not get cost' );
122
is( $neworder->{orderstatus}, 'complete', 'new order set to complete' );
121
is( $neworder->orderstatus, 'complete', 'new order set to complete' );
123
is( $neworder->{quantityreceived}, 2, 'new order has received items' );
122
is( $neworder->quantityreceived, 2, 'new order has received items' );
124
cmp_ok( $neworder->{unitprice}, '==', 12, 'new order does get cost' );
123
cmp_ok( $neworder->unitprice, '==', 12, 'new order does get cost' );
125
124
126
$search_orders = SearchOrders( {
125
$search_orders = SearchOrders( {
127
    basketno => $basketno,
126
    basketno => $basketno,
(-)a/t/db_dependent/Acquisition/TransferOrder.t (-4 / +4 lines)
Lines 11-17 use C4::Budgets; Link Here
11
use Koha::Database;
11
use Koha::Database;
12
use Koha::DateUtils;
12
use Koha::DateUtils;
13
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Orders;
15
use MARC::Record;
15
use MARC::Record;
16
16
17
my $schema = Koha::Database->new()->schema();
17
my $schema = Koha::Database->new()->schema();
Lines 65-72 my $order = Koha::Acquisition::Order->new( Link Here
65
        biblionumber => $biblionumber,
65
        biblionumber => $biblionumber,
66
        budget_id => $budget->{budget_id},
66
        budget_id => $budget->{budget_id},
67
    }
67
    }
68
)->insert;
68
)->store;
69
my $ordernumber = $order->{ordernumber};
69
my $ordernumber = $order->ordernumber;
70
$order->add_item( $itemnumber );
70
$order->add_item( $itemnumber );
71
71
72
# Begin tests
72
# Begin tests
Lines 95-101 $orders = SearchOrders({ ordernumber => $ordernumber }); Link Here
95
is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with [old]ordernumber' );
95
is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with [old]ordernumber' );
96
is ( $orders->[0]->{ordernumber}, $newordernumber, 'SearchOrders returns newordernumber if [old]ordernumber is given' );
96
is ( $orders->[0]->{ordernumber}, $newordernumber, 'SearchOrders returns newordernumber if [old]ordernumber is given' );
97
97
98
my $neworder = GetOrder( $newordernumber );
98
my $neworder = Koha::Acquisition::Orders->find( $newordernumber )->unblessed;
99
99
100
ModReceiveOrder({
100
ModReceiveOrder({
101
    biblionumber => $biblionumber,
101
    biblionumber => $biblionumber,
(-)a/t/db_dependent/Acquisition/close_reopen_basket.t (-6 / +6 lines)
Lines 8-15 use C4::Biblio qw( AddBiblio DelBiblio ); Link Here
8
use C4::Budgets;
8
use C4::Budgets;
9
use C4::Context;
9
use C4::Context;
10
use Koha::Database;
10
use Koha::Database;
11
use Koha::Acquisition::Bookseller;
11
use Koha::Acquisition::Booksellers;
12
use Koha::Acquisition::Order;
12
use Koha::Acquisition::Orders;
13
13
14
# Start transaction
14
# Start transaction
15
my $schema = Koha::Database->new()->schema();
15
my $schema = Koha::Database->new()->schema();
Lines 54-61 my $order1 = Koha::Acquisition::Order->new( Link Here
54
        biblionumber => $biblionumber1,
54
        biblionumber => $biblionumber1,
55
        budget_id => $budget->{budget_id},
55
        budget_id => $budget->{budget_id},
56
    }
56
    }
57
)->insert;
57
)->store;
58
my $ordernumber1 = $order1->{ordernumber};
58
my $ordernumber1 = $order1->ordernumber;
59
59
60
my $order2 = Koha::Acquisition::Order->new(
60
my $order2 = Koha::Acquisition::Order->new(
61
    {
61
    {
Lines 64-71 my $order2 = Koha::Acquisition::Order->new( Link Here
64
        biblionumber => $biblionumber2,
64
        biblionumber => $biblionumber2,
65
        budget_id => $budget->{budget_id},
65
        budget_id => $budget->{budget_id},
66
    }
66
    }
67
)->insert;
67
)->store;
68
my $ordernumber2 = $order2->{ordernumber};
68
my $ordernumber2 = $order2->ordernumber;
69
69
70
my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno );
70
my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno );
71
is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
71
is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
(-)a/t/db_dependent/Bookseller.t (-9 / +9 lines)
Lines 18-24 use C4::Budgets; Link Here
18
use C4::Biblio;
18
use C4::Biblio;
19
19
20
use Koha::Acquisition::Booksellers;
20
use Koha::Acquisition::Booksellers;
21
use Koha::Acquisition::Order;
21
use Koha::Acquisition::Orders;
22
use Koha::Database;
22
use Koha::Database;
23
23
24
BEGIN {
24
BEGIN {
Lines 365-372 my $order1 = Koha::Acquisition::Order->new( Link Here
365
        ecost            => 10,
365
        ecost            => 10,
366
        datereceived     => '01-06-2013'
366
        datereceived     => '01-06-2013'
367
    }
367
    }
368
)->insert;
368
)->store;
369
my $ordernumber1 = $order1->{ordernumber};
369
my $ordernumber1 = $order1->ordernumber;
370
370
371
my $order2 = Koha::Acquisition::Order->new(
371
my $order2 = Koha::Acquisition::Order->new(
372
    {
372
    {
Lines 383-390 my $order2 = Koha::Acquisition::Order->new( Link Here
383
        rrp            => 10,
383
        rrp            => 10,
384
        ecost          => 10,
384
        ecost          => 10,
385
    }
385
    }
386
)->insert;
386
)->store;
387
my $ordernumber2 = $order2->{ordernumber};
387
my $ordernumber2 = $order2->ordernumber;
388
388
389
my $order3 = Koha::Acquisition::Order->new(
389
my $order3 = Koha::Acquisition::Order->new(
390
    {
390
    {
Lines 401-408 my $order3 = Koha::Acquisition::Order->new( Link Here
401
        rrp            => 11,
401
        rrp            => 11,
402
        ecost          => 11,
402
        ecost          => 11,
403
    }
403
    }
404
)->insert;
404
)->store;
405
my $ordernumber3 = $order3->{ordernumber};
405
my $ordernumber3 = $order3->ordernumber;
406
406
407
my $order4 = Koha::Acquisition::Order->new(
407
my $order4 = Koha::Acquisition::Order->new(
408
    {
408
    {
Lines 420-427 my $order4 = Koha::Acquisition::Order->new( Link Here
420
        ecost            => 11,
420
        ecost            => 11,
421
        quantityreceived => 20
421
        quantityreceived => 20
422
    }
422
    }
423
)->insert;
423
)->store;
424
my $ordernumber4 = $order4->{ordernumber};
424
my $ordernumber4 = $order4->ordernumber;
425
425
426
#Test cases:
426
#Test cases:
427
# Sample datas :
427
# Sample datas :
(-)a/t/db_dependent/Budgets.t (-6 / +6 lines)
Lines 10-17 use C4::Biblio; Link Here
10
use C4::Acquisition;
10
use C4::Acquisition;
11
use C4::Members qw( AddMember );
11
use C4::Members qw( AddMember );
12
12
13
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Orders;
15
15
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
17
17
Lines 357-364 for my $infos (@order_infos) { Link Here
357
                discount           => 0,
357
                discount           => 0,
358
                uncertainprice     => 0,
358
                uncertainprice     => 0,
359
            }
359
            }
360
        )->insert;
360
        )->store;
361
        my $ordernumber = $order->{ordernumber};
361
        my $ordernumber = $order->ordernumber;
362
        push @{ $budgets{$infos->{budget_id}} }, $ordernumber;
362
        push @{ $budgets{$infos->{budget_id}} }, $ordernumber;
363
        $number_of_orders_to_move++;
363
        $number_of_orders_to_move++;
364
    }
364
    }
Lines 378-388 for my $infos (@order_infos) { Link Here
378
                discount           => 0,
378
                discount           => 0,
379
                uncertainprice     => 0,
379
                uncertainprice     => 0,
380
            }
380
            }
381
        )->insert;
381
        )->store;
382
        my $ordernumber = $order->{ordernumber};
382
        my $ordernumber = $order->ordernumber;
383
        ModReceiveOrder({
383
        ModReceiveOrder({
384
              biblionumber     => $biblionumber,
384
              biblionumber     => $biblionumber,
385
              order            => $order,
385
              order            => $order->unblessed,
386
              budget_id        => $infos->{budget_id},
386
              budget_id        => $infos->{budget_id},
387
              quantityreceived => $item_quantity,
387
              quantityreceived => $item_quantity,
388
              invoice          => $invoice,
388
              invoice          => $invoice,
(-)a/t/db_dependent/Letters.t (-3 / +3 lines)
Lines 43-51 use t::lib::Mocks; Link Here
43
use t::lib::TestBuilder;
43
use t::lib::TestBuilder;
44
use Koha::Database;
44
use Koha::Database;
45
use Koha::DateUtils qw( dt_from_string output_pref );
45
use Koha::DateUtils qw( dt_from_string output_pref );
46
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Booksellers;
46
use Koha::Acquisition::Booksellers;
48
use Koha::Acquisition::Bookseller::Contacts;
47
use Koha::Acquisition::Bookseller::Contacts;
48
use Koha::Acquisition::Orders;
49
use Koha::Libraries;
49
use Koha::Libraries;
50
use Koha::Notice::Templates;
50
use Koha::Notice::Templates;
51
my $schema = Koha::Database->schema;
51
my $schema = Koha::Database->schema;
Lines 435-442 my $order = Koha::Acquisition::Order->new( Link Here
435
        biblionumber => $biblionumber,
435
        biblionumber => $biblionumber,
436
        budget_id => $budgetid,
436
        budget_id => $budgetid,
437
    }
437
    }
438
)->insert;
438
)->store;
439
my $ordernumber = $order->{ordernumber};
439
my $ordernumber = $order->ordernumber;
440
440
441
C4::Acquisition::CloseBasket( $basketno );
441
C4::Acquisition::CloseBasket( $basketno );
442
my $err;
442
my $err;
(-)a/t/db_dependent/UsageStats.t (-2 / +1 lines)
Lines 31-37 BEGIN { Link Here
31
    use_ok( 'C4::AuthoritiesMarc', qw(AddAuthority) );
31
    use_ok( 'C4::AuthoritiesMarc', qw(AddAuthority) );
32
    use_ok('C4::Reserves');
32
    use_ok('C4::Reserves');
33
    use_ok('MARC::Record');
33
    use_ok('MARC::Record');
34
    use_ok('Koha::Acquisition::Order');
34
    use_ok('Koha::Acquisition::Orders');
35
}
35
}
36
36
37
can_ok(
37
can_ok(
38
- 

Return to bug 19256