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

(-)a/Koha/Acquisition/Order.pm (+16 lines)
Lines 22-27 use Carp qw( croak ); Link Here
22
use Koha::Acquisition::Baskets;
22
use Koha::Acquisition::Baskets;
23
use Koha::Acquisition::Funds;
23
use Koha::Acquisition::Funds;
24
use Koha::Acquisition::Invoices;
24
use Koha::Acquisition::Invoices;
25
use Koha::Subscriptions;
25
use Koha::Database;
26
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string output_pref );
27
use Koha::DateUtils qw( dt_from_string output_pref );
27
28
Lines 151-156 sub invoice { Link Here
151
    return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs );
152
    return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs );
152
}
153
}
153
154
155
=head3 subscription
156
157
    my $subscription = $order->subscription
158
159
Returns the subscription associated to the order.
160
161
=cut
162
163
sub subscription {
164
    my ( $self )  = @_;
165
    my $subscription_rs = $self->_result->subscriptionid;
166
    return unless $subscription_rs;
167
    return Koha::Subscription->_new_from_dbic( $subscription_rs );
168
}
169
154
=head2 Internal methods
170
=head2 Internal methods
155
171
156
=head3 _type
172
=head3 _type
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-2 / +30 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 143-145 subtest 'invoice' => sub { Link Here
143
143
144
    $schema->storage->txn_rollback;
144
    $schema->storage->txn_rollback;
145
};
145
};
146
- 
146
147
subtest 'subscription' => sub {
148
    plan tests => 2;
149
150
    $schema->storage->txn_begin;
151
    my $o = $builder->build_object(
152
        {
153
            class => 'Koha::Acquisition::Orders',
154
            value => { subscriptionid => undef }, # not linked to a subscription
155
        }
156
    );
157
158
    my $order = Koha::Acquisition::Orders->find( $o->ordernumber );
159
    is( $order->subscription, undef,
160
        '->subscription should return undef if not created from a subscription');
161
162
    $o = $builder->build_object(
163
        {
164
            class => 'Koha::Acquisition::Orders',
165
            # Will be linked to a subscription by TestBuilder
166
        }
167
    );
168
169
    $order = Koha::Acquisition::Orders->find( $o->ordernumber );
170
    is( ref( $order->subscription ), 'Koha::Subscription',
171
        '->subscription should return a Koha::Subscription object if created from a subscription');
172
173
    $schema->storage->txn_rollback;
174
};

Return to bug 20366