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

(-)a/Koha/Illrequest.pm (-23 / +43 lines)
Lines 180-194 sub patron { Link Here
180
}
180
}
181
181
182
=head3 status_alias
182
=head3 status_alias
183
Overloaded getter/setter for status_alias,
183
184
that only returns authorised values from the
184
    $Illrequest->status_alias('CUSTOM_AV');
185
correct category
185
186
Overloaded getter/setter for request status_alias,
187
returns authorised values from the correct category,
188
also records the fact that the status has changed
186
189
187
=cut
190
=cut
188
191
189
sub status_alias {
192
sub status_alias {
190
    my ($self, $newval) = @_;
193
    my ($self, $new_status_alias) = @_;
191
    if ($newval) {
194
195
    my $current_status_alias = $self->SUPER::status_alias;
196
197
    if ($new_status_alias) {
198
        # Keep a record of the previous status before we change it,
199
        # we might need it
200
        $self->{previous_status} = $current_status_alias ?
201
            $current_status_alias :
202
            scalar $self->status;
192
        # This is hackery to enable us to undefine
203
        # This is hackery to enable us to undefine
193
        # status_alias, since we need to have an overloaded
204
        # status_alias, since we need to have an overloaded
194
        # status_alias method to get us around the problem described
205
        # status_alias method to get us around the problem described
Lines 196-221 sub status_alias { Link Here
196
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
207
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
197
        # We need a way of accepting implied undef, so we can nullify
208
        # We need a way of accepting implied undef, so we can nullify
198
        # the status_alias column, when called from $self->status
209
        # the status_alias column, when called from $self->status
199
        my $val = $newval eq "-1" ? undef : $newval;
210
        my $val = $new_status_alias eq "-1" ? undef : $new_status_alias;
200
        my $newval = $self->SUPER::status_alias($newval);
211
        my $ret = $self->SUPER::status_alias($val)->store;
201
        if ($newval) {
212
        if ($ret) {
202
            return $newval;
213
            my $logger = Koha::Illrequest::Logger->new;
214
            $logger->log_status_change(
215
                $self,
216
                $new_status_alias
217
            );
203
        } else {
218
        } else {
204
            return;
219
            delete $self->{previous_status};
205
        }
220
        }
206
    }
221
        return $ret;
207
    # We can't know which result is the right one if there are multiple
208
    # ILLSTATUS authorised values with the same authorised_value column value
209
    # so we just use the first
210
    my $alias = Koha::AuthorisedValues->search({
211
        branchcode => $self->branchcode,
212
        category => 'ILLSTATUS',
213
        authorised_value => $self->SUPER::status_alias
214
    })->next;
215
    if ($alias) {
216
        return $alias->authorised_value;
217
    } else {
222
    } else {
218
        return;
223
        # We can't know which result is the right one if there are multiple
224
        # ILLSTATUS authorised values with the same authorised_value column
225
        # value so we just use the first
226
        my $alias = Koha::AuthorisedValues->search({
227
            branchcode => $self->branchcode,
228
            category => 'ILLSTATUS',
229
            authorised_value => $current_status_alias
230
        })->next;
231
        if ($alias) {
232
            return $alias->authorised_value;
233
        } else {
234
            return;
235
        }
219
    }
236
    }
220
}
237
}
221
238
Lines 232-237 sub status { Link Here
232
    my ( $self, $new_status) = @_;
249
    my ( $self, $new_status) = @_;
233
250
234
    my $current_status = $self->SUPER::status;
251
    my $current_status = $self->SUPER::status;
252
    my $current_status_alias = $self->status_alias;
235
253
236
    if ($new_status) {
254
    if ($new_status) {
237
        # This is hackery to enable us to undefine
255
        # This is hackery to enable us to undefine
Lines 244-250 sub status { Link Here
244
        #
262
        #
245
        # Keep a record of the previous status before we change it,
263
        # Keep a record of the previous status before we change it,
246
        # we might need it
264
        # we might need it
247
        $self->{previous_status} = $current_status;
265
        $self->{previous_status} = $current_status_alias ?
266
            $current_status_alias :
267
            $current_status;
248
        my $ret = $self->SUPER::status($new_status)->store;
268
        my $ret = $self->SUPER::status($new_status)->store;
249
        if ($ret) {
269
        if ($ret) {
250
            $self->status_alias("-1");
270
            $self->status_alias("-1");
(-)a/Koha/Illrequest/Logger.pm (+8 lines)
Lines 20-25 package Koha::Illrequest::Logger; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use JSON qw( to_json from_json );
21
use JSON qw( to_json from_json );
22
use Time::Local;
22
use Time::Local;
23
use C4::Koha;
23
use C4::Context;
24
use C4::Context;
24
use C4::Templates;
25
use C4::Templates;
25
use C4::Log qw( logaction GetLogs );
26
use C4::Log qw( logaction GetLogs );
Lines 237-243 sub get_request_logs { Link Here
237
        undef,
238
        undef,
238
        undef
239
        undef
239
    );
240
    );
241
    # Populate a lookup table for status aliases
242
    my $aliases = GetAuthorisedValues('ILLSTATUS');
243
    my $alias_hash;
244
    foreach my $alias(@{$aliases}) {
245
        $alias_hash->{$alias->{id}} = $alias;
246
    }
240
    foreach my $log(@{$logs}) {
247
    foreach my $log(@{$logs}) {
248
        $log->{aliases} = $alias_hash;
241
        $log->{info} = from_json($log->{info});
249
        $log->{info} = from_json($log->{info});
242
        $log->{template} = $self->get_log_template(
250
        $log->{template} = $self->get_log_template(
243
        $request,
251
        $request,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/log/status_change.tt (-2 / +14 lines)
Lines 1-7 Link Here
1
<p>
1
<p>
2
[% log.timestamp | $KohaDates with_hours => 1 %] : <b>Status changed </b>
2
[% log.timestamp | $KohaDates with_hours => 1 %] : <b>Status changed </b>
3
[% IF log.info.status_before %]
3
[% IF log.info.status_before %]
4
from &quot;[% request.capabilities(log.info.status_before).name | html %]&quot;
4
[% before = log.info.status_before %]
5
[%
6
    display_before = log.info.status_before.match('^\d+$') ?
7
        log.aliases.$before.lib :
8
        request.capabilities.$before.name
9
%]
10
from &quot;[% display_before %]&quot;
5
[% END %]
11
[% END %]
6
to &quot;[% request.capabilities(log.info.status_after).name | html %]&quot;
12
[% after = log.info.status_after %]
13
[%
14
    display_after = log.info.status_after.match('^\d+$') ?
15
        log.aliases.$after.lib :
16
        request.capabilities.$after.name;
17
%]
18
to &quot;[% display_after | html %]&quot;
7
</p>
19
</p>
(-)a/t/db_dependent/Illrequest/Logger.t (-30 / +1 lines)
Lines 57-63 use_ok('Koha::Illrequest::Logger'); Link Here
57
57
58
subtest 'Basics' => sub {
58
subtest 'Basics' => sub {
59
59
60
    plan tests => 10;
60
    plan tests => 9;
61
61
62
    $schema->storage->txn_begin;
62
    $schema->storage->txn_begin;
63
63
Lines 120-154 subtest 'Basics' => sub { Link Here
120
        'get_log_template() fetches correct core template'
120
        'get_log_template() fetches correct core template'
121
    );
121
    );
122
122
123
    # get_request_logs
124
    #
125
    my $res_obj = [
126
        {
127
            'template' => 'mock',
128
            'info' => { 'log_origin' => 'core' },
129
            'timestamp' => '2018-10-02 11:12:32',
130
            'action' => 'STATUS_CHANGE'
131
        },
132
        {
133
            'template' => 'mock',
134
            'action' => 'STATUS_CHANGE',
135
            'timestamp' => '2018-10-02 11:12:22',
136
            'info' => { 'log_origin' => 'core' }
137
        },
138
        {
139
            'template' => 'mock',
140
            'action' => 'STATUS_CHANGE',
141
            'info' => { 'log_origin' => 'core' },
142
            'timestamp' => '2018-10-02 11:12:12'
143
        }
144
    ];
145
    my $me_mock = Test::MockModule->new('Koha::Illrequest::Logger');
146
    $me_mock->mock('get_log_template', sub { return 'mock'; });
147
    my $mock_req = Test::MockObject->new();
148
    $mock_req->mock('id', sub { 1 });
149
    is_deeply($logger->get_request_logs($mock_req), $res_obj,
150
		'get_request_logs() returns logs property structured and sorted');
151
152
    $schema->storage->txn_rollback;
123
    $schema->storage->txn_rollback;
153
};
124
};
154
125
(-)a/t/db_dependent/Illrequests.t (-2 / +3 lines)
Lines 39-45 use_ok('Koha::Illrequests'); Link Here
39
39
40
subtest 'Basic object tests' => sub {
40
subtest 'Basic object tests' => sub {
41
41
42
    plan tests => 24;
42
    plan tests => 25;
43
43
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
Lines 62-67 subtest 'Basic object tests' => sub { Link Here
62
       "Branchcode getter works.");
62
       "Branchcode getter works.");
63
    is($illrq_obj->status, $illrq->{status},
63
    is($illrq_obj->status, $illrq->{status},
64
       "Status getter works.");
64
       "Status getter works.");
65
    is($illrq_obj->status_alias, $illrq->{status_alias},
66
       "Status_alias getter works.");
65
    is($illrq_obj->placed, $illrq->{placed},
67
    is($illrq_obj->placed, $illrq->{placed},
66
       "Placed getter works.");
68
       "Placed getter works.");
67
    is($illrq_obj->replied, $illrq->{replied},
69
    is($illrq_obj->replied, $illrq->{replied},
68
- 

Return to bug 20750