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

(-)a/Koha/Illrequest.pm (-9 / +29 lines)
Lines 180-194 sub patron { Link Here
180
}
180
}
181
181
182
=head3 status_alias
182
=head3 status_alias
183
184
    $Illrequest->status_alias(143);
185
183
Overloaded getter/setter for status_alias,
186
Overloaded getter/setter for status_alias,
184
that only returns authorised values from the
187
that only returns authorised values from the
185
correct category
188
correct category and 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-208 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($val);
211
        my $ret = $self->SUPER::status_alias($val);
201
        if ($newval) {
212
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
202
            return $newval;
213
        if ($ret) {
214
            my $logger = Koha::Illrequest::Logger->new;
215
            $logger->log_status_change(
216
                $self,
217
                $val_to_log
218
            );
203
        } else {
219
        } else {
204
            return;
220
            delete $self->{previous_status};
205
        }
221
        }
222
        return $ret;
206
    }
223
    }
207
    # We can't know which result is the right one if there are multiple
224
    # 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
225
    # ILLSTATUS authorised values with the same authorised_value column value
Lines 232-242 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->SUPER::status_alias;
235
253
236
    if ($new_status) {
254
    if ($new_status) {
237
        # Keep a record of the previous status before we change it,
255
        # Keep a record of the previous status before we change it,
238
        # we might need it
256
        # we might need it
239
        $self->{previous_status} = $current_status;
257
        $self->{previous_status} = $current_status_alias ?
258
            $current_status_alias :
259
            $current_status;
240
        my $ret = $self->SUPER::status($new_status)->store;
260
        my $ret = $self->SUPER::status($new_status)->store;
241
        if ($ret) {
261
        if ($ret) {
242
            # This is hackery to enable us to undefine
262
            # This is hackery to enable us to undefine
(-)a/Koha/Illrequest/Logger.pm (+8 lines)
Lines 21-26 use Modern::Perl; Link Here
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
23
24
use C4::Koha;
24
use C4::Context;
25
use C4::Context;
25
use C4::Templates;
26
use C4::Templates;
26
use C4::Log qw( logaction GetLogs );
27
use C4::Log qw( logaction GetLogs );
Lines 238-244 sub get_request_logs { Link Here
238
        undef,
239
        undef,
239
        undef
240
        undef
240
    );
241
    );
242
    # Populate a lookup table for status aliases
243
    my $aliases = GetAuthorisedValues('ILLSTATUS');
244
    my $alias_hash;
245
    foreach my $alias(@{$aliases}) {
246
        $alias_hash->{$alias->{id}} = $alias;
247
    }
241
    foreach my $log(@{$logs}) {
248
    foreach my $log(@{$logs}) {
249
        $log->{aliases} = $alias_hash;
242
        $log->{info} = from_json($log->{info});
250
        $log->{info} = from_json($log->{info});
243
        $log->{template} = $self->get_log_template(
251
        $log->{template} = $self->get_log_template(
244
        $request,
252
        $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