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

(-)a/Koha/ItemType.pm (-1 / +14 lines)
Lines 221-227 on the API. Link Here
221
=cut
221
=cut
222
222
223
sub to_api_mapping {
223
sub to_api_mapping {
224
    return { 'itemtype' => 'item_type_id' };
224
    return {
225
        checkinmsg                   => 'checkin_message',
226
        checkinmsgtype               => 'checkin_message_type',
227
        defaultreplacecost           => 'default_replacement_cost',
228
        hideinopac                   => 'hide_in_opac',
229
        imageurl                     => 'image_url',
230
        itemtype                     => 'item_type_id',
231
        notforloan                   => 'not_for_loan_status',
232
        processfee                   => 'process_fee',
233
        rentalcharge_daily           => 'daily_rental_charge',
234
        rentalcharge_daily_calendar  => 'daily_rental_charge_calendar',
235
        rentalcharge_hourly          => 'hourly_rental_charge',
236
        rentalcharge_hourly_calendar => 'hourly_rental_charge_calendar',
237
    };
225
}
238
}
226
239
227
=head2 Internal methods
240
=head2 Internal methods
(-)a/Koha/Schema/Result/Itemtype.pm (-2 / +4 lines)
Lines 337-345 __PACKAGE__->has_many( Link Here
337
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SoRKIMEqXE2+RkGq6zBejA
337
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SoRKIMEqXE2+RkGq6zBejA
338
338
339
__PACKAGE__->add_columns(
339
__PACKAGE__->add_columns(
340
    '+rentalcharge_hourly_calendar' => { is_boolean => 1 },
341
    '+rentalcharge_daily_calendar'  => { is_boolean => 1 },
342
    '+automatic_checkin'            => { is_boolean => 1 },
340
    '+automatic_checkin'            => { is_boolean => 1 },
341
    '+hideinopac'                   => { is_boolean => 1 },
342
    '+notforloan'                   => { is_boolean => 1 },
343
    '+rentalcharge_daily_calendar'  => { is_boolean => 1 },
344
    '+rentalcharge_hourly_calendar' => { is_boolean => 1 },
343
);
345
);
344
346
345
# Use the ItemtypeLocalization view to create the join on localization
347
# Use the ItemtypeLocalization view to create the join on localization
(-)a/api/v1/swagger/definitions/item_type.yaml (-17 / +15 lines)
Lines 18-55 properties: Link Here
18
    type:
18
    type:
19
      - number
19
      - number
20
      - "null"
20
      - "null"
21
  rentalcharge_daily:
21
  daily_rental_charge:
22
    description: The amount charged for each day between checkout date and due date
22
    description: The amount charged for each day between checkout date and due date
23
    type:
23
    type:
24
      - number
24
      - number
25
      - "null"
25
      - "null"
26
  rentalcharge_daily_calendar:
26
  daily_rental_charge_calendar:
27
    description: Controls if the daily rental fee is calculated directly or using finesCalendar
27
    description: Controls if the daily rental fee is calculated directly or using finesCalendar
28
    type: boolean
28
    type: boolean
29
  rentalcharge_hourly:
29
  hourly_rental_charge:
30
    description: The amount charged for each hour between checkout date and due date
30
    description: The amount charged for each hour between checkout date and due date
31
    type:
31
    type:
32
      - number
32
      - number
33
      - "null"
33
      - "null"
34
  rentalcharge_hourly_calendar:
34
  hourly_rental_charge_calendar:
35
    description: Controls if the hourly rental fee is calculated directly or using finesCalendar
35
    description: Controls if the hourly rental fee is calculated directly or using finesCalendar
36
    type: boolean
36
    type: boolean
37
  defaultreplacecost:
37
  default_replacement_cost:
38
    description: Default replacement cost
38
    description: Default replacement cost
39
    type:
39
    type:
40
      - number
40
      - number
41
      - "null"
41
      - "null"
42
  processfee:
42
  process_fee:
43
    description: Default text be recorded in the column note when the processing fee is applied
43
    description: Default text be recorded in the column note when the processing fee is applied
44
    type:
44
    type:
45
      - number
45
      - number
46
      - "null"
46
      - "null"
47
  notforloan:
47
  not_for_loan_status:
48
    description: Controls if the item is available for loan
48
    description: If items of this type are not for loan
49
    type:
49
    type: boolean
50
      - boolean
50
  image_url:
51
      - "null"
52
  imageurl:
53
    description: URL for the item type icon
51
    description: URL for the item type icon
54
    type:
52
    type:
55
      - string
53
      - string
Lines 59-71 properties: Link Here
59
    type:
57
    type:
60
      - string
58
      - string
61
      - "null"
59
      - "null"
62
  checkinmsg:
60
  checkin_message:
63
    description: Message that is displayed when an item with the given item type is checked in
61
    description: Message that is displayed when an item with the given item type is checked in
64
    type:
62
    type:
65
      - string
63
      - string
66
      - "null"
64
      - "null"
67
  checkinmsgtype:
65
  checkin_message_type:
68
    description: Type (CSS class) for the checkinmsg, can be 'alert' or 'message'
66
    description: Type (CSS class) for the checkin_message, can be 'alert' or 'message'
69
    type:
67
    type:
70
      - string
68
      - string
71
      - "null"
69
      - "null"
Lines 74-80 properties: Link Here
74
    type:
72
    type:
75
      - string
73
      - string
76
      - "null"
74
      - "null"
77
  hideinopac:
75
  hide_in_opac:
78
    description: Hide the item type from the search options in OPAC
76
    description: Hide the item type from the search options in OPAC
79
    type: boolean
77
    type: boolean
80
  searchcategory:
78
  searchcategory:
Lines 86-92 properties: Link Here
86
    description: Controls if automatic checkin is enabled for items of this type
84
    description: Controls if automatic checkin is enabled for items of this type
87
    type: boolean
85
    type: boolean
88
  translated_descriptions:
86
  translated_descriptions:
89
    description: Translations of description plain text
87
    description: Translations of description plain text (x-koha-embed)
90
    type: array
88
    type: array
91
    items:
89
    items:
92
      $ref: "item_type_translated_description.yaml"
90
      $ref: "item_type_translated_description.yaml"
(-)a/t/db_dependent/api/v1/item_types.t (-29 / +18 lines)
Lines 23-28 use Test::Mojo; Link Here
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
26
use Mojo::JSON qw(encode_json);
27
26
use Koha::ItemTypes;
28
use Koha::ItemTypes;
27
use Koha::Database;
29
use Koha::Database;
28
30
Lines 34-40 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
34
36
35
subtest 'list() tests' => sub {
37
subtest 'list() tests' => sub {
36
38
37
    plan tests => 12;
39
    plan tests => 13;
38
40
39
    $schema->storage->txn_begin;
41
    $schema->storage->txn_begin;
40
42
Lines 42-48 subtest 'list() tests' => sub { Link Here
42
        {
44
        {
43
            class => 'Koha::ItemTypes',
45
            class => 'Koha::ItemTypes',
44
            value => {
46
            value => {
45
                itemtype                     => 'TEST_IT',
46
                parent_type                  => undef,
47
                parent_type                  => undef,
47
                description                  => 'Test item type',
48
                description                  => 'Test item type',
48
                rentalcharge                 => 100.0,
49
                rentalcharge                 => 100.0,
Lines 70-76 subtest 'list() tests' => sub { Link Here
70
            class => 'Koha::Localizations',
71
            class => 'Koha::Localizations',
71
            value => {
72
            value => {
72
                entity      => 'itemtypes',
73
                entity      => 'itemtypes',
73
                code        => 'TEST_IT',
74
                code        => $item_type->id,
74
                lang        => 'en',
75
                lang        => 'en',
75
                translation => 'English word "test"',
76
                translation => 'English word "test"',
76
            }
77
            }
Lines 81-87 subtest 'list() tests' => sub { Link Here
81
            class => 'Koha::Localizations',
82
            class => 'Koha::Localizations',
82
            value => {
83
            value => {
83
                entity      => 'itemtypes',
84
                entity      => 'itemtypes',
84
                code        => 'TEST_IT',
85
                code        => $item_type->id,
85
                lang        => 'sv_SE',
86
                lang        => 'sv_SE',
86
                translation => 'Swedish word "test"',
87
                translation => 'Swedish word "test"',
87
            }
88
            }
Lines 109-138 subtest 'list() tests' => sub { Link Here
109
    my $unauth_userid = $patron->userid;
110
    my $unauth_userid = $patron->userid;
110
111
111
    ## Authorized user tests
112
    ## Authorized user tests
112
    $t->get_ok("//$userid:$password@/api/v1/item_types")->status_is(200)->json_has('/0');
113
    my $query = encode_json( { item_type_id => $item_type->id } );
113
114
    $t->get_ok("//$userid:$password@/api/v1/item_types?q=$query")->status_is(200)->json_has('/0')
114
    for my $json ( @{ $t->tx->res->json } ) {
115
        ->json_is( '/0/description', $item_type->description )->json_hasnt('/0/translated_descriptions');
115
        if ( $json->{item_type_id} eq 'TEST_IT' ) {
116
116
            is( $json->{description}, 'Test item type' );
117
    $t->get_ok( "//$userid:$password@/api/v1/item_types?q=$query" => { 'x-koha-embed' => 'translated_descriptions' } )
117
            ok( !exists $json->{translated_descriptions} );
118
        ->status_is(200)->json_has('/0')->json_is( '/0/description', $item_type->description )
118
        }
119
        ->json_has('/0/translated_descriptions')->json_is(
119
    }
120
        '/0/translated_descriptions',
120
121
        [
121
    $t->get_ok( "//$userid:$password@/api/v1/item_types" => { 'x-koha-embed' => 'translated_descriptions' } )
122
            { lang => 'en',    translation => 'English word "test"' },
122
        ->status_is(200)->json_has('/0');
123
            { lang => 'sv_SE', translation => 'Swedish word "test"' },
123
124
        ]
124
    for my $json ( @{ $t->tx->res->json } ) {
125
        );
125
        if ( $json->{item_type_id} eq 'TEST_IT' ) {
126
            is( $json->{description}, 'Test item type' );
127
            is_deeply(
128
                $json->{translated_descriptions},
129
                [
130
                    { lang => 'en',    translation => 'English word "test"' },
131
                    { lang => 'sv_SE', translation => 'Swedish word "test"' },
132
                ]
133
            );
134
        }
135
    }
136
126
137
    # Unauthorized access
127
    # Unauthorized access
138
    $t->get_ok("//$unauth_userid:$password@/api/v1/item_types")->status_is(403);
128
    $t->get_ok("//$unauth_userid:$password@/api/v1/item_types")->status_is(403);
139
- 

Return to bug 34008