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

(-)a/C4/Acquisition.pm (-8 / +1 lines)
Lines 1270-1284 sub NewOrder { Link Here
1270
        croak "Cannot insert order: Mandatory parameter $key is missing" unless $orderinfo->{$key};
1270
        croak "Cannot insert order: Mandatory parameter $key is missing" unless $orderinfo->{$key};
1271
    }
1271
    }
1272
1272
1273
    if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
1274
        $orderinfo->{'subscription'} = 1;
1275
    } else {
1276
        $orderinfo->{'subscription'} = 0;
1277
    }
1278
1279
    $orderinfo->{entrydate} ||= output_pref({ dt => dt_from_string, dateformat => 'iso'});
1280
1281
    $orderinfo->{quantityreceived} ||= 0;
1273
    $orderinfo->{quantityreceived} ||= 0;
1274
    $orderinfo->{entrydate} ||= output_pref({ dt => dt_from_string, dateformat => 'iso'});
1282
1275
1283
    # get only the columns of Aqorder
1276
    # get only the columns of Aqorder
1284
    my $schema = Koha::Database->new()->schema;
1277
    my $schema = Koha::Database->new()->schema;
(-)a/t/db_dependent/Acquisition.t (-41 / +1 lines)
Lines 8-14 use POSIX qw(strftime); Link Here
8
8
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
10
11
use Test::More tests => 79;
11
use Test::More tests => 74;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Acquisition');
14
    use_ok('C4::Acquisition');
Lines 144-189 my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' ); Link Here
144
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
144
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
145
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
145
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
146
146
147
#
148
# Test NewOrder
149
#
150
151
my ( $mandatoryparams, $return_error, $basketnum );
152
153
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
154
eval { $ordernumbers[0] = C4::Acquisition::NewOrder() };
155
$return_error = $@;
156
ok(
157
    ( ! defined $ordernumbers[0] )
158
      && ( defined $return_error ),
159
    "NewOrder with no params returns undef and croaks"
160
);
161
162
$mandatoryparams = {
163
    basketno     => $basketno,
164
    quantity     => 24,
165
    biblionumber => $biblionumber1,
166
    budget_id    => $budget->{budget_id},
167
};
168
my @mandatoryparams_keys = keys %$mandatoryparams;
169
foreach my $mandatoryparams_key (@mandatoryparams_keys) {
170
    my %test_missing_mandatoryparams = %$mandatoryparams;
171
    delete $test_missing_mandatoryparams{$mandatoryparams_key};
172
    eval {
173
        $ordernumbers[0] =
174
          C4::Acquisition::NewOrder( \%test_missing_mandatoryparams );
175
    };
176
    $return_error = $@;
177
    my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
178
    ok(
179
        ( !( defined $basketnum || defined $ordernumbers[0] ) )
180
          && ( index( $return_error, $expected_error ) >= 0 ),
181
"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message"
182
    );
183
}
184
185
# FIXME to do : test the other features of NewOrder
186
187
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
147
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
188
# Ex : a price of 50.1 will be stored internally as 5.100000
148
# Ex : a price of 50.1 will be stored internally as 5.100000
189
149
(-)a/t/db_dependent/Acquisition/NewOrder.t (-1 / +86 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 7;
6
use C4::Acquisition;
7
use C4::Biblio;
8
use C4::Bookseller;
9
use C4::Budgets;
10
use MARC::Record;
11
use Koha::DateUtils qw( dt_from_string output_pref );
12
13
my $dbh = C4::Context->dbh;
14
$dbh->{AutoCommit} = 0;
15
$dbh->{RaiseError} = 1;
16
17
my $booksellerid = C4::Bookseller::AddBookseller(
18
    {
19
        name => "my vendor",
20
        address1 => "bookseller's address",
21
        phone => "0123456",
22
        active => 1
23
    }
24
);
25
26
my $basketno = C4::Acquisition::NewBasket(
27
    $booksellerid
28
);
29
30
my $budgetid = C4::Budgets::AddBudget(
31
    {
32
        budget_code => "budget_code_test_getordersbybib",
33
        budget_name => "budget_name_test_getordersbybib",
34
    }
35
);
36
37
my $budget = C4::Budgets::GetBudget( $budgetid );
38
39
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
40
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
41
42
43
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
44
my $ordernumber = eval { C4::Acquisition::NewOrder() };
45
my $return_error = $@;
46
ok(
47
    ( ! defined $ordernumber )
48
      && ( defined $return_error ),
49
    "NewOrder with no params returns undef and croaks"
50
);
51
52
my $mandatoryparams = {
53
    basketno     => $basketno,
54
    quantity     => 24,
55
    biblionumber => $biblionumber1,
56
    budget_id    => $budgetid,
57
};
58
my @mandatoryparams_keys = keys %$mandatoryparams;
59
foreach my $mandatoryparams_key (@mandatoryparams_keys) {
60
    my %test_missing_mandatoryparams = %$mandatoryparams;
61
    delete $test_missing_mandatoryparams{$mandatoryparams_key};
62
    eval {
63
        $ordernumber =
64
          C4::Acquisition::NewOrder( \%test_missing_mandatoryparams );
65
    };
66
    $return_error = $@;
67
    my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
68
    ok(
69
        ( !( defined $ordernumber ) )
70
          && ( index( $return_error, $expected_error ) >= 0 ),
71
"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message"
72
    );
73
}
74
75
$ordernumber = C4::Acquisition::NewOrder(
76
    {
77
        basketno => $basketno,
78
        quantity => 24,
79
        biblionumber => $biblionumber1,
80
        budget_id => $budget->{budget_id},
81
    }
82
);
83
84
my $order = C4::Acquisition::GetOrder( $ordernumber );
85
is( $order->{quantityreceived}, 0, 'NewOrder set quantityreceivedto 0 if undef is given' );
86
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'NewOrder set entrydate to today' );

Return to bug 12826