Bugzilla – Attachment 129875 Details for
Bug 29959
Populate prices when creating an order with the API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29959: Populate prices when creating an order with the API
Bug-29959-Populate-prices-when-creating-an-order-w.patch (text/plain), 3.61 KB, created by
Julian Maurice
on 2022-01-27 12:58:09 UTC
(
hide
)
Description:
Bug 29959: Populate prices when creating an order with the API
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2022-01-27 12:58:09 UTC
Size:
3.61 KB
patch
obsolete
>From 7ea817ee05b8fcfeca768ad98c52586eacf575f6 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 27 Jan 2022 13:50:52 +0100 >Subject: [PATCH] Bug 29959: Populate prices when creating an order with the > API > >Price columns (aqorders.*_tax_included, aqorders.*_tax_excluded, >aqorders.tax_value_*) are automatically calculated when creating an >order with the staff interface. They should also be automatically >calculated when the order is created with the API. > >Depends on bug 29955 > >Test plan: >1. Run tests in t/db_dependent/api/v1/acquisitions_orders.t >--- > Koha/REST/V1/Acquisitions/Orders.pm | 19 +++++++++++++++ > t/db_dependent/api/v1/acquisitions_orders.t | 27 ++++++++++++++++++++- > 2 files changed, 45 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Acquisitions/Orders.pm b/Koha/REST/V1/Acquisitions/Orders.pm >index d3a7033d2d..d71900cb76 100644 >--- a/Koha/REST/V1/Acquisitions/Orders.pm >+++ b/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 Scalar::Util qw( blessed ); >@@ -214,6 +215,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( >diff --git a/t/db_dependent/api/v1/acquisitions_orders.t b/t/db_dependent/api/v1/acquisitions_orders.t >index 398f918b97..10ded416f4 100755 >--- a/t/db_dependent/api/v1/acquisitions_orders.t >+++ b/t/db_dependent/api/v1/acquisitions_orders.t >@@ -248,7 +248,7 @@ subtest 'get() tests' => sub { > > subtest 'add() tests' => sub { > >- plan tests => 17; >+ plan tests => 27; > > $schema->storage->txn_begin; > >@@ -330,6 +330,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; > }; > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29959
:
129875
|
135437