View | Details | Raw Unified | Return to bug 38010
Collapse All | Expand All

(-)a/api/v1/swagger/definitions/vendor.yaml (-1 / +11 lines)
Lines 122-127 properties: Link Here
122
  baskets:
122
  baskets:
123
    type: array
123
    type: array
124
    description: List of baskets
124
    description: List of baskets
125
  baskets_count:
126
    type:
127
      - integer
128
      - "null"
129
    description: Number of linked baskets
125
  subscriptions_count:
130
  subscriptions_count:
126
    type:
131
    type:
127
      - integer
132
      - integer
Lines 139-144 properties: Link Here
139
  invoices:
144
  invoices:
140
    type: array
145
    type: array
141
    description: List of invoices
146
    description: List of invoices
147
  invoices_count:
148
    type:
149
      - integer
150
      - "null"
151
    description: Number of linked invoices
142
additionalProperties: false
152
additionalProperties: false
143
required:
153
required:
144
  - name
154
  - name
(-)a/api/v1/swagger/paths/acquisitions_vendors.yaml (-4 / +4 lines)
Lines 35-43 Link Here
35
          type: string
35
          type: string
36
          enum:
36
          enum:
37
            - aliases
37
            - aliases
38
            - baskets
38
            - baskets+count
39
            - subscriptions+count
39
            - subscriptions+count
40
            - invoices
40
            - invoices+count
41
        collectionFormat: csv
41
        collectionFormat: csv
42
    responses:
42
    responses:
43
      "200":
43
      "200":
Lines 149-155 Link Here
149
          type: string
149
          type: string
150
          enum:
150
          enum:
151
            - aliases
151
            - aliases
152
            - baskets
152
            - baskets+count
153
            - subscriptions+count
153
            - subscriptions+count
154
            - interfaces
154
            - interfaces
155
            - contacts
155
            - contacts
Lines 285-288 Link Here
285
          $ref: "../swagger.yaml#/definitions/error"
285
          $ref: "../swagger.yaml#/definitions/error"
286
    x-koha-authorization:
286
    x-koha-authorization:
287
      permissions:
287
      permissions:
288
        acquisition: vendors_manage
288
        acquisition: vendors_manage
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/acquisition-api-client.js (-2 / +2 lines)
Lines 21-27 export class AcquisitionAPIClient { Link Here
21
                    endpoint: "vendors/" + id,
21
                    endpoint: "vendors/" + id,
22
                    headers: {
22
                    headers: {
23
                        "x-koha-embed":
23
                        "x-koha-embed":
24
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets",
24
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets+count",
25
                    },
25
                    },
26
                }),
26
                }),
27
            getAll: (query, params) =>
27
            getAll: (query, params) =>
Lines 30-36 export class AcquisitionAPIClient { Link Here
30
                    query,
30
                    query,
31
                    params: { _order_by: "name", ...params },
31
                    params: { _order_by: "name", ...params },
32
                    headers: {
32
                    headers: {
33
                        "x-koha-embed": "aliases,baskets",
33
                        "x-koha-embed": "aliases,baskets+count",
34
                    },
34
                    },
35
                }),
35
                }),
36
            delete: id =>
36
            delete: id =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue (+1 lines)
Lines 128-133 export default { Link Here
128
            delete vendor.physical;
128
            delete vendor.physical;
129
            delete vendor.subscriptions_count;
129
            delete vendor.subscriptions_count;
130
            delete vendor.baskets;
130
            delete vendor.baskets;
131
            delete vendor.baskets_count;
131
            delete vendor.subscriptions;
132
            delete vendor.subscriptions;
132
            delete vendor.contracts;
133
            delete vendor.contracts;
133
134
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorList.vue (-10 / +7 lines)
Lines 67-73 export default { Link Here
67
            tableOptions: {
67
            tableOptions: {
68
                columns: this.getTableColumns(),
68
                columns: this.getTableColumns(),
69
                options: {
69
                options: {
70
                    embed: "aliases,baskets,subscriptions+count,invoices",
70
                    embed: "aliases,baskets+count,subscriptions+count,invoices+count",
71
                },
71
                },
72
                url: () => this.tableURL(),
72
                url: () => this.tableURL(),
73
                add_filters: true,
73
                add_filters: true,
Lines 89-100 export default { Link Here
89
                                text: this.$__("Delete"),
89
                                text: this.$__("Delete"),
90
                                icon: "fa fa-trash",
90
                                icon: "fa fa-trash",
91
                                should_display: row =>
91
                                should_display: row =>
92
                                    (!row.baskets ||
92
                                    row.baskets_count === 0 &&
93
                                        row.baskets.length === 0) &&
93
                                    row.subscriptions_count === 0 &&
94
                                    (!row.subscriptions_count ||
94
                                    row.invoices_count === 0,
95
                                        row.subscriptions_count === 0) &&
96
                                    (!row.invoices ||
97
                                        row.invoices.length === 0),
98
                            },
95
                            },
99
                        },
96
                        },
100
                        {
97
                        {
Lines 103-109 export default { Link Here
103
                                icon: "fa fa-inbox",
100
                                icon: "fa fa-inbox",
104
                                should_display: row =>
101
                                should_display: row =>
105
                                    row.active &&
102
                                    row.active &&
106
                                    row.baskets?.length > 0 &&
103
                                    row.baskets_count > 0 &&
107
                                    this.isUserPermitted(
104
                                    this.isUserPermitted(
108
                                        "CAN_user_acquisition_order_receive"
105
                                        "CAN_user_acquisition_order_receive"
109
                                    ),
106
                                    ),
Lines 241-253 export default { Link Here
241
                    searchable: false,
238
                    searchable: false,
242
                    orderable: false,
239
                    orderable: false,
243
                    render(data, type, row, meta) {
240
                    render(data, type, row, meta) {
244
                        return row.baskets.length
241
                        return row.baskets_count
245
                            ? '<a href="/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' +
242
                            ? '<a href="/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' +
246
                                  row.id +
243
                                  row.id +
247
                                  '" class="show">' +
244
                                  '" class="show">' +
248
                                  escape_str(
245
                                  escape_str(
249
                                      __("%s basket(s)").format(
246
                                      __("%s basket(s)").format(
250
                                          row.baskets.length
247
                                          row.baskets_count
251
                                      )
248
                                      )
252
                                  ) +
249
                                  ) +
253
                                  "</a>"
250
                                  "</a>"
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorShow.vue (-5 / +4 lines)
Lines 48-54 Link Here
48
            <ToolbarButton
48
            <ToolbarButton
49
                v-if="
49
                v-if="
50
                    vendor.active &&
50
                    vendor.active &&
51
                    vendor.baskets?.length > 0 &&
51
                    vendor.baskets_count > 0 &&
52
                    isUserPermitted('CAN_user_acquisition_order_receive')
52
                    isUserPermitted('CAN_user_acquisition_order_receive')
53
                "
53
                "
54
                :to="{
54
                :to="{
Lines 61-70 Link Here
61
            />
61
            />
62
            <a
62
            <a
63
                v-if="
63
                v-if="
64
                    (!vendor.baskets || vendor.baskets.length === 0) &&
64
                    vendor.baskets_count === 0 &&
65
                    (!vendor.subscriptions_count ||
65
                    vendor.subscriptions_count === 0 &&
66
                        vendor.subscriptions_count === 0) &&
66
                    vendor.invoices_count === 0
67
                    (!vendor.invoices || vendor.invoices.length === 0)
68
                "
67
                "
69
                @click="doDelete(vendor.id, vendor.name)"
68
                @click="doDelete(vendor.id, vendor.name)"
70
                class="btn btn-default"
69
                class="btn btn-default"
(-)a/t/db_dependent/api/v1/acquisitions_vendors.t (-13 / +21 lines)
Lines 37-43 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
37
37
38
subtest 'list() and delete() tests | authorized user' => sub {
38
subtest 'list() and delete() tests | authorized user' => sub {
39
39
40
    plan tests => 44;
40
    plan tests => 39;
41
41
42
    $schema->storage->txn_begin;
42
    $schema->storage->txn_begin;
43
43
Lines 92-114 subtest 'list() and delete() tests | authorized user' => sub { Link Here
92
        ->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' )
92
        ->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' )
93
        ->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' );
93
        ->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' );
94
94
95
    my @cleanup;
95
    for ( 0 .. 1 ) {
96
    for ( 0 .. 1 ) {
96
        $builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } );
97
        push @cleanup,
98
            $builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } );
99
        push @cleanup,
100
            $builder->build_object(
101
            { class => 'Koha::Acquisition::Baskets', value => { booksellerid => $vendor->id } } );
102
        push @cleanup,
103
            $builder->build_object(
104
            { class => 'Koha::Acquisition::Invoices', value => { booksellerid => $vendor->id } } );
97
    }
105
    }
98
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => { 'x-koha-embed' => 'subscriptions+count' } )
106
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" =>
99
        ->status_is(200)->json_has( '/0/subscriptions_count', 'subscriptions_count is embedded' )
107
            { 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )->status_is(200)
100
        ->json_is( '/0/subscriptions_count' => '2', 'subscription count is 2' );
108
        ->json_is( '/0/subscriptions_count', 2, 'subscriptions_count is 2' )
109
        ->json_is( '/0/baskets_count',       2, 'baskets_count is 2' )
110
        ->json_is( '/0/invoices_count',      2, 'invoices_count is 2' );
111
112
    # FIXME We need to add more tests/code here
113
    # A vendor deletion should be rejected if it has baskets or subscriptions (or invoices?) linked to it
114
    $_->delete for @cleanup;
101
115
102
    $t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' )
116
    $t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' )
103
        ->content_is( '', 'REST3.3.4' );
117
        ->content_is( '', 'REST3.3.4' );
104
118
105
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)
119
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )->status_is(200);
106
        ->json_like( '/0/name' => qr/$other_vendor_name/ )->json_hasnt( '/1', 'Only one vendor' );
120
    $t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(404);
107
108
    $t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )
109
        ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' );
110
111
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)->json_is( [] );
112
121
113
    $schema->storage->txn_rollback;
122
    $schema->storage->txn_rollback;
114
};
123
};
115
- 

Return to bug 38010