Bug 38010: Embed baskets+count and subscriptions+count

We don't need to whole list of baskets and subscriptions

(cherry picked from commit 391b4d3b32b57c97bfb7e66ab394020ae7eed0e5)

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2025-04-30 15:55:23 +02:00 committed by Katrin Fischer
parent a780f0396f
commit c5819f40a8
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
7 changed files with 50 additions and 34 deletions

View File

@ -122,6 +122,11 @@ properties:
baskets:
type: array
description: List of baskets
baskets_count:
type:
- integer
- "null"
description: Number of linked baskets
subscriptions_count:
type:
- integer
@ -139,6 +144,11 @@ properties:
invoices:
type: array
description: List of invoices
invoices_count:
type:
- integer
- "null"
description: Number of linked invoices
additionalProperties: false
required:
- name
- name

View File

@ -35,9 +35,9 @@
type: string
enum:
- aliases
- baskets
- baskets+count
- subscriptions+count
- invoices
- invoices+count
collectionFormat: csv
responses:
"200":
@ -149,7 +149,7 @@
type: string
enum:
- aliases
- baskets
- baskets+count
- subscriptions+count
- interfaces
- contacts
@ -285,4 +285,4 @@
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
acquisition: vendors_manage
acquisition: vendors_manage

View File

@ -21,7 +21,7 @@ export class AcquisitionAPIClient {
endpoint: "vendors/" + id,
headers: {
"x-koha-embed":
"aliases,subscriptions+count,interfaces,contacts,contracts,baskets",
"aliases,subscriptions+count,interfaces,contacts,contracts,baskets+count",
},
}),
getAll: (query, params) =>
@ -30,7 +30,7 @@ export class AcquisitionAPIClient {
query,
params: { _order_by: "name", ...params },
headers: {
"x-koha-embed": "aliases,baskets",
"x-koha-embed": "aliases,baskets+count",
},
}),
delete: id =>

View File

@ -128,6 +128,7 @@ export default {
delete vendor.physical;
delete vendor.subscriptions_count;
delete vendor.baskets;
delete vendor.baskets_count;
delete vendor.subscriptions;
delete vendor.contracts;

View File

@ -67,7 +67,7 @@ export default {
tableOptions: {
columns: this.getTableColumns(),
options: {
embed: "aliases,baskets,subscriptions+count,invoices",
embed: "aliases,baskets+count,subscriptions+count,invoices+count",
},
url: () => this.tableURL(),
add_filters: true,
@ -89,12 +89,9 @@ export default {
text: this.$__("Delete"),
icon: "fa fa-trash",
should_display: row =>
(!row.baskets ||
row.baskets.length === 0) &&
(!row.subscriptions_count ||
row.subscriptions_count === 0) &&
(!row.invoices ||
row.invoices.length === 0),
row.baskets_count === 0 &&
row.subscriptions_count === 0 &&
row.invoices_count === 0,
},
},
{
@ -103,7 +100,7 @@ export default {
icon: "fa fa-inbox",
should_display: row =>
row.active &&
row.baskets?.length > 0 &&
row.baskets_count > 0 &&
this.isUserPermitted(
"CAN_user_acquisition_order_receive"
),
@ -241,13 +238,13 @@ export default {
searchable: false,
orderable: false,
render(data, type, row, meta) {
return row.baskets.length
return row.baskets_count
? '<a href="/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' +
row.id +
'" class="show">' +
escape_str(
__("%s basket(s)").format(
row.baskets.length
row.baskets_count
)
) +
"</a>"

View File

@ -48,7 +48,7 @@
<ToolbarButton
v-if="
vendor.active &&
vendor.baskets?.length > 0 &&
vendor.baskets_count > 0 &&
isUserPermitted('CAN_user_acquisition_order_receive')
"
:to="{
@ -61,10 +61,9 @@
/>
<a
v-if="
(!vendor.baskets || vendor.baskets.length === 0) &&
(!vendor.subscriptions_count ||
vendor.subscriptions_count === 0) &&
(!vendor.invoices || vendor.invoices.length === 0)
vendor.baskets_count === 0 &&
vendor.subscriptions_count === 0 &&
vendor.invoices_count === 0
"
@click="doDelete(vendor.id, vendor.name)"
class="btn btn-default"

View File

@ -37,7 +37,7 @@ my $t = Test::Mojo->new('Koha::REST::V1');
subtest 'list() and delete() tests | authorized user' => sub {
plan tests => 44;
plan tests => 39;
$schema->storage->txn_begin;
@ -92,23 +92,32 @@ subtest 'list() and delete() tests | authorized user' => sub {
->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' )
->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' );
my @cleanup;
for ( 0 .. 1 ) {
$builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } );
push @cleanup,
$builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } );
push @cleanup,
$builder->build_object(
{ class => 'Koha::Acquisition::Baskets', value => { booksellerid => $vendor->id } } );
push @cleanup,
$builder->build_object(
{ class => 'Koha::Acquisition::Invoices', value => { booksellerid => $vendor->id } } );
}
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => { 'x-koha-embed' => 'subscriptions+count' } )
->status_is(200)->json_has( '/0/subscriptions_count', 'subscriptions_count is embedded' )
->json_is( '/0/subscriptions_count' => '2', 'subscription count is 2' );
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" =>
{ 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )->status_is(200)
->json_is( '/0/subscriptions_count', 2, 'subscriptions_count is 2' )
->json_is( '/0/baskets_count', 2, 'baskets_count is 2' )
->json_is( '/0/invoices_count', 2, 'invoices_count is 2' );
# FIXME We need to add more tests/code here
# A vendor deletion should be rejected if it has baskets or subscriptions (or invoices?) linked to it
$_->delete for @cleanup;
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' )
->content_is( '', 'REST3.3.4' );
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)
->json_like( '/0/name' => qr/$other_vendor_name/ )->json_hasnt( '/1', 'Only one vendor' );
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' );
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)->json_is( [] );
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )->status_is(200);
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(404);
$schema->storage->txn_rollback;
};