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

(-)a/Koha/REST/V1/Acquisitions/Orders.pm (+19 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Acquisition::Orders;
22
use Koha::Acquisition::Orders;
23
use Koha::Exceptions;
23
24
24
use Clone qw( clone );
25
use Clone qw( clone );
25
use JSON;
26
use JSON;
Lines 120-125 sub add { Link Here
120
121
121
    return try {
122
    return try {
122
        my $order = Koha::Acquisition::Order->new_from_api( $c->req->json );
123
        my $order = Koha::Acquisition::Order->new_from_api( $c->req->json );
124
125
        my $basket = $order->basket;
126
        unless ($basket) {
127
            Koha::Exceptions::ObjectNotFound->throw();
128
        }
129
130
        my $bookseller = $basket->bookseller;
131
132
        unless (defined $order->tax_rate_on_ordering) {
133
            $order->tax_rate_on_ordering($bookseller->tax_rate || 0);
134
        }
135
        $order->populate_with_prices_for_ordering();
136
137
        unless (defined $order->tax_rate_on_receiving) {
138
            $order->tax_rate_on_receiving($bookseller->tax_rate || 0);
139
        }
140
        $order->populate_with_prices_for_receiving();
141
123
        $order->store->discard_changes;
142
        $order->store->discard_changes;
124
143
125
        $c->res->headers->location( $c->req->url->to_string . '/' . $order->ordernumber );
144
        $c->res->headers->location( $c->req->url->to_string . '/' . $order->ordernumber );
(-)a/t/db_dependent/api/v1/acquisitions_orders.t (-2 / +26 lines)
Lines 286-292 subtest 'get() tests' => sub { Link Here
286
286
287
subtest 'add() tests' => sub {
287
subtest 'add() tests' => sub {
288
288
289
    plan tests => 17;
289
    plan tests => 27;
290
290
291
    $schema->storage->txn_begin;
291
    $schema->storage->txn_begin;
292
292
Lines 369-374 subtest 'add() tests' => sub { Link Here
369
    }
369
    }
370
    qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
370
    qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
371
371
372
    # Check that prices are correctly populated
373
    my $order_without_prices = {
374
        basket_id => $order->{basket_id},
375
        biblio_id => $order->{biblio_id},
376
        fund_id => $order->{fund_id},
377
        quantity => 1,
378
        tax_rate_on_ordering => '0.5',
379
        tax_rate_on_receiving => '0.5',
380
        unit_price => 4.20,
381
        rrp => 4.20,
382
        discount_rate => 0.10,
383
    };
384
385
    $order_obj->basket->bookseller->listincgst(0)->invoiceincgst(0)->store();
386
    $t->post_ok("//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order_without_prices)
387
        ->status_is(201)
388
        ->json_is('/tax_value_on_ordering', '2.1')
389
        ->json_is('/tax_value_on_receiving', '2.1')
390
        ->json_is('/rrp_tax_included', '6.3')
391
        ->json_is('/rrp_tax_excluded', '4.2')
392
        ->json_is('/unit_price_tax_included', '6.3')
393
        ->json_is('/unit_price_tax_excluded', '4.2')
394
        ->json_is('/ecost_tax_included', '5.67')
395
        ->json_is('/ecost_tax_excluded', '3.78');
396
372
    $schema->storage->txn_rollback;
397
    $schema->storage->txn_rollback;
373
};
398
};
374
399
375
- 

Return to bug 29959