Bug 26524: Add Koha::Acquisition::Basket->orders

This patch adds a handy accessor for a basket's orders. It can be used
to embed orders on an API call or be used in controller scripts to
replace C4::* methods.

To test:
1. Apply this patches
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Acquisition/Basket.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2020-09-23 15:56:41 -03:00 committed by Jonathan Druart
parent 00e01c5555
commit 2900cee991
2 changed files with 24 additions and 0 deletions

View file

@ -22,6 +22,7 @@ use Modern::Perl;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::BasketGroups;
use Koha::Acquisition::Orders;
use Koha::Patrons;
use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
@ -77,6 +78,22 @@ sub basket_group {
return Koha::Acquisition::BasketGroup->_new_from_dbic( $basket_group_rs );
}
=head3 orders
my $orders = $basket->orders;
Returns a Koha::Acquisition::Orders resultset, with the orders linked
to this basket.
=cut
sub orders {
my ($self) = @_;
my $orders_rs = $self->_result->orders;
return Koha::Acquisition::Orders->_new_from_dbic( $orders_rs );
}
=head3 effective_create_items
Returns C<create_items> for this basket, falling back to C<AcqCreateItem> if unset.

View file

@ -340,6 +340,13 @@ __PACKAGE__->belongs_to(
},
);
__PACKAGE__->has_many(
"orders",
"Koha::Schema::Result::Aqorder",
{ "foreign.basketno" => "self.basketno" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub koha_object_class {
'Koha::Acquisition::Basket';
}