Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 11897 - Stock Rotation #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion Koha/Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use Koha::IssuingRules;
use Koha::Item::Transfer;
use Koha::Patrons;
use Koha::Libraries;
use Koha::StockRotationItem;
use Koha::StockRotationRotas;

use base qw(Koha::Object);

Expand Down Expand Up @@ -235,7 +237,52 @@ sub current_holds {
return Koha::Holds->_new_from_dbic($hold_rs);
}

=head3 type
=head3 stockrotationitem

my $sritem = Koha::Item->stockrotationitem;

Returns the stock rotation item associated with the current item.

=cut

sub stockrotationitem {
my ( $self ) = @_;
my $rs = $self->_result->stockrotationitem;
return 0 if !$rs;
return Koha::StockRotationItem->_new_from_dbic( $rs );
}

=head3 add_to_rota

my $item = $item->add_to_rota($rota_id);

Add this item to the rota identified by $ROTA_ID, which means associating it
with the first stage of that rota. Should this item already be associated
with a rota, then we will move it to the new rota.

=cut

sub add_to_rota {
my ( $self, $rota_id ) = @_;
Koha::StockRotationRotas->find($rota_id)->add_item($self->itemnumber);
return $self;
}

=head3 biblio

my $biblio = $item->biblio;

Returns the biblio associated with the current item.

=cut

sub biblio {
my ( $self ) = @_;
my $rs = $self->_result->biblio;
return Koha::Biblio->_new_from_dbic( $rs );
}

=head3 _type

=cut

Expand Down
46 changes: 46 additions & 0 deletions Koha/Library.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use Carp;
use C4::Context;

use Koha::Database;
use Koha::StockRotationStages;

use base qw(Koha::Object);

Expand All @@ -41,6 +42,51 @@ TODO: Ask the author to add a proper description

=cut

sub get_categories {
my ( $self, $params ) = @_;
# TODO This should return Koha::LibraryCategories
return $self->{_result}->categorycodes( $params );
}

=head3 update_categories

TODO: Ask the author to add a proper description

=cut

sub update_categories {
my ( $self, $categories ) = @_;
$self->_result->delete_related( 'branchrelations' );
$self->add_to_categories( $categories );
}

=head3 add_to_categories

TODO: Ask the author to add a proper description

=cut

sub add_to_categories {
my ( $self, $categories ) = @_;
for my $category ( @$categories ) {
$self->_result->add_to_categorycodes( $category->_result );
}
}

=head3 stockrotationstages

my $stages = Koha::Library->stockrotationstages;

Returns the stockrotation stages associated with this Library.

=cut

sub stockrotationstages {
my ( $self ) = @_;
my $rs = $self->_result->stockrotationstages;
return Koha::StockRotationStages->_new_from_dbic( $rs );
}

=head3 get_effective_marcorgcode

my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
Expand Down
60 changes: 60 additions & 0 deletions Koha/REST/V1/Stage.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package Koha::REST::V1::Stage;

# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

use Modern::Perl;

use Mojo::Base 'Mojolicious::Controller';

use Koha::StockRotationRotas;
use Koha::StockRotationStages;

=head1 NAME

Koha::REST::V1::Stage

=head2 Operations

=head3 move

Move a stage up or down the stockrotation rota.

=cut

sub move {
my $c = shift->openapi->valid_input or return;
my $input = $c->validation->output;

my $rota = Koha::StockRotationRotas->find( $input->{rota_id} );
my $stage = Koha::StockRotationStages->find( $input->{stage_id} );

if ( $stage && $rota ) {
my $result = $stage->move_to( $input->{position} );
return $c->render( openapi => {}, status => 200 ) if $result;
return $c->render(
openapi => { error => "Bad request - new position invalid" },
status => 400
);
}
else {
return $c->render(
openapi => { error => "Not found - Invalid rota or stage ID" },
status => 404
);
}
}

1;
19 changes: 17 additions & 2 deletions Koha/Schema/Result/Branch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,21 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 stockrotationstages

Type: has_many

Related object: L<Koha::Schema::Result::Stockrotationstage>

=cut

__PACKAGE__->has_many(
"stockrotationstages",
"Koha::Schema::Result::Stockrotationstage",
{ "foreign.branchcode_id" => "self.branchcode" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 transport_cost_frombranches

Type: has_many
Expand Down Expand Up @@ -609,8 +624,8 @@ __PACKAGE__->has_many(
);


# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QOMUFz2EjvAVWCkIpNmvtg
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2018-04-17 16:37:51
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0hfhEZW9VseBN7k05ByvpQ


# You can replace this text with custom code or comments, and it will be preserved on regeneration
Expand Down
19 changes: 17 additions & 2 deletions Koha/Schema/Result/Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,24 @@ __PACKAGE__->might_have(
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 stockrotationitem

# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-18 16:41:12
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CrNXvpDUvvcuPZK2Gfzs/Q
Type: might_have

Related object: L<Koha::Schema::Result::Stockrotationitem>

=cut

__PACKAGE__->might_have(
"stockrotationitem",
"Koha::Schema::Result::Stockrotationitem",
{ "foreign.itemnumber_id" => "self.itemnumber" },
{ cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07046 @ 2018-04-17 16:37:51
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aOcn/Am4XilK4NblfY5zXQ

__PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );

Expand Down
113 changes: 113 additions & 0 deletions Koha/Schema/Result/Stockrotationitem.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use utf8;
package Koha::Schema::Result::Stockrotationitem;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

Koha::Schema::Result::Stockrotationitem

=cut

use strict;
use warnings;

use base 'DBIx::Class::Core';

=head1 TABLE: C<stockrotationitems>

=cut

__PACKAGE__->table("stockrotationitems");

=head1 ACCESSORS

=head2 itemnumber_id

data_type: 'integer'
is_foreign_key: 1
is_nullable: 0

=head2 stage_id

data_type: 'integer'
is_foreign_key: 1
is_nullable: 0

=head2 indemand

data_type: 'tinyint'
default_value: 0
is_nullable: 0

=head2 fresh

data_type: 'tinyint'
default_value: 0
is_nullable: 0

=cut

__PACKAGE__->add_columns(
"itemnumber_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"stage_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"indemand",
{ data_type => "tinyint", default_value => 0, is_nullable => 0 },
"fresh",
{ data_type => "tinyint", default_value => 0, is_nullable => 0 },
);

=head1 PRIMARY KEY

=over 4

=item * L</itemnumber_id>

=back

=cut

__PACKAGE__->set_primary_key("itemnumber_id");

=head1 RELATIONS

=head2 itemnumber

Type: belongs_to

Related object: L<Koha::Schema::Result::Item>

=cut

__PACKAGE__->belongs_to(
"itemnumber",
"Koha::Schema::Result::Item",
{ itemnumber => "itemnumber_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);

=head2 stage

Type: belongs_to

Related object: L<Koha::Schema::Result::Stockrotationstage>

=cut

__PACKAGE__->belongs_to(
"stage",
"Koha::Schema::Result::Stockrotationstage",
{ stage_id => "stage_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);


# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-04 12:16:10
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5IDh4gVR3uzLEdUPBfsHTA


# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
Loading