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 241-246 sub add { Link Here
241
242
242
    return try {
243
    return try {
243
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
244
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
245
246
        my $basket = $order->basket;
247
        unless ($basket) {
248
            Koha::Exceptions::ObjectNotFound->throw();
249
        }
250
251
        my $bookseller = $basket->bookseller;
252
253
        unless (defined $order->tax_rate_on_ordering) {
254
            $order->tax_rate_on_ordering($bookseller->tax_rate || 0);
255
        }
256
        $order->populate_with_prices_for_ordering();
257
258
        unless (defined $order->tax_rate_on_receiving) {
259
            $order->tax_rate_on_receiving($bookseller->tax_rate || 0);
260
        }
261
        $order->populate_with_prices_for_receiving();
262
244
        $order->store->discard_changes;
263
        $order->store->discard_changes;
245
264
246
        $c->res->headers->location(
265
        $c->res->headers->location(
(-)a/t/db_dependent/api/v1/acquisitions_orders.t (-2 / +26 lines)
Lines 272-278 subtest 'get() tests' => sub { Link Here
272
272
273
subtest 'add() tests' => sub {
273
subtest 'add() tests' => sub {
274
274
275
    plan tests => 17;
275
    plan tests => 27;
276
276
277
    $schema->storage->txn_begin;
277
    $schema->storage->txn_begin;
278
278
Lines 354-359 subtest 'add() tests' => sub { Link Here
354
          ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); }
354
          ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); }
355
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
355
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/;
356
356
357
    # Check that prices are correctly populated
358
    my $order_without_prices = {
359
        basket_id => $order->{basket_id},
360
        biblio_id => $order->{biblio_id},
361
        fund_id => $order->{fund_id},
362
        quantity => 1,
363
        tax_rate_on_ordering => '0.5',
364
        tax_rate_on_receiving => '0.5',
365
        unit_price => 4.20,
366
        rrp => 4.20,
367
        discount_rate => 0.10,
368
    };
369
370
    $order_obj->basket->bookseller->listincgst(0)->invoiceincgst(0)->store();
371
    $t->post_ok("//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order_without_prices)
372
        ->status_is(201)
373
        ->json_is('/tax_value_on_ordering', '2.1')
374
        ->json_is('/tax_value_on_receiving', '2.1')
375
        ->json_is('/rrp_tax_included', '6.3')
376
        ->json_is('/rrp_tax_excluded', '4.2')
377
        ->json_is('/unit_price_tax_included', '6.3')
378
        ->json_is('/unit_price_tax_excluded', '4.2')
379
        ->json_is('/ecost_tax_included', '5.67')
380
        ->json_is('/ecost_tax_excluded', '3.78');
381
357
    $schema->storage->txn_rollback;
382
    $schema->storage->txn_rollback;
358
};
383
};
359
384
360
- 

Return to bug 29959