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

(-)a/Koha/Illrequest.pm (-2 / +41 lines)
Lines 171-176 sub patron { Link Here
171
    );
171
    );
172
}
172
}
173
173
174
=head3 status_alias
175
176
    $Illrequest->status_alias(143);
177
178
Overloaded getter/setter for request status_alias,
179
also records the fact that the status has changed
180
181
=cut
182
183
sub status_alias {
184
    my ($self, $new_status_alias) = @_;
185
186
    my $current_status_alias = $self->SUPER::status_alias;
187
188
    if ($new_status_alias) {
189
        # Keep a record of the previous status before we change it,
190
        # we might need it
191
        $self->{previous_status} = $current_status_alias ?
192
            $current_status_alias :
193
            scalar $self->status;
194
        my $ret = $self->SUPER::status_alias($new_status_alias)->store;
195
        if ($ret) {
196
            my $logger = Koha::Illrequest::Logger->new;
197
            $logger->log_status_change(
198
                $self,
199
                $new_status_alias
200
            );
201
        } else {
202
            delete $self->{previous_status};
203
        }
204
        return $ret;
205
    } else {
206
        return $current_status_alias;
207
    }
208
}
209
174
=head3 status
210
=head3 status
175
211
176
    $Illrequest->status('CANREQ');
212
    $Illrequest->status('CANREQ');
Lines 184-197 sub status { Link Here
184
    my ( $self, $new_status) = @_;
220
    my ( $self, $new_status) = @_;
185
221
186
    my $current_status = $self->SUPER::status;
222
    my $current_status = $self->SUPER::status;
223
    my $current_status_alias = $self->SUPER::status_alias;
187
224
188
    if ($new_status) {
225
    if ($new_status) {
189
        # Keep a record of the previous status before we change it,
226
        # Keep a record of the previous status before we change it,
190
        # we might need it
227
        # we might need it
191
        $self->{previous_status} = $current_status;
228
        $self->{previous_status} = $current_status_alias ?
229
            $current_status_alias :
230
            $current_status;
192
        my $ret = $self->SUPER::status($new_status)->store;
231
        my $ret = $self->SUPER::status($new_status)->store;
193
        if ($ret) {
232
        if ($ret) {
194
            $self->status_alias(undef);
233
            $self->SUPER::status_alias(undef);
195
            my $logger = Koha::Illrequest::Logger->new;
234
            my $logger = Koha::Illrequest::Logger->new;
196
            $logger->log_status_change(
235
            $logger->log_status_change(
197
                $self,
236
                $self,
(-)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