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

(-)a/Koha/Acquisition/Order.pm (+47 lines)
Lines 264-269 sub duplicate_to { Link Here
264
    return $new_order;
264
    return $new_order;
265
}
265
}
266
266
267
=head3 to_api_mapping
268
269
This method returns the mapping for representing a Koha::Acquisition::Order object
270
on the API.
271
272
=cut
273
274
sub to_api_mapping {
275
    return {
276
        basketno                      => 'basket_id',
277
        biblionumber                  => 'biblio_id',
278
        budget_id                     => 'fund_id',
279
        budgetdate                    => undef,                    # unused
280
        cancellationreason            => 'cancellation_reason',
281
        claimed_date                  => 'last_claim_date',
282
        datecancellationprinted       => 'cancellation_date',
283
        datereceived                  => 'date_received',
284
        discount                      => 'discount_rate',
285
        entrydate                     => 'entry_date',
286
        freight                       => 'shipping_cost',
287
        invoiceid                     => 'invoice_id',
288
        line_item_id                  => undef,                    # EDIFACT related
289
        listprice                     => 'list_price',
290
        order_internalnote            => 'internal_note',
291
        order_vendornote              => 'vendor_note',
292
        ordernumber                   => 'order_id',
293
        orderstatus                   => 'status',
294
        parent_ordernumber            => 'parent_order_id',
295
        purchaseordernumber           => undef,                    # obsolete
296
        quantityreceived              => 'quantity_received',
297
        replacementprice              => 'replacement_price',
298
        sort1                         => 'statistics_1',
299
        sort1_authcat                 => 'statistics_1_authcat',
300
        sort2                         => 'statistics_2',
301
        sort2_authcat                 => 'statistics_2_authcat',
302
        subscriptionid                => 'subscription_id',
303
        suppliers_reference_number    => undef,                    # EDIFACT related
304
        suppliers_reference_qualifier => undef,                    # EDIFACT related
305
        suppliers_report              => undef,                    # EDIFACT related
306
        tax_rate_bak                  => undef,                    # unused
307
        tax_value_bak                 => undef,                    # unused
308
        uncertainprice                => 'uncertain_price',
309
        unitprice                     => 'unit_price',
310
        unitprice_tax_excluded        => 'unit_price_tax_excluded',
311
        unitprice_tax_included        => 'unit_price_tax_included'
312
    };
313
}
267
314
268
=head2 Internal methods
315
=head2 Internal methods
269
316
(-)a/Koha/REST/V1/Acquisitions/Orders.pm (+229 lines)
Line 0 Link Here
1
package Koha::REST::V1::Acquisitions::Orders;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Acquisition::Orders;
23
use Koha::DateUtils;
24
25
use Scalar::Util qw( blessed );
26
use Try::Tiny;
27
28
=head1 NAME
29
30
Koha::REST::V1::Acquisitions::Orders
31
32
=head1 API
33
34
=head2 Methods
35
36
=head3 list
37
38
Controller function that handles listing Koha::Acquisition::Order objects
39
40
=cut
41
42
sub list {
43
44
    my $c = shift->openapi->valid_input or return;
45
46
    return try {
47
        my $orders = $c->objects->search( Koha::Acquisition::Orders->new );
48
49
        return $c->render(
50
            status  => 200,
51
            openapi => $orders
52
        );
53
    }
54
    catch {
55
        if ( $_->isa('Koha::Exceptions::Exception') ) {
56
            return $c->render(
57
                status  => 500,
58
                openapi => { error => "Unhandled exception ($_)" }
59
            );
60
        }
61
        else {
62
            return $c->render(
63
                status  => 500,
64
                openapi => { error => "Something went wrong, check the logs. ($_)" }
65
            );
66
        }
67
    };
68
}
69
70
=head3 get
71
72
Controller function that handles retrieving a single Koha::Aquisition::Order object
73
74
=cut
75
76
sub get {
77
    my $c = shift->openapi->valid_input or return;
78
79
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
80
81
    unless ($order) {
82
        return $c->render(
83
            status  => 404,
84
            openapi => { error => "Order not found" }
85
        );
86
    }
87
88
    my $embed = $c->stash('koha.embed');
89
90
    return $c->render(
91
        status  => 200,
92
        openapi => $order->to_api({ embed => $embed })
93
    );
94
}
95
96
=head3 add
97
98
Controller function that handles adding a new Koha::Acquisition::Order object
99
100
=cut
101
102
sub add {
103
    my $c = shift->openapi->valid_input or return;
104
105
    return try {
106
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
107
        $order->store->discard_changes;
108
109
        $c->res->headers->location(
110
            $c->req->url->to_string . '/' . $order->ordernumber
111
        );
112
113
        return $c->render(
114
            status  => 201,
115
            openapi => $order->to_api
116
        );
117
    }
118
    catch {
119
        unless ( blessed $_ && $_->can('rethrow') ) {
120
            return $c->render(
121
                status  => 500,
122
                openapi => {
123
                    error =>
124
                      "Something went wrong, check Koha logs for details."
125
                }
126
            );
127
        }
128
        if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
129
            return $c->render(
130
                status  => 409,
131
                openapi => { error => $_->error, conflict => $_->duplicate_id }
132
            );
133
        }
134
        else {
135
            return $c->render(
136
                status  => 500,
137
                openapi => { error => "$_" }
138
            );
139
        }
140
    };
141
}
142
143
=head3 update
144
145
Controller function that handles updating a Koha::Acquisition::Order object
146
147
=cut
148
149
sub update {
150
    my $c = shift->openapi->valid_input or return;
151
152
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
153
154
    unless ($order) {
155
        return $c->render(
156
            status  => 404,
157
            openapi => { error => "Order not found" }
158
        );
159
    }
160
161
    return try {
162
        $order->set_from_api( $c->validation->param('body') );
163
        $order->store()->discard_changes;
164
165
        return $c->render(
166
            status  => 200,
167
            openapi => $order->to_api
168
        );
169
    }
170
    catch {
171
        if ( $_->isa('Koha::Exceptions::Exception') ) {
172
            return $c->render(
173
                status  => 500,
174
                openapi => { error => "Unhandled exception ($_)" }
175
            );
176
        }
177
        else {
178
            return $c->render(
179
                status  => 500,
180
                openapi => { error => "Something went wrong, check the logs." }
181
            );
182
        }
183
    };
184
}
185
186
=head3 delete
187
188
Controller function that handles deleting a Koha::Patron object
189
190
=cut
191
192
sub delete {
193
    my $c = shift->openapi->valid_input or return;
194
195
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
196
197
    unless ($order) {
198
        return $c->render(
199
            status  => 404,
200
            openapi => { error => 'Order not found' }
201
        );
202
    }
203
204
    return try {
205
206
        $order->delete;
207
208
        return $c->render(
209
            status  => 204,
210
            openapi => q{}
211
        );
212
    }
213
    catch {
214
        if ( $_->isa('Koha::Exceptions::Exception') ) {
215
            return $c->render(
216
                status  => 500,
217
                openapi => { error => "Unhandled exception ($_)" }
218
            );
219
        }
220
        else {
221
            return $c->render(
222
                status  => 500,
223
                openapi => { error => "Something went wrong, check the logs." }
224
            );
225
        }
226
    };
227
}
228
229
1;
(-)a/Koha/Schema/Result/Aqorder.pm (-1 / +3 lines)
Lines 670-674 sub koha_objects_class { Link Here
670
sub koha_object_class {
670
sub koha_object_class {
671
    'Koha::Acquisition::Order';
671
    'Koha::Acquisition::Order';
672
}
672
}
673
__PACKAGE__->add_columns(
674
    '+uncertainprice' => { is_boolean => 1 }
675
);
673
676
674
1;
677
1;
675
- 

Return to bug 18731