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

(-)a/Koha/Item.pm (-4 / +4 lines)
Lines 30-37 use Koha::IssuingRules; Link Here
30
use Koha::Item::Transfer;
30
use Koha::Item::Transfer;
31
use Koha::Patrons;
31
use Koha::Patrons;
32
use Koha::Libraries;
32
use Koha::Libraries;
33
use Koha::Stockrotationitem;
33
use Koha::StockRotationItem;
34
use Koha::Stockrotationrotas;
34
use Koha::StockRotationRotas;
35
35
36
use base qw(Koha::Object);
36
use base qw(Koha::Object);
37
37
Lines 249-255 sub stockrotationitem { Link Here
249
    my ( $self ) = @_;
249
    my ( $self ) = @_;
250
    my $rs = $self->_result->stockrotationitem;
250
    my $rs = $self->_result->stockrotationitem;
251
    return 0 if !$rs;
251
    return 0 if !$rs;
252
    return Koha::Stockrotationitem->_new_from_dbic( $rs );
252
    return Koha::StockRotationItem->_new_from_dbic( $rs );
253
}
253
}
254
254
255
=head3 add_to_rota
255
=head3 add_to_rota
Lines 264-270 with a rota, then we will move it to the new rota. Link Here
264
264
265
sub add_to_rota {
265
sub add_to_rota {
266
    my ( $self, $rota_id ) = @_;
266
    my ( $self, $rota_id ) = @_;
267
    Koha::Stockrotationrotas->find($rota_id)->add_item($self->itemnumber);
267
    Koha::StockRotationRotas->find($rota_id)->add_item($self->itemnumber);
268
    return $self;
268
    return $self;
269
}
269
}
270
270
(-)a/Koha/Library.pm (-2 / +2 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Stockrotationstages;
25
use Koha::StockRotationStages;
26
26
27
use base qw(Koha::Object);
27
use base qw(Koha::Object);
28
28
Lines 66-72 Returns the stockrotation stages associated with this Library. Link Here
66
sub stockrotationstages {
66
sub stockrotationstages {
67
    my ( $self ) = @_;
67
    my ( $self ) = @_;
68
    my $rs = $self->_result->stockrotationstages;
68
    my $rs = $self->_result->stockrotationstages;
69
    return Koha::Stockrotationstages->_new_from_dbic( $rs );
69
    return Koha::StockRotationStages->_new_from_dbic( $rs );
70
}
70
}
71
71
72
=head3 type
72
=head3 type
(-)a/Koha/REST/V1/Stage.pm (-4 / +4 lines)
Lines 19-32 use Modern::Perl; Link Here
19
19
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Stockrotationrotas;
22
use Koha::StockRotationRotas;
23
use Koha::Stockrotationstages;
23
use Koha::StockRotationStages;
24
24
25
sub move {
25
sub move {
26
    my ($c, $args, $cb) = @_;
26
    my ($c, $args, $cb) = @_;
27
27
28
    my $rota = Koha::Stockrotationrotas->find($args->{rota_id});
28
    my $rota = Koha::StockRotationRotas->find($args->{rota_id});
29
    my $stage = Koha::Stockrotationstages->find($args->{stage_id});
29
    my $stage = Koha::StockRotationStages->find($args->{stage_id});
30
30
31
    if ($stage && $rota) {
31
    if ($stage && $rota) {
32
        my $result = $stage->move_to($args->{position});
32
        my $result = $stage->move_to($args->{position});
(-)a/Koha/Stockrotationitem.pm (-9 / +9 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationitem;
1
package Koha::StockRotationItem;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 25-41 use Koha::Database; Link Here
25
use Koha::DateUtils qw/dt_from_string/;
25
use Koha::DateUtils qw/dt_from_string/;
26
use Koha::Item::Transfer;
26
use Koha::Item::Transfer;
27
use Koha::Item;
27
use Koha::Item;
28
use Koha::Stockrotationstage;
28
use Koha::StockRotationStage;
29
29
30
use base qw(Koha::Object);
30
use base qw(Koha::Object);
31
31
32
=head1 NAME
32
=head1 NAME
33
33
34
Stockrotationitem - Koha Stockrotationitem Object class
34
StockRotationItem - Koha StockRotationItem Object class
35
35
36
=head1 SYNOPSIS
36
=head1 SYNOPSIS
37
37
38
Stockrotationitem class used primarily by stockrotation .pls and the stock
38
StockRotationItem class used primarily by stockrotation .pls and the stock
39
rotation cron script.
39
rotation cron script.
40
40
41
=head1 DESCRIPTION
41
=head1 DESCRIPTION
Lines 58-64 sub _type { Link Here
58
58
59
=head3 itemnumber
59
=head3 itemnumber
60
60
61
  my $item = Koha::Stockrotationitem->itemnumber;
61
  my $item = Koha::StockRotationItem->itemnumber;
62
62
63
Returns the item associated with the current stock rotation item.
63
Returns the item associated with the current stock rotation item.
64
64
Lines 72-78 sub itemnumber { Link Here
72
72
73
=head3 stage
73
=head3 stage
74
74
75
  my $stage = Koha::Stockrotationitem->stage;
75
  my $stage = Koha::StockRotationItem->stage;
76
76
77
Returns the stage associated with the current stock rotation item.
77
Returns the stage associated with the current stock rotation item.
78
78
Lines 81-87 Returns the stage associated with the current stock rotation item. Link Here
81
sub stage {
81
sub stage {
82
    my ( $self ) = @_;
82
    my ( $self ) = @_;
83
    my $rs = $self->_result->stage;
83
    my $rs = $self->_result->stage;
84
    return Koha::Stockrotationstage->_new_from_dbic( $rs );
84
    return Koha::StockRotationStage->_new_from_dbic( $rs );
85
}
85
}
86
86
87
=head3 needs_repatriating
87
=head3 needs_repatriating
Lines 171-177 transfer it to the next stage in its rota. Link Here
171
171
172
If this is the last stage in the rota and this rota is cyclical, we return to
172
If this is the last stage in the rota and this rota is cyclical, we return to
173
the first stage.  If it is not cyclical, then we delete this
173
the first stage.  If it is not cyclical, then we delete this
174
Stockrotationitem.
174
StockRotationItem.
175
175
176
If this item is 'indemand', and advance is invoked, we disable 'indemand' and
176
If this item is 'indemand', and advance is invoked, we disable 'indemand' and
177
advance the item as per usual.
177
advance the item as per usual.
Lines 209-215 sub advance { Link Here
209
                $transfer->tobranch($new_stage->branchcode_id);
209
                $transfer->tobranch($new_stage->branchcode_id);
210
                $transfer->datearrived(DateTime->now);
210
                $transfer->datearrived(DateTime->now);
211
            } else {
211
            } else {
212
                $self->delete;  # Stockrotationitem is done.
212
                $self->delete;  # StockRotationItem is done.
213
                return 1;
213
                return 1;
214
            }
214
            }
215
        } else {
215
        } else {
(-)a/Koha/Stockrotationitems.pm (-6 / +6 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationitems;
1
package Koha::StockRotationItems;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 20-36 package Koha::Stockrotationitems; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Stockrotationitem;
23
use Koha::StockRotationItem;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Stockrotationitems - Koha Stockrotationitems Object class
29
StockRotationItems - Koha StockRotationItems Object class
30
30
31
=head1 SYNOPSIS
31
=head1 SYNOPSIS
32
32
33
Stockrotationitems class used primarily by stockrotation .pls and the stock
33
StockRotationItems class used primarily by stockrotation .pls and the stock
34
rotation cron script.
34
rotation cron script.
35
35
36
=head1 DESCRIPTION
36
=head1 DESCRIPTION
Lines 52-58 sub _type { Link Here
52
}
52
}
53
53
54
sub object_class {
54
sub object_class {
55
    return 'Koha::Stockrotationitem';
55
    return 'Koha::StockRotationItem';
56
}
56
}
57
57
58
=head3 investigate
58
=head3 investigate
Lines 69-75 The report generated here will be used on the stage level to slot our item Link Here
69
reports into appropriate sections of the branched report.
69
reports into appropriate sections of the branched report.
70
70
71
For details of intent and context of this procedure, please see
71
For details of intent and context of this procedure, please see
72
Koha::Stockrotationrota->investigate.
72
Koha::StockRotationRota->investigate.
73
73
74
=cut
74
=cut
75
75
(-)a/Koha/Stockrotationrota.pm (-11 / +11 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationrota;
1
package Koha::StockRotationRota;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 20-38 package Koha::Stockrotationrota; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Stockrotationstages;
23
use Koha::StockRotationStages;
24
use Koha::Stockrotationitem;
24
use Koha::StockRotationItem;
25
use Koha::Stockrotationitems;
25
use Koha::StockRotationItems;
26
26
27
use base qw(Koha::Object);
27
use base qw(Koha::Object);
28
28
29
=head1 NAME
29
=head1 NAME
30
30
31
Stockrotationrota - Koha Stockrotationrota Object class
31
StockRotationRota - Koha StockRotationRota Object class
32
32
33
=head1 SYNOPSIS
33
=head1 SYNOPSIS
34
34
35
Stockrotationrota class used primarily by stockrotation .pls and the stock
35
StockRotationRota class used primarily by stockrotation .pls and the stock
36
rotation cron script.
36
rotation cron script.
37
37
38
=head1 DESCRIPTION
38
=head1 DESCRIPTION
Lines 47-53 Standard Koha::Objects definitions, and additional methods. Link Here
47
47
48
=head3 stockrotationstages
48
=head3 stockrotationstages
49
49
50
  my $stages = Koha::Stockrotationrota->stockrotationstages;
50
  my $stages = Koha::StockRotationRota->stockrotationstages;
51
51
52
Returns the stages associated with the current rota.
52
Returns the stages associated with the current rota.
53
53
Lines 56-62 Returns the stages associated with the current rota. Link Here
56
sub stockrotationstages {
56
sub stockrotationstages {
57
    my ( $self ) = @_;
57
    my ( $self ) = @_;
58
    my $rs = $self->_result->stockrotationstages;
58
    my $rs = $self->_result->stockrotationstages;
59
    return Koha::Stockrotationstages->_new_from_dbic( $rs );
59
    return Koha::StockRotationStages->_new_from_dbic( $rs );
60
}
60
}
61
61
62
=head3 add_item
62
=head3 add_item
Lines 71-82 a rota, move it from that rota to this rota. Link Here
71
71
72
sub add_item {
72
sub add_item {
73
    my ( $self, $itemnumber ) = @_;
73
    my ( $self, $itemnumber ) = @_;
74
    my $sritem = Koha::Stockrotationitems->find($itemnumber);
74
    my $sritem = Koha::StockRotationItems->find($itemnumber);
75
    if ($sritem) {
75
    if ($sritem) {
76
        $sritem->stage_id($self->first_stage->stage_id)
76
        $sritem->stage_id($self->first_stage->stage_id)
77
            ->indemand(0)->fresh(1)->store;
77
            ->indemand(0)->fresh(1)->store;
78
    } else {
78
    } else {
79
        $sritem = Koha::Stockrotationitem->new({
79
        $sritem = Koha::StockRotationItem->new({
80
            itemnumber_id => $itemnumber,
80
            itemnumber_id => $itemnumber,
81
            stage_id      => $self->first_stage->stage_id,
81
            stage_id      => $self->first_stage->stage_id,
82
            indemand      => 0,
82
            indemand      => 0,
Lines 112-118 Return all items associated with this rota via its stages. Link Here
112
112
113
sub stockrotationitems {
113
sub stockrotationitems {
114
    my ( $self ) = @_;
114
    my ( $self ) = @_;
115
    my $rs = Koha::Stockrotationitems->search(
115
    my $rs = Koha::StockRotationItems->search(
116
        { 'stage.rota_id' => $self->rota_id }, { join =>  [ qw/stage/ ] }
116
        { 'stage.rota_id' => $self->rota_id }, { join =>  [ qw/stage/ ] }
117
    );
117
    );
118
    return $rs;
118
    return $rs;
(-)a/Koha/Stockrotationrotas.pm (-6 / +6 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationrotas;
1
package Koha::StockRotationRotas;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 20-36 package Koha::Stockrotationrotas; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Stockrotationrota;
23
use Koha::StockRotationRota;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Stockrotationrotas - Koha Stockrotationrotas Object class
29
StockRotationRotas - Koha StockRotationRotas Object class
30
30
31
=head1 SYNOPSIS
31
=head1 SYNOPSIS
32
32
33
Stockrotationrotas class used primarily by stockrotation .pls and the stock
33
StockRotationRotas class used primarily by stockrotation .pls and the stock
34
rotation cron script.
34
rotation cron script.
35
35
36
=head1 DESCRIPTION
36
=head1 DESCRIPTION
Lines 50-56 Standard Koha::Objects definitions, and additional methods. Link Here
50
Return a report detailing the current status and required actions for all
50
Return a report detailing the current status and required actions for all
51
relevant items spread over rotas.
51
relevant items spread over rotas.
52
52
53
See Koha::Stockrotationrota->investigate for details.
53
See Koha::StockRotationRota->investigate for details.
54
54
55
=cut
55
=cut
56
56
Lines 89-95 sub _type { Link Here
89
}
89
}
90
90
91
sub object_class {
91
sub object_class {
92
    return 'Koha::Stockrotationrota';
92
    return 'Koha::StockRotationRota';
93
}
93
}
94
94
95
1;
95
1;
(-)a/Koha/Stockrotationstage.pm (-17 / +17 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationstage;
1
package Koha::StockRotationStage;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 21-37 use Modern::Perl; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Library;
23
use Koha::Library;
24
use Koha::Stockrotationrota;
24
use Koha::StockRotationRota;
25
25
26
use base qw(Koha::Object);
26
use base qw(Koha::Object);
27
27
28
=head1 NAME
28
=head1 NAME
29
29
30
Stockrotationstage - Koha Stockrotationstage Object class
30
StockRotationStage - Koha StockRotationStage Object class
31
31
32
=head1 SYNOPSIS
32
=head1 SYNOPSIS
33
33
34
Stockrotationstage class used primarily by stockrotation .pls and the stock
34
StockRotationStage class used primarily by stockrotation .pls and the stock
35
rotation cron script.
35
rotation cron script.
36
36
37
=head1 DESCRIPTION
37
=head1 DESCRIPTION
Lines 64-70 sub _relation { Link Here
64
64
65
=head3 stockrotationitems
65
=head3 stockrotationitems
66
66
67
  my $stages = Koha::Stockrotationstage->stockrotationitems;
67
  my $stages = Koha::StockRotationStage->stockrotationitems;
68
68
69
Returns the items associated with the current stage.
69
Returns the items associated with the current stage.
70
70
Lines 72-83 Returns the items associated with the current stage. Link Here
72
72
73
sub stockrotationitems {
73
sub stockrotationitems {
74
    my ( $self ) = @_;
74
    my ( $self ) = @_;
75
    return &{$self->_relation(qw/ stockrotationitems Stockrotationitems /)};
75
    return &{$self->_relation(qw/ stockrotationitems StockRotationItems /)};
76
}
76
}
77
77
78
=head3 branchcode
78
=head3 branchcode
79
79
80
  my $branch = Koha::Stockrotationstage->branchcode;
80
  my $branch = Koha::StockRotationStage->branchcode;
81
81
82
Returns the branch associated with the current stage.
82
Returns the branch associated with the current stage.
83
83
Lines 90-96 sub branchcode { Link Here
90
90
91
=head3 rota
91
=head3 rota
92
92
93
  my $rota = Koha::Stockrotationstage->rota;
93
  my $rota = Koha::StockRotationStage->rota;
94
94
95
Returns the rota associated with the current stage.
95
Returns the rota associated with the current stage.
96
96
Lines 98-104 Returns the rota associated with the current stage. Link Here
98
98
99
sub rota {
99
sub rota {
100
    my ( $self ) = @_;
100
    my ( $self ) = @_;
101
    return &{$self->_relation(qw/ rota Stockrotationrota /)};
101
    return &{$self->_relation(qw/ rota StockRotationRota /)};
102
}
102
}
103
103
104
=head3 siblings
104
=head3 siblings
Lines 111-117 Koha::Object wrapper around DBIx::Class::Ordered. Link Here
111
111
112
sub siblings {
112
sub siblings {
113
    my ( $self ) = @_;
113
    my ( $self ) = @_;
114
    return &{$self->_relation(qw/ siblings Stockrotationstages /)};
114
    return &{$self->_relation(qw/ siblings StockRotationStages /)};
115
}
115
}
116
116
117
=head3 next_siblings
117
=head3 next_siblings
Lines 124-130 Koha::Object wrapper around DBIx::Class::Ordered. Link Here
124
124
125
sub next_siblings {
125
sub next_siblings {
126
    my ( $self ) = @_;
126
    my ( $self ) = @_;
127
    return &{$self->_relation(qw/ next_siblings Stockrotationstages /)};
127
    return &{$self->_relation(qw/ next_siblings StockRotationStages /)};
128
}
128
}
129
129
130
=head3 previous_siblings
130
=head3 previous_siblings
Lines 137-143 Koha::Object wrapper around DBIx::Class::Ordered. Link Here
137
137
138
sub previous_siblings {
138
sub previous_siblings {
139
    my ( $self ) = @_;
139
    my ( $self ) = @_;
140
    return &{$self->_relation(qw/ previous_siblings Stockrotationstages /)};
140
    return &{$self->_relation(qw/ previous_siblings StockRotationStages /)};
141
}
141
}
142
142
143
=head3 next_sibling
143
=head3 next_sibling
Lines 150-156 Koha::Object wrapper around DBIx::Class::Ordered. Link Here
150
150
151
sub next_sibling {
151
sub next_sibling {
152
    my ( $self ) = @_;
152
    my ( $self ) = @_;
153
    return &{$self->_relation(qw/ next_sibling Stockrotationstage /)};
153
    return &{$self->_relation(qw/ next_sibling StockRotationStage /)};
154
}
154
}
155
155
156
=head3 previous_sibling
156
=head3 previous_sibling
Lines 163-169 Koha::Object Wrapper around DBIx::Class::Ordered. Link Here
163
163
164
sub previous_sibling {
164
sub previous_sibling {
165
    my ( $self ) = @_;
165
    my ( $self ) = @_;
166
    return &{$self->_relation(qw/ previous_sibling Stockrotationstage /)};
166
    return &{$self->_relation(qw/ previous_sibling StockRotationStage /)};
167
}
167
}
168
168
169
=head3 first_sibling
169
=head3 first_sibling
Lines 176-182 Koha::Object Wrapper around DBIx::Class::Ordered. Link Here
176
176
177
sub first_sibling {
177
sub first_sibling {
178
    my ( $self ) = @_;
178
    my ( $self ) = @_;
179
    return &{$self->_relation(qw/ first_sibling Stockrotationstage /)};
179
    return &{$self->_relation(qw/ first_sibling StockRotationStage /)};
180
}
180
}
181
181
182
=head3 last_sibling
182
=head3 last_sibling
Lines 189-195 Koha::Object Wrapper around DBIx::Class::Ordered. Link Here
189
189
190
sub last_sibling {
190
sub last_sibling {
191
    my ( $self ) = @_;
191
    my ( $self ) = @_;
192
    return &{$self->_relation(qw/ last_sibling Stockrotationstage /)};
192
    return &{$self->_relation(qw/ last_sibling StockRotationStage /)};
193
}
193
}
194
194
195
=head3 move_previous
195
=head3 move_previous
Lines 294-300 that is passed to it. It slots item reports into the branched and temporary Link Here
294
rota sections of the report.  It also increments a number of counters.
294
rota sections of the report.  It also increments a number of counters.
295
295
296
For details of intent and context of this procedure, please see
296
For details of intent and context of this procedure, please see
297
Koha::Stockrotationrota->investigate.
297
Koha::StockRotationRota->investigate.
298
298
299
=cut
299
=cut
300
300
(-)a/Koha/Stockrotationstages.pm (-6 / +6 lines)
Lines 1-4 Link Here
1
package Koha::Stockrotationstages;
1
package Koha::StockRotationStages;
2
2
3
# Copyright PTFS Europe 2016
3
# Copyright PTFS Europe 2016
4
#
4
#
Lines 20-36 package Koha::Stockrotationstages; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Stockrotationstage;
23
use Koha::StockRotationStage;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
29
Stockrotationstages - Koha Stockrotationstages Object class
29
StockRotationStages - Koha StockRotationStages Object class
30
30
31
=head1 SYNOPSIS
31
=head1 SYNOPSIS
32
32
33
Stockrotationstages class used primarily by stockrotation .pls and the stock
33
StockRotationStages class used primarily by stockrotation .pls and the stock
34
rotation cron script.
34
rotation cron script.
35
35
36
=head1 DESCRIPTION
36
=head1 DESCRIPTION
Lines 51-57 Return a report detailing the current status and required actions for all Link Here
51
relevant items spread over the set of stages.
51
relevant items spread over the set of stages.
52
52
53
For details of intent and context of this procedure, please see
53
For details of intent and context of this procedure, please see
54
Koha::Stockrotationrota->investigate.
54
Koha::StockRotationRota->investigate.
55
55
56
=cut
56
=cut
57
57
Lines 74-80 sub _type { Link Here
74
}
74
}
75
75
76
sub object_class {
76
sub object_class {
77
    return 'Koha::Stockrotationstage';
77
    return 'Koha::StockRotationStage';
78
}
78
}
79
79
80
1;
80
1;
(-)a/Koha/Util/Stockrotation.pm (-7 / +7 lines)
Lines 1-4 Link Here
1
package Koha::Util::Stockrotation;
1
package Koha::Util::StockRotation;
2
2
3
# Module contains subroutines used with Stock Rotation
3
# Module contains subroutines used with Stock Rotation
4
#
4
#
Lines 22-28 package Koha::Util::Stockrotation; Link Here
22
use Modern::Perl;
22
use Modern::Perl;
23
23
24
use Koha::Items;
24
use Koha::Items;
25
use Koha::Stockrotationitems;
25
use Koha::StockRotationItems;
26
use Koha::Database;
26
use Koha::Database;
27
27
28
our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
28
our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
Lines 44-50 BEGIN { Link Here
44
44
45
=head1 NAME
45
=head1 NAME
46
46
47
Koha::Util::Stockrotation - utility class with routines for Stock Rotation
47
Koha::Util::StockRotation - utility class with routines for Stock Rotation
48
48
49
=head1 FUNCTIONS
49
=head1 FUNCTIONS
50
50
Lines 66-72 sub get_branches { Link Here
66
66
67
=head2 get_stages
67
=head2 get_stages
68
68
69
    returns an arrayref of Stockrotationstage objects representing
69
    returns an arrayref of StockRotationStage objects representing
70
    all stages for a passed rota
70
    all stages for a passed rota
71
71
72
=cut
72
=cut
Lines 100-106 sub toggle_indemand { Link Here
100
    my ($item_id, $stage_id) = @_;
100
    my ($item_id, $stage_id) = @_;
101
101
102
    # Get the item object
102
    # Get the item object
103
    my $item = Koha::Stockrotationitems->find(
103
    my $item = Koha::StockRotationItems->find(
104
        {
104
        {
105
            itemnumber_id => $item_id,
105
            itemnumber_id => $item_id,
106
            stage_id      => $stage_id
106
            stage_id      => $stage_id
Lines 126-132 sub move_to_next_stage { Link Here
126
    my ($item_id, $stage_id) = shift;
126
    my ($item_id, $stage_id) = shift;
127
127
128
    # Get the item object
128
    # Get the item object
129
    my $item = Koha::Stockrotationitems->find(
129
    my $item = Koha::StockRotationItems->find(
130
        {
130
        {
131
            itemnumber_id => $item_id,
131
            itemnumber_id => $item_id,
132
            stage_id      => $stage_id
132
            stage_id      => $stage_id
Lines 148-154 sub remove_from_stage { Link Here
148
    my ($item_id, $stage_id) = @_;
148
    my ($item_id, $stage_id) = @_;
149
149
150
    # Get the item object and delete it
150
    # Get the item object and delete it
151
    Koha::Stockrotationitems->find(
151
    Koha::StockRotationItems->find(
152
        {
152
        {
153
            itemnumber_id => $item_id,
153
            itemnumber_id => $item_id,
154
            stage_id      => $stage_id
154
            stage_id      => $stage_id
(-)a/catalogue/stockrotation.pl (-4 / +4 lines)
Lines 33-41 use C4::Search; Link Here
33
33
34
use Koha::Biblio;
34
use Koha::Biblio;
35
use Koha::Item;
35
use Koha::Item;
36
use Koha::Stockrotationrotas;
36
use Koha::StockRotationRotas;
37
use Koha::Stockrotationstages;
37
use Koha::StockRotationStages;
38
use Koha::Util::Stockrotation qw(:ALL);
38
use Koha::Util::StockRotation qw(:ALL);
39
39
40
my $input = new CGI;
40
my $input = new CGI;
41
41
Lines 63-69 if (!defined $op) { Link Here
63
    my $items = $biblio->items;
63
    my $items = $biblio->items;
64
64
65
    # Get only rotas with stages
65
    # Get only rotas with stages
66
    my $rotas = Koha::Stockrotationrotas->search(
66
    my $rotas = Koha::StockRotationRotas->search(
67
        {
67
        {
68
            'stockrotationstages.stage_id' => { '!=', undef }
68
            'stockrotationstages.stage_id' => { '!=', undef }
69
        },
69
        },
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-2 / +2 lines)
Lines 813-819 Circulation: Link Here
813
                  yes: Enable
813
                  yes: Enable
814
                  no: Disable
814
                  no: Disable
815
            - "housebound module"
815
            - "housebound module"
816
    Stockrotation module:
816
    Stock Rotation module:
817
        -
817
        -
818
            - pref: StockRotation
818
            - pref: StockRotation
819
              choices:
819
              choices:
Lines 825-831 Circulation: Link Here
825
              choices:
825
              choices:
826
                  yes: Enable
826
                  yes: Enable
827
                  no: Disable
827
                  no: Disable
828
            - "Prevent branchtransfers on items in stockrotation rotas"
828
            - "Prevent branchtransfers on items in stock rotation rotas"
829
    Article Requests:
829
    Article Requests:
830
        -
830
        -
831
            - pref: ArticleRequests
831
            - pref: ArticleRequests
(-)a/misc/cronjobs/stockrotation.pl (-2 / +2 lines)
Lines 112-118 use Getopt::Long qw/HelpMessage :config gnu_getopt/; Link Here
112
use Mail::Sendmail;
112
use Mail::Sendmail;
113
use C4::Context;
113
use C4::Context;
114
use Koha::Email;
114
use Koha::Email;
115
use Koha::Stockrotationrotas;
115
use Koha::StockRotationRotas;
116
116
117
my $admin_email = '';
117
my $admin_email = '';
118
my $branch = 0;
118
my $branch = 0;
Lines 464-470 sub emit { Link Here
464
#### Main Code
464
#### Main Code
465
465
466
# Compile Stockrotation Report data
466
# Compile Stockrotation Report data
467
my $rotas = Koha::Stockrotationrotas->search;
467
my $rotas = Koha::StockRotationRotas->search;
468
my $data = $rotas->investigate;
468
my $data = $rotas->investigate;
469
469
470
# Perform db updates if requested
470
# Perform db updates if requested
(-)a/t/db_dependent/Items.t (-5 / +5 lines)
Lines 796-802 subtest 'Check stockrotationitem relationship' => sub { Link Here
796
    });
796
    });
797
797
798
    my $sritem = Koha::Items->find($item->{itemnumber})->stockrotationitem;
798
    my $sritem = Koha::Items->find($item->{itemnumber})->stockrotationitem;
799
    isa_ok( $sritem, 'Koha::Stockrotationitem', "Relationship works and correctly creates Koha::Object." );
799
    isa_ok( $sritem, 'Koha::StockRotationItem', "Relationship works and correctly creates Koha::Object." );
800
800
801
    $schema->storage->txn_rollback;
801
    $schema->storage->txn_rollback;
802
};
802
};
Lines 809-815 subtest 'Check add_to_rota method' => sub { Link Here
809
    my $builder = t::lib::TestBuilder->new;
809
    my $builder = t::lib::TestBuilder->new;
810
    my $item = $builder->build({ source => 'Item' });
810
    my $item = $builder->build({ source => 'Item' });
811
    my $rota = $builder->build({ source => 'Stockrotationrota' });
811
    my $rota = $builder->build({ source => 'Stockrotationrota' });
812
    my $srrota = Koha::Stockrotationrotas->find($rota->{rota_id});
812
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
813
813
814
    $builder->build({
814
    $builder->build({
815
        source => 'Stockrotationstage',
815
        source => 'Stockrotationstage',
Lines 820-833 subtest 'Check add_to_rota method' => sub { Link Here
820
    $sritem->add_to_rota($rota->{rota_id});
820
    $sritem->add_to_rota($rota->{rota_id});
821
821
822
    is(
822
    is(
823
        Koha::Stockrotationitems->find($item->{itemnumber})->stage_id,
823
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
824
        $srrota->stockrotationstages->next->stage_id,
824
        $srrota->stockrotationstages->next->stage_id,
825
        "Adding to a rota a new sritem item being assigned to its first stage."
825
        "Adding to a rota a new sritem item being assigned to its first stage."
826
    );
826
    );
827
827
828
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
828
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
829
829
830
    my $srnewrota = Koha::Stockrotationrotas->find($newrota->{rota_id});
830
    my $srnewrota = Koha::StockRotationRotas->find($newrota->{rota_id});
831
831
832
    $builder->build({
832
    $builder->build({
833
        source => 'Stockrotationstage',
833
        source => 'Stockrotationstage',
Lines 837-843 subtest 'Check add_to_rota method' => sub { Link Here
837
    $sritem->add_to_rota($newrota->{rota_id});
837
    $sritem->add_to_rota($newrota->{rota_id});
838
838
839
    is(
839
    is(
840
        Koha::Stockrotationitems->find($item->{itemnumber})->stage_id,
840
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
841
        $srnewrota->stockrotationstages->next->stage_id,
841
        $srnewrota->stockrotationstages->next->stage_id,
842
        "Moving an item results in that sritem being assigned to the new first stage."
842
        "Moving an item results in that sritem being assigned to the new first stage."
843
    );
843
    );
(-)a/t/db_dependent/Koha/Libraries.t (-1 / +1 lines)
Lines 107-113 my $srstages = Koha::Libraries->find($new_library_sr->{branchcode}) Link Here
107
    ->stockrotationstages;
107
    ->stockrotationstages;
108
is( $srstages->count, 3, 'Correctly fetched stockrotationstages associated with this branch');
108
is( $srstages->count, 3, 'Correctly fetched stockrotationstages associated with this branch');
109
109
110
isa_ok( $srstages->next, 'Koha::Stockrotationstage', "Relationship correctly creates Koha::Objects." );
110
isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly creates Koha::Objects." );
111
111
112
$schema->storage->txn_rollback;
112
$schema->storage->txn_rollback;
113
1;
113
1;
(-)a/t/db_dependent/Stockrotationitems.t (-24 / +24 lines)
Lines 29-36 use Test::More tests => 8; Link Here
29
29
30
my $schema = Koha::Database->new->schema;
30
my $schema = Koha::Database->new->schema;
31
31
32
use_ok('Koha::Stockrotationitems');
32
use_ok('Koha::StockRotationItems');
33
use_ok('Koha::Stockrotationitem');
33
use_ok('Koha::StockRotationItem');
34
34
35
my $builder = t::lib::TestBuilder->new;
35
my $builder = t::lib::TestBuilder->new;
36
36
Lines 51-60 subtest 'Basic object tests' => sub { Link Here
51
        },
51
        },
52
    });
52
    });
53
53
54
    my $sritem = Koha::Stockrotationitems->find($item->{itemnumber_id});
54
    my $sritem = Koha::StockRotationItems->find($item->{itemnumber_id});
55
    isa_ok(
55
    isa_ok(
56
        $sritem,
56
        $sritem,
57
        'Koha::Stockrotationitem',
57
        'Koha::StockRotationItem',
58
        "Correctly create and load a stock rotation item."
58
        "Correctly create and load a stock rotation item."
59
    );
59
    );
60
60
Lines 63-69 subtest 'Basic object tests' => sub { Link Here
63
    is( $sritem->itemnumber->itemnumber, $itm->{itemnumber}, "Related rota OK." );
63
    is( $sritem->itemnumber->itemnumber, $itm->{itemnumber}, "Related rota OK." );
64
64
65
    # Relationship to stage
65
    # Relationship to stage
66
    isa_ok( $sritem->stage, 'Koha::Stockrotationstage', "Fetched related stage." );
66
    isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." );
67
    is( $sritem->stage->stage_id, $stage->{stage_id}, "Related stage OK." );
67
    is( $sritem->stage->stage_id, $stage->{stage_id}, "Related stage OK." );
68
68
69
69
Lines 78-84 subtest 'Tests for needs_repatriating' => sub { Link Here
78
78
79
    # Setup a pristine stockrotation context.
79
    # Setup a pristine stockrotation context.
80
    my $sritem = $builder->build({ source => 'Stockrotationitem' });
80
    my $sritem = $builder->build({ source => 'Stockrotationitem' });
81
    my $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
81
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
82
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
82
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
83
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
83
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
84
    $dbitem->stage->position(1);
84
    $dbitem->stage->position(1);
Lines 113-119 subtest 'Tests for needs_repatriating' => sub { Link Here
113
    # - homebranch != stockrotationstage.branch & not in transit [1]
113
    # - homebranch != stockrotationstage.branch & not in transit [1]
114
    is(
114
    is(
115
        $dbitem->needs_repatriating, 1,
115
        $dbitem->needs_repatriating, 1,
116
        "Homebranch != Stockrotationstage.Branchcode_id & not in transit."
116
        "Homebranch != StockRotationStage.Branchcode_id & not in transit."
117
    );
117
    );
118
118
119
    # Set to in transit (by implication).
119
    # Set to in transit (by implication).
Lines 131-137 subtest "Tests for repatriate." => sub { Link Here
131
    plan tests => 3;
131
    plan tests => 3;
132
    $schema->storage->txn_begin;
132
    $schema->storage->txn_begin;
133
    my $sritem = $builder->build({ source => 'Stockrotationitem' });
133
    my $sritem = $builder->build({ source => 'Stockrotationitem' });
134
    my $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
134
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
135
    $dbitem->stage->position(1);
135
    $dbitem->stage->position(1);
136
    $dbitem->stage->duration(50);
136
    $dbitem->stage->duration(50);
137
    my $branch = $builder->build({ source => 'Branch' });
137
    my $branch = $builder->build({ source => 'Branch' });
Lines 155-161 subtest "Tests for needs_advancing." => sub { Link Here
155
        source => 'Stockrotationitem',
155
        source => 'Stockrotationitem',
156
        value  => { 'fresh' => 1, },
156
        value  => { 'fresh' => 1, },
157
    });
157
    });
158
    my $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
158
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
159
    is($dbitem->needs_advancing, 1, "An item that is fresh will always need advancing.");
159
    is($dbitem->needs_advancing, 1, "An item that is fresh will always need advancing.");
160
160
161
    # Setup a pristine stockrotation context.
161
    # Setup a pristine stockrotation context.
Lines 163-169 subtest "Tests for needs_advancing." => sub { Link Here
163
        source => 'Stockrotationitem',
163
        source => 'Stockrotationitem',
164
        value => { 'fresh' => 0,}
164
        value => { 'fresh' => 0,}
165
    });
165
    });
166
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
166
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
167
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
167
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
168
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
168
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
169
    $dbitem->stage->position(1);
169
    $dbitem->stage->position(1);
Lines 213-219 subtest "Tests for advance." => sub { Link Here
213
        source => 'Stockrotationitem',
213
        source => 'Stockrotationitem',
214
        value => { 'fresh' => 1 }
214
        value => { 'fresh' => 1 }
215
    });
215
    });
216
    my $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
216
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
217
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
217
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
218
    my $dbstage = $dbitem->stage;
218
    my $dbstage = $dbitem->stage;
219
    $dbstage->position(1)->duration(50)->store; # Configure stage.
219
    $dbstage->position(1)->duration(50)->store; # Configure stage.
Lines 233-246 subtest "Tests for advance." => sub { Link Here
233
    $dbstage->rota->cyclical(1)->store;         # Set Rota to cyclical.
233
    $dbstage->rota->cyclical(1)->store;         # Set Rota to cyclical.
234
    ok($dbitem->advance, "Single stage cyclical advance done.");
234
    ok($dbitem->advance, "Single stage cyclical advance done.");
235
    ## Refetch dbitem
235
    ## Refetch dbitem
236
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
236
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
237
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Single stage cyclical stage OK.");
237
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Single stage cyclical stage OK.");
238
238
239
    # Test with indemand advance
239
    # Test with indemand advance
240
    $dbitem->indemand(1)->store;
240
    $dbitem->indemand(1)->store;
241
    ok($dbitem->advance, "Indemand item advance done.");
241
    ok($dbitem->advance, "Indemand item advance done.");
242
    ## Refetch dbitem
242
    ## Refetch dbitem
243
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
243
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
244
    is($dbitem->indemand, 0, "Indemand OK.");
244
    is($dbitem->indemand, 0, "Indemand OK.");
245
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Indemand item advance stage OK.");
245
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Indemand item advance stage OK.");
246
246
Lines 249-262 subtest "Tests for advance." => sub { Link Here
249
        source => 'Stockrotationstage',
249
        source => 'Stockrotationstage',
250
        values => { duration => 50 }
250
        values => { duration => 50 }
251
    });
251
    });
252
    my $dbstage2 = Koha::Stockrotationstages->find($srstage->{stage_id});
252
    my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id});
253
    $dbstage2->move_to_group($dbitem->stage->rota_id);
253
    $dbstage2->move_to_group($dbitem->stage->rota_id);
254
    $dbstage2->move_last;
254
    $dbstage2->move_last;
255
255
256
    # Test a straight up advance
256
    # Test a straight up advance
257
    ok($dbitem->advance, "Advancement done.");
257
    ok($dbitem->advance, "Advancement done.");
258
    ## Refetch dbitem
258
    ## Refetch dbitem
259
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
259
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
260
    ## Test results
260
    ## Test results
261
    is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated.");
261
    is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated.");
262
    my $intransfer = $dbitem->itemnumber->get_transfer;
262
    my $intransfer = $dbitem->itemnumber->get_transfer;
Lines 273-280 subtest "Tests for advance." => sub { Link Here
273
    # Advance again, Remove from rota.
273
    # Advance again, Remove from rota.
274
    ok($dbitem->advance, "Non-cyclical advance.");
274
    ok($dbitem->advance, "Non-cyclical advance.");
275
    ## Refetch dbitem
275
    ## Refetch dbitem
276
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
276
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
277
    is($dbitem, undef, "Stockrotationitem has been removed.");
277
    is($dbitem, undef, "StockRotationItem has been removed.");
278
278
279
    $schema->storage->txn_rollback;
279
    $schema->storage->txn_rollback;
280
};
280
};
Lines 285-296 subtest "Tests for investigate (singular)." => sub { Link Here
285
285
286
    # Test brand new item's investigation ['initiation']
286
    # Test brand new item's investigation ['initiation']
287
    my $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } });
287
    my $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } });
288
    my $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
288
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
289
    is($dbitem->investigate->{reason}, 'initiation', "fresh item initiates.");
289
    is($dbitem->investigate->{reason}, 'initiation', "fresh item initiates.");
290
290
291
    # Test brand new item at stagebranch ['initiation']
291
    # Test brand new item at stagebranch ['initiation']
292
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } });
292
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } });
293
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
293
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
294
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
294
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
295
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
295
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
296
    is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates.");
296
    is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates.");
Lines 300-306 subtest "Tests for investigate (singular)." => sub { Link Here
300
        source => 'Stockrotationitem',
300
        source => 'Stockrotationitem',
301
        value => { 'fresh'       => 0,}
301
        value => { 'fresh'       => 0,}
302
    });
302
    });
303
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
303
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
304
    my $dbtransfer = Koha::Item::Transfer->new({
304
    my $dbtransfer = Koha::Item::Transfer->new({
305
        'itemnumber'  => $dbitem->itemnumber_id,
305
        'itemnumber'  => $dbitem->itemnumber_id,
306
        'frombranch'  => $dbitem->itemnumber->homebranch,
306
        'frombranch'  => $dbitem->itemnumber->homebranch,
Lines 316-322 subtest "Tests for investigate (singular)." => sub { Link Here
316
        source => 'Stockrotationitem',
316
        source => 'Stockrotationitem',
317
        value => { 'fresh'       => 0,}
317
        value => { 'fresh'       => 0,}
318
    });
318
    });
319
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
319
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
320
    $dbtransfer = Koha::Item::Transfer->new({
320
    $dbtransfer = Koha::Item::Transfer->new({
321
        'itemnumber'  => $dbitem->itemnumber_id,
321
        'itemnumber'  => $dbitem->itemnumber_id,
322
        'frombranch'  => $dbitem->itemnumber->homebranch,
322
        'frombranch'  => $dbitem->itemnumber->homebranch,
Lines 331-337 subtest "Tests for investigate (singular)." => sub { Link Here
331
331
332
    # Test item due for advancement ['advancement']
332
    # Test item due for advancement ['advancement']
333
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
333
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
334
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
334
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
335
    $dbitem->indemand(0)->store;
335
    $dbitem->indemand(0)->store;
336
    $dbitem->stage->duration(50)->store;
336
    $dbitem->stage->duration(50)->store;
337
    my $sent_duration =  DateTime::Duration->new( days => 55);
337
    my $sent_duration =  DateTime::Duration->new( days => 55);
Lines 351-357 subtest "Tests for investigate (singular)." => sub { Link Here
351
351
352
    # Test item due for advancement but in-demand ['in-demand']
352
    # Test item due for advancement but in-demand ['in-demand']
353
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
353
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
354
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
354
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
355
    $dbitem->indemand(1)->store;
355
    $dbitem->indemand(1)->store;
356
    $dbitem->stage->duration(50)->store;
356
    $dbitem->stage->duration(50)->store;
357
    $sent_duration =  DateTime::Duration->new( days => 55);
357
    $sent_duration =  DateTime::Duration->new( days => 55);
Lines 371-377 subtest "Tests for investigate (singular)." => sub { Link Here
371
371
372
    # Test item ready for advancement, but at wrong library ['repatriation']
372
    # Test item ready for advancement, but at wrong library ['repatriation']
373
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
373
    $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } });
374
    $dbitem = Koha::Stockrotationitems->find($sritem->{itemnumber_id});
374
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
375
    $dbitem->indemand(0)->store;
375
    $dbitem->indemand(0)->store;
376
    $dbitem->stage->duration(50)->store;
376
    $dbitem->stage->duration(50)->store;
377
    $sent_duration =  DateTime::Duration->new( days => 55);
377
    $sent_duration =  DateTime::Duration->new( days => 55);
(-)a/t/db_dependent/Stockrotationrotas.t (-12 / +12 lines)
Lines 26-33 use Test::More tests => 5; Link Here
26
26
27
my $schema = Koha::Database->new->schema;
27
my $schema = Koha::Database->new->schema;
28
28
29
use_ok('Koha::Stockrotationrotas');
29
use_ok('Koha::StockRotationRotas');
30
use_ok('Koha::Stockrotationrota');
30
use_ok('Koha::StockRotationRota');
31
31
32
subtest 'Basic object tests' => sub {
32
subtest 'Basic object tests' => sub {
33
33
Lines 39-48 subtest 'Basic object tests' => sub { Link Here
39
39
40
    my $rota = $builder->build({ source => 'Stockrotationrota' });
40
    my $rota = $builder->build({ source => 'Stockrotationrota' });
41
41
42
    my $srrota = Koha::Stockrotationrotas->find($rota->{rota_id});
42
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
43
    isa_ok(
43
    isa_ok(
44
        $srrota,
44
        $srrota,
45
        'Koha::Stockrotationrota',
45
        'Koha::StockRotationRota',
46
        "Correctly create and load a stock rotation rota."
46
        "Correctly create and load a stock rotation rota."
47
    );
47
    );
48
48
Lines 62-68 subtest 'Basic object tests' => sub { Link Here
62
    my $srstages = $srrota->stockrotationstages;
62
    my $srstages = $srrota->stockrotationstages;
63
    is( $srstages->count, 3, 'Correctly fetched stockrotationstages associated with this rota');
63
    is( $srstages->count, 3, 'Correctly fetched stockrotationstages associated with this rota');
64
64
65
    isa_ok( $srstages->next, 'Koha::Stockrotationstage', "Relationship correctly creates Koha::Objects." );
65
    isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly creates Koha::Objects." );
66
66
67
    #### Test add_item
67
    #### Test add_item
68
68
Lines 71-84 subtest 'Basic object tests' => sub { Link Here
71
    $srrota->add_item($item->{itemnumber});
71
    $srrota->add_item($item->{itemnumber});
72
72
73
    is(
73
    is(
74
        Koha::Stockrotationitems->find($item->{itemnumber})->stage_id,
74
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
75
        $srrota->first_stage->stage_id,
75
        $srrota->first_stage->stage_id,
76
        "Adding an item results in a new sritem item being assigned to the first stage."
76
        "Adding an item results in a new sritem item being assigned to the first stage."
77
    );
77
    );
78
78
79
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
79
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
80
80
81
    my $srnewrota = Koha::Stockrotationrotas->find($newrota->{rota_id});
81
    my $srnewrota = Koha::StockRotationRotas->find($newrota->{rota_id});
82
82
83
    $builder->build({
83
    $builder->build({
84
        source => 'Stockrotationstage',
84
        source => 'Stockrotationstage',
Lines 88-94 subtest 'Basic object tests' => sub { Link Here
88
    $srnewrota->add_item($item->{itemnumber});
88
    $srnewrota->add_item($item->{itemnumber});
89
89
90
    is(
90
    is(
91
        Koha::Stockrotationitems->find($item->{itemnumber})->stage_id,
91
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
92
        $srnewrota->stockrotationstages->next->stage_id,
92
        $srnewrota->stockrotationstages->next->stage_id,
93
        "Moving an item results in that sritem being assigned to the new first stage."
93
        "Moving an item results in that sritem being assigned to the new first stage."
94
    );
94
    );
Lines 118-132 subtest '->first_stage test' => sub { Link Here
118
        value  => { rota_id => $rota->{rota_id} },
118
        value  => { rota_id => $rota->{rota_id} },
119
    });
119
    });
120
120
121
    my $srrota = Koha::Stockrotationrotas->find($rota->{rota_id});
121
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
122
    my $srstage2 = Koha::Stockrotationstages->find($stage2->{stage_id});
122
    my $srstage2 = Koha::StockRotationStages->find($stage2->{stage_id});
123
    my $firststage = $srstage2->first_sibling || $srstage2;
123
    my $firststage = $srstage2->first_sibling || $srstage2;
124
124
125
    is( $srrota->first_stage->stage_id, $firststage->stage_id, "First stage works" );
125
    is( $srrota->first_stage->stage_id, $firststage->stage_id, "First stage works" );
126
126
127
    $srstage2->move_first;
127
    $srstage2->move_first;
128
128
129
    is( Koha::Stockrotationrotas->find($rota->{rota_id})->first_stage->stage_id, $stage2->{stage_id}, "Stage re-organized" );
129
    is( Koha::StockRotationRotas->find($rota->{rota_id})->first_stage->stage_id, $stage2->{stage_id}, "Stage re-organized" );
130
130
131
    $schema->storage->txn_rollback;
131
    $schema->storage->txn_rollback;
132
};
132
};
Lines 162-168 subtest '->items test' => sub { Link Here
162
        $stage3->{stage_id}, $stage3->{stage_id},
162
        $stage3->{stage_id}, $stage3->{stage_id},
163
    );
163
    );
164
164
165
    my $srrota = Koha::Stockrotationrotas->find($rota->{rota_id});
165
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
166
166
167
    is(
167
    is(
168
        $srrota->stockrotationitems->count,
168
        $srrota->stockrotationitems->count,
(-)a/t/db_dependent/Stockrotationstages.t (-17 / +17 lines)
Lines 26-33 use Test::More tests => 6; Link Here
26
26
27
my $schema = Koha::Database->new->schema;
27
my $schema = Koha::Database->new->schema;
28
28
29
use_ok('Koha::Stockrotationstages');
29
use_ok('Koha::StockRotationStages');
30
use_ok('Koha::Stockrotationstage');
30
use_ok('Koha::StockRotationStage');
31
31
32
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
33
33
Lines 46-55 subtest 'Basic object tests' => sub { Link Here
46
        },
46
        },
47
    });
47
    });
48
48
49
    my $srstage = Koha::Stockrotationstages->find($stage->{stage_id});
49
    my $srstage = Koha::StockRotationStages->find($stage->{stage_id});
50
    isa_ok(
50
    isa_ok(
51
        $srstage,
51
        $srstage,
52
        'Koha::Stockrotationstage',
52
        'Koha::StockRotationStage',
53
        "Correctly create and load a stock rotation stage."
53
        "Correctly create and load a stock rotation stage."
54
    );
54
    );
55
55
Lines 58-64 subtest 'Basic object tests' => sub { Link Here
58
    is( $srstage->branchcode->branchcode, $library->{branchcode}, "Related branch OK." );
58
    is( $srstage->branchcode->branchcode, $library->{branchcode}, "Related branch OK." );
59
59
60
    # Relationship to rota
60
    # Relationship to rota
61
    isa_ok( $srstage->rota, 'Koha::Stockrotationrota', "Fetched related rota." );
61
    isa_ok( $srstage->rota, 'Koha::StockRotationRota', "Fetched related rota." );
62
    is( $srstage->rota->rota_id, $rota->{rota_id}, "Related rota OK." );
62
    is( $srstage->rota->rota_id, $rota->{rota_id}, "Related rota OK." );
63
63
64
    $schema->storage->txn_rollback;
64
    $schema->storage->txn_rollback;
Lines 92-98 subtest 'DBIx::Class::Ordered tests' => sub { Link Here
92
        value    => { rota_id  => $rota->{rota_id}, position => 5 }
92
        value    => { rota_id  => $rota->{rota_id}, position => 5 }
93
    });
93
    });
94
94
95
    my $srstage = Koha::Stockrotationstages->find($stage->{stage_id});
95
    my $srstage = Koha::StockRotationStages->find($stage->{stage_id});
96
96
97
    is($srstage->siblings->count, 4, "Siblings works.");
97
    is($srstage->siblings->count, 4, "Siblings works.");
98
    is($srstage->previous_siblings->count, 2, "Previous Siblings works.");
98
    is($srstage->previous_siblings->count, 2, "Previous Siblings works.");
Lines 107-113 subtest 'DBIx::Class::Ordered tests' => sub { Link Here
107
    # Test plain relations:
107
    # Test plain relations:
108
    while ( my ( $srxsr, $check ) = each %{$map} ) {
108
    while ( my ( $srxsr, $check ) = each %{$map} ) {
109
        my $sr = $srstage->$srxsr;
109
        my $sr = $srstage->$srxsr;
110
        isa_ok($sr, 'Koha::Stockrotationstage', "Fetched using '$srxsr'.");
110
        isa_ok($sr, 'Koha::StockRotationStage', "Fetched using '$srxsr'.");
111
        is($sr->stage_id, $check->{stage_id}, "'$srxsr' data is correct.");
111
        is($sr->stage_id, $check->{stage_id}, "'$srxsr' data is correct.");
112
    };
112
    };
113
113
Lines 146-157 subtest 'DBIx::Class::Ordered tests' => sub { Link Here
146
    # Group manipulation
146
    # Group manipulation
147
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
147
    my $newrota = $builder->build({ source => 'Stockrotationrota' });
148
    ok($srstage->move_to_group($newrota->{rota_id}), "Move to Group.");
148
    ok($srstage->move_to_group($newrota->{rota_id}), "Move to Group.");
149
    is(Koha::Stockrotationstages->find($srstage->stage_id)->rota_id, $newrota->{rota_id}, "Moved correctly.");
149
    is(Koha::StockRotationStages->find($srstage->stage_id)->rota_id, $newrota->{rota_id}, "Moved correctly.");
150
150
151
    # Delete in ordered context
151
    # Delete in ordered context
152
    ok($srstage->delete, "Deleted OK.");
152
    ok($srstage->delete, "Deleted OK.");
153
    is(
153
    is(
154
        Koha::Stockrotationstages->find($stageprevious)->next_sibling->stage_id,
154
        Koha::StockRotationStages->find($stageprevious)->next_sibling->stage_id,
155
        $stagenext->{stage_id},
155
        $stagenext->{stage_id},
156
        "Delete, correctly re-ordered."
156
        "Delete, correctly re-ordered."
157
    );
157
    );
Lines 178-184 subtest 'Relationship to stockrotationitems' => sub { Link Here
178
        value  => { stage_id => $stage->{stage_id} },
178
        value  => { stage_id => $stage->{stage_id} },
179
    });
179
    });
180
180
181
    my $srstage = Koha::Stockrotationstages->find($stage->{stage_id});
181
    my $srstage = Koha::StockRotationStages->find($stage->{stage_id});
182
    my $sritems = $srstage->stockrotationitems;
182
    my $sritems = $srstage->stockrotationitems;
183
    is(
183
    is(
184
        $sritems->count, 3,
184
        $sritems->count, 3,
Lines 186-192 subtest 'Relationship to stockrotationitems' => sub { Link Here
186
    );
186
    );
187
187
188
    isa_ok(
188
    isa_ok(
189
        $sritems->next, 'Koha::Stockrotationitem',
189
        $sritems->next, 'Koha::StockRotationItem',
190
        "Relationship correctly creates Koha::Objects."
190
        "Relationship correctly creates Koha::Objects."
191
    );
191
    );
192
192
Lines 200-206 subtest 'Tests for investigate (singular)' => sub { Link Here
200
200
201
    # In this subtest series we will primarily be testing whether items end up
201
    # In this subtest series we will primarily be testing whether items end up
202
    # in the correct 'branched' section of the stage-report.  We don't care
202
    # in the correct 'branched' section of the stage-report.  We don't care
203
    # for item reasons here, as they are tested in Stockrotationitems.
203
    # for item reasons here, as they are tested in StockRotationItems.
204
204
205
    # We will run tests on first on an empty report (the base-case) and then
205
    # We will run tests on first on an empty report (the base-case) and then
206
    # on a populated report.
206
    # on a populated report.
Lines 291-303 subtest 'Tests for investigate (singular)' => sub { Link Here
291
                    fresh    => 1,
291
                    fresh    => 1,
292
                }
292
                }
293
            });
293
            });
294
            my $dbitem = Koha::Stockrotationitems->find($item);
294
            my $dbitem = Koha::StockRotationItems->find($item);
295
            $dbitem->itemnumber->homebranch($code)
295
            $dbitem->itemnumber->homebranch($code)
296
                ->holdingbranch($code)->store;
296
                ->holdingbranch($code)->store;
297
            $cnt++;
297
            $cnt++;
298
        }
298
        }
299
    }
299
    }
300
    my $report = Koha::Stockrotationstages
300
    my $report = Koha::StockRotationStages
301
        ->find($stage1->{stage_id})->investigate;
301
        ->find($stage1->{stage_id})->investigate;
302
    my $results = [];
302
    my $results = [];
303
    foreach my $lib ( @{$libraries} ) {
303
    foreach my $lib ( @{$libraries} ) {
Lines 330-343 subtest 'Tests for investigate (singular)' => sub { Link Here
330
                    fresh => 1,
330
                    fresh => 1,
331
                }
331
                }
332
            });
332
            });
333
            my $dbitem = Koha::Stockrotationitems->find($item);
333
            my $dbitem = Koha::StockRotationItems->find($item);
334
            $dbitem->itemnumber->homebranch($code)
334
            $dbitem->itemnumber->homebranch($code)
335
                ->holdingbranch($code)->store;
335
                ->holdingbranch($code)->store;
336
            $cnt++;
336
            $cnt++;
337
        }
337
        }
338
    }
338
    }
339
339
340
    $report = Koha::Stockrotationstages
340
    $report = Koha::StockRotationStages
341
        ->find($stage2->{stage_id})->investigate($report);
341
        ->find($stage2->{stage_id})->investigate($report);
342
    $results = [];
342
    $results = [];
343
    foreach my $lib ( @{$libraries} ) {
343
    foreach my $lib ( @{$libraries} ) {
Lines 358-364 subtest 'Tests for investigate (singular)' => sub { Link Here
358
        }
358
        }
359
    }
359
    }
360
360
361
    $report = Koha::Stockrotationstages
361
    $report = Koha::StockRotationStages
362
        ->find($stage1->{stage_id})->investigate;
362
        ->find($stage1->{stage_id})->investigate;
363
    $results = [];
363
    $results = [];
364
    foreach my $lib ( @{$libraries} ) {
364
    foreach my $lib ( @{$libraries} ) {
(-)a/t/db_dependent/api/v1/stockrotationstage.t (-1 / +1 lines)
Lines 25-31 use t::lib::TestBuilder; Link Here
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use C4::Auth;
27
use C4::Auth;
28
use Koha::Stockrotationstages;
28
use Koha::StockRotationStages;
29
29
30
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
(-)a/tools/stockrotation.pl (-18 / +17 lines)
Lines 31-41 use C4::Auth; Link Here
31
use C4::Output;
31
use C4::Output;
32
32
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Stockrotationrotas;
34
use Koha::StockRotationRotas;
35
use Koha::Stockrotationitems;
35
use Koha::StockRotationItems;
36
use Koha::Stockrotationstages;
36
use Koha::StockRotationStages;
37
use Koha::Item;
37
use Koha::Item;
38
use Koha::Util::Stockrotation qw(:ALL);
38
use Koha::Util::StockRotation qw(:ALL);
39
39
40
my $input = new CGI;
40
my $input = new CGI;
41
41
Lines 58-64 my $op = $params{op}; Link Here
58
if (!defined $op) {
58
if (!defined $op) {
59
59
60
    # No operation is supplied, we're just displaying the list of rotas
60
    # No operation is supplied, we're just displaying the list of rotas
61
    my $rotas = Koha::Stockrotationrotas->search->as_list;
61
    my $rotas = Koha::StockRotationRotas->search->as_list;
62
62
63
    $template->param(
63
    $template->param(
64
        existing_rotas => $rotas,
64
        existing_rotas => $rotas,
Lines 84-90 if (!defined $op) { Link Here
84
    } else {
84
    } else {
85
85
86
        # ID supplied, we're editing an existing rota
86
        # ID supplied, we're editing an existing rota
87
        $rota = Koha::Stockrotationrotas->find($rota_id);
87
        $rota = Koha::StockRotationRotas->find($rota_id);
88
88
89
    }
89
    }
90
90
Lines 96-102 if (!defined $op) { Link Here
96
} elsif ($op eq 'toggle_rota') {
96
} elsif ($op eq 'toggle_rota') {
97
97
98
    # Find and update the active status of the rota
98
    # Find and update the active status of the rota
99
    my $rota = Koha::Stockrotationrotas->find($params{rota_id});
99
    my $rota = Koha::StockRotationRotas->find($params{rota_id});
100
100
101
    my $new_active = ($rota->active == 1) ? 0 : 1;
101
    my $new_active = ($rota->active == 1) ? 0 : 1;
102
102
Lines 128-134 if (!defined $op) { Link Here
128
128
129
} elsif ($op eq 'manage_stages') {
129
} elsif ($op eq 'manage_stages') {
130
130
131
    my $rota = Koha::Stockrotationrotas->find($params{rota_id});
131
    my $rota = Koha::StockRotationRotas->find($params{rota_id});
132
132
133
    $template->param(
133
    $template->param(
134
        rota            => $rota,
134
        rota            => $rota,
Lines 158-164 if (!defined $op) { Link Here
158
    } else {
158
    } else {
159
159
160
        # ID supplied, we're editing an existing stage
160
        # ID supplied, we're editing an existing stage
161
        my $stage = Koha::Stockrotationstages->find($stage_id);
161
        my $stage = Koha::StockRotationStages->find($stage_id);
162
162
163
        $template->param(
163
        $template->param(
164
            branches => get_branches(),
164
            branches => get_branches(),
Lines 182-188 if (!defined $op) { Link Here
182
} elsif ($op eq 'confirm_delete_stage') {
182
} elsif ($op eq 'confirm_delete_stage') {
183
183
184
    # Get the stage we're deleting
184
    # Get the stage we're deleting
185
    my $stage = Koha::Stockrotationstages->find($params{stage_id});
185
    my $stage = Koha::StockRotationStages->find($params{stage_id});
186
186
187
    $template->param(
187
    $template->param(
188
        op    => $op,
188
        op    => $op,
Lines 192-198 if (!defined $op) { Link Here
192
} elsif ($op eq 'delete_stage') {
192
} elsif ($op eq 'delete_stage') {
193
193
194
    # Get the stage we're deleting
194
    # Get the stage we're deleting
195
    my $stage = Koha::Stockrotationstages->find($params{stage_id});
195
    my $stage = Koha::StockRotationStages->find($params{stage_id});
196
196
197
    # Get the ID of the rota with which this stage is associated
197
    # Get the ID of the rota with which this stage is associated
198
    # (so we can return to the "Manage stages" page after deletion)
198
    # (so we can return to the "Manage stages" page after deletion)
Lines 234-244 if (!defined $op) { Link Here
234
234
235
} elsif ($op eq 'manage_items') {
235
} elsif ($op eq 'manage_items') {
236
236
237
    my $rota = Koha::Stockrotationrotas->find($params{rota_id});
237
    my $rota = Koha::StockRotationRotas->find($params{rota_id});
238
238
239
    # Get all items on this rota, for each prefetch their
239
    # Get all items on this rota, for each prefetch their
240
    # stage and biblio objects
240
    # stage and biblio objects
241
    my $items = Koha::Stockrotationitems->search(
241
    my $items = Koha::StockRotationItems->search(
242
        { 'stage.rota_id' => $params{rota_id} },
242
        { 'stage.rota_id' => $params{rota_id} },
243
        {
243
        {
244
            prefetch => {
244
            prefetch => {
Lines 430-436 sub process_rota { Link Here
430
430
431
    # Passed validation
431
    # Passed validation
432
    # Find the rota we're updating
432
    # Find the rota we're updating
433
    my $rota = Koha::Stockrotationrotas->find($sub_rota->{id});
433
    my $rota = Koha::StockRotationRotas->find($sub_rota->{id});
434
434
435
    if ($rota) {
435
    if ($rota) {
436
436
Lines 446-452 sub process_rota { Link Here
446
446
447
    } else {
447
    } else {
448
448
449
        $rota = Koha::Stockrotationrota->new({
449
        $rota = Koha::StockRotationRota->new({
450
            title       => $sub_rota->{title},
450
            title       => $sub_rota->{title},
451
            cyclical    => $sub_rota->{cyclical},
451
            cyclical    => $sub_rota->{cyclical},
452
            active      => $sub_rota->{active},
452
            active      => $sub_rota->{active},
Lines 487-493 sub process_stage { Link Here
487
487
488
    # Passed validation
488
    # Passed validation
489
    # Find the stage we're updating
489
    # Find the stage we're updating
490
    my $stage = Koha::Stockrotationstages->find($sub_stage->{stage_id});
490
    my $stage = Koha::StockRotationStages->find($sub_stage->{stage_id});
491
491
492
    if ($stage) {
492
    if ($stage) {
493
493
Lines 501-507 sub process_stage { Link Here
501
    } else {
501
    } else {
502
502
503
        # Creating a new stage
503
        # Creating a new stage
504
        $stage = Koha::Stockrotationstage->new({
504
        $stage = Koha::StockRotationStage->new({
505
            branchcode_id  => $sub_stage->{branchcode},
505
            branchcode_id  => $sub_stage->{branchcode},
506
            rota_id        => $rota_id,
506
            rota_id        => $rota_id,
507
            duration       => $sub_stage->{duration}
507
            duration       => $sub_stage->{duration}
508
- 

Return to bug 11897