@@ -, +, @@ API --- Koha/REST/V1/Acquisitions/Orders.pm | 19 +++++++++++++++ t/db_dependent/api/v1/acquisitions_orders.t | 27 ++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) --- a/Koha/REST/V1/Acquisitions/Orders.pm +++ a/Koha/REST/V1/Acquisitions/Orders.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::Acquisition::Orders; +use Koha::Exceptions; use Clone qw( clone ); use JSON; @@ -241,6 +242,24 @@ sub add { return try { my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') ); + + my $basket = $order->basket; + unless ($basket) { + Koha::Exceptions::ObjectNotFound->throw(); + } + + my $bookseller = $basket->bookseller; + + unless (defined $order->tax_rate_on_ordering) { + $order->tax_rate_on_ordering($bookseller->tax_rate || 0); + } + $order->populate_with_prices_for_ordering(); + + unless (defined $order->tax_rate_on_receiving) { + $order->tax_rate_on_receiving($bookseller->tax_rate || 0); + } + $order->populate_with_prices_for_receiving(); + $order->store->discard_changes; $c->res->headers->location( --- a/t/db_dependent/api/v1/acquisitions_orders.t +++ a/t/db_dependent/api/v1/acquisitions_orders.t @@ -272,7 +272,7 @@ subtest 'get() tests' => sub { subtest 'add() tests' => sub { - plan tests => 17; + plan tests => 27; $schema->storage->txn_begin; @@ -354,6 +354,31 @@ subtest 'add() tests' => sub { ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); } qr/DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/; + # Check that prices are correctly populated + my $order_without_prices = { + basket_id => $order->{basket_id}, + biblio_id => $order->{biblio_id}, + fund_id => $order->{fund_id}, + quantity => 1, + tax_rate_on_ordering => '0.5', + tax_rate_on_receiving => '0.5', + unit_price => 4.20, + rrp => 4.20, + discount_rate => 0.10, + }; + + $order_obj->basket->bookseller->listincgst(0)->invoiceincgst(0)->store(); + $t->post_ok("//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order_without_prices) + ->status_is(201) + ->json_is('/tax_value_on_ordering', '2.1') + ->json_is('/tax_value_on_receiving', '2.1') + ->json_is('/rrp_tax_included', '6.3') + ->json_is('/rrp_tax_excluded', '4.2') + ->json_is('/unit_price_tax_included', '6.3') + ->json_is('/unit_price_tax_excluded', '4.2') + ->json_is('/ecost_tax_included', '5.67') + ->json_is('/ecost_tax_excluded', '3.78'); + $schema->storage->txn_rollback; }; --