@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Acquisition/Order.t --- Koha/Acquisition/Order.pm | 30 +++++++++++++++--------- Koha/Schema/Result/Aqorder.pm | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) --- a/Koha/Acquisition/Order.pm +++ a/Koha/Acquisition/Order.pm @@ -113,43 +113,48 @@ sub add_item { =head3 basket - my $basket = Koha::Acquisition::Orders->find( $id )->basket; + my $basket = $order->basket; -Returns the basket associated to the order. +Returns the I object for the basket associated +to the order. =cut sub basket { my ( $self ) = @_; - my $basket_rs = $self->_result->basketno; + my $basket_rs = $self->_result->basket; return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs ); } =head3 fund - my $fund = $order->fund + my $fund = $order->fund; -Returns the fund (aqbudgets) associated to the order. +Returns the I object for the fund (aqbudgets) +associated to the order. =cut sub fund { my ( $self ) = @_; - my $fund_rs = $self->_result->budget; + my $fund_rs = $self->_result->fund; return Koha::Acquisition::Fund->_new_from_dbic( $fund_rs ); } =head3 invoice - my $invoice = $order->invoice + my $invoice = $order->invoice; -Returns the invoice associated to the order. +Returns the I object for the invoice associated +to the order. + +It returns B if no linked invoice is found. =cut sub invoice { my ( $self ) = @_; - my $invoice_rs = $self->_result->invoiceid; + my $invoice_rs = $self->_result->invoice; return unless $invoice_rs; return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs ); } @@ -158,13 +163,16 @@ sub invoice { my $subscription = $order->subscription -Returns the subscription associated to the order. +Returns the I object for the subscription associated +to the order. + +It returns B if no linked subscription is found. =cut sub subscription { my ( $self ) = @_; - my $subscription_rs = $self->_result->subscriptionid; + my $subscription_rs = $self->_result->subscription; return unless $subscription_rs; return Koha::Subscription->_new_from_dbic( $subscription_rs ); } --- a/Koha/Schema/Result/Aqorder.pm +++ a/Koha/Schema/Result/Aqorder.pm @@ -664,6 +664,18 @@ __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber"); # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-31 11:51:37 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GQEXetlivZm7buQohl8m4A +__PACKAGE__->belongs_to( + "basket", + "Koha::Schema::Result::Aqbasket", + { "foreign.basketno" => "self.basketno" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + __PACKAGE__->belongs_to( "biblio", "Koha::Schema::Result::Biblio", @@ -676,6 +688,37 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->belongs_to( + "fund", + "Koha::Schema::Result::Aqbudget", + { "foreign.budget_id" => "self.budget_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "invoice", + "Koha::Schema::Result::Aqinvoice", + { "foreign.invoiceid" => "self.invoiceid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "subscription", + "Koha::Schema::Result::Subscription", + { "foreign.subscriptionid" => "self.subscriptionid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + sub koha_objects_class { 'Koha::Acquisition::Orders'; } --