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 Scalar::Util qw( blessed );
26
use Scalar::Util qw( blessed );
Lines 214-219 sub add { Link Here
214
215
215
    return try {
216
    return try {
216
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
217
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
218
219
        my $basket = $order->basket;
220
        unless ($basket) {
221
            Koha::Exceptions::ObjectNotFound->throw();
222
        }
223
224
        my $bookseller = $basket->bookseller;
225
226
        unless (defined $order->tax_rate_on_ordering) {
227
            $order->tax_rate_on_ordering($bookseller->tax_rate || 0);
228
        }
229
        $order->populate_with_prices_for_ordering();
230
231
        unless (defined $order->tax_rate_on_receiving) {
232
            $order->tax_rate_on_receiving($bookseller->tax_rate || 0);
233
        }
234
        $order->populate_with_prices_for_receiving();
235
217
        $order->store->discard_changes;
236
        $order->store->discard_changes;
218
237
219
        $c->res->headers->location(
238
        $c->res->headers->location(
(-)a/t/db_dependent/api/v1/acquisitions_orders.t (-2 / +26 lines)
Lines 248-254 subtest 'get() tests' => sub { Link Here
248
248
249
subtest 'add() tests' => sub {
249
subtest 'add() tests' => sub {
250
250
251
    plan tests => 17;
251
    plan tests => 27;
252
252
253
    $schema->storage->txn_begin;
253
    $schema->storage->txn_begin;
254
254
Lines 330-335 subtest 'add() tests' => sub { Link Here
330
          ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); }
330
          ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); }
331
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
331
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
332
332
333
    # Check that prices are correctly populated
334
    my $order_without_prices = {
335
        basket_id => $order->{basket_id},
336
        biblio_id => $order->{biblio_id},
337
        fund_id => $order->{fund_id},
338
        quantity => 1,
339
        tax_rate_on_ordering => '0.5',
340
        tax_rate_on_receiving => '0.5',
341
        unit_price => 4.20,
342
        rrp => 4.20,
343
        discount_rate => 0.10,
344
    };
345
346
    $order_obj->basket->bookseller->listincgst(0)->invoiceincgst(0)->store();
347
    $t->post_ok("//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order_without_prices)
348
        ->status_is(201)
349
        ->json_is('/tax_value_on_ordering', '2.1')
350
        ->json_is('/tax_value_on_receiving', '2.1')
351
        ->json_is('/rrp_tax_included', '6.3')
352
        ->json_is('/rrp_tax_excluded', '4.2')
353
        ->json_is('/unit_price_tax_included', '6.3')
354
        ->json_is('/unit_price_tax_excluded', '4.2')
355
        ->json_is('/ecost_tax_included', '5.67')
356
        ->json_is('/ecost_tax_excluded', '3.78');
357
333
    $schema->storage->txn_rollback;
358
    $schema->storage->txn_rollback;
334
};
359
};
335
360
336
- 

Return to bug 29959