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

(-)a/Koha/Checkout.pm (+15 lines)
Lines 28-33 use Koha::Checkouts::ReturnClaims; Link Here
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::DateUtils;
29
use Koha::DateUtils;
30
use Koha::Items;
30
use Koha::Items;
31
use Koha::Libraries;
31
32
32
use base qw(Koha::Object);
33
use base qw(Koha::Object);
33
34
Lines 77-82 sub item { Link Here
77
    return Koha::Item->_new_from_dbic( $item_rs );
78
    return Koha::Item->_new_from_dbic( $item_rs );
78
}
79
}
79
80
81
=head3 library
82
83
my $library = $checkout->library;
84
85
Return the library in which the transaction took place
86
87
=cut
88
89
sub library {
90
    my ( $self ) = @_;
91
    my $library_rs = $self->_result->library;
92
    return Koha::Library->_new_from_dbic( $library_rs );
93
}
94
80
=head3 patron
95
=head3 patron
81
96
82
my $patron = $checkout->patron
97
my $patron = $checkout->patron
(-)a/Koha/Old/Checkout.pm (+16 lines)
Lines 18-23 package Koha::Old::Checkout; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Libraries;
21
22
22
use base qw(Koha::Object);
23
use base qw(Koha::Object);
23
24
Lines 43-48 sub item { Link Here
43
    return Koha::Item->_new_from_dbic( $item_rs );
44
    return Koha::Item->_new_from_dbic( $item_rs );
44
}
45
}
45
46
47
=head3 library
48
49
my $library = $checkout->library;
50
51
Return the library in which the transaction took place. Might return I<undef>.
52
53
=cut
54
55
sub library {
56
    my ( $self ) = @_;
57
    my $library_rs = $self->_result->library;
58
    return unless $library_rs;
59
    return Koha::Library->_new_from_dbic( $library_rs );
60
}
61
46
=head3 patron
62
=head3 patron
47
63
48
my $patron = $checkout->patron
64
my $patron = $checkout->patron
(-)a/Koha/Schema/Result/Issue.pm (+12 lines)
Lines 303-308 __PACKAGE__->belongs_to( Link Here
303
  },
303
  },
304
);
304
);
305
305
306
__PACKAGE__->belongs_to(
307
  "library",
308
  "Koha::Schema::Result::Branch",
309
  { "foreign.branchcode" => "self.branchcode" },
310
  {
311
    is_deferrable => 1,
312
    join_type     => "LEFT",
313
    on_delete     => "CASCADE",
314
    on_update     => "CASCADE",
315
  },
316
);
317
306
sub koha_object_class {
318
sub koha_object_class {
307
    'Koha::Checkout';
319
    'Koha::Checkout';
308
}
320
}
(-)a/Koha/Schema/Result/OldIssue.pm (+10 lines)
Lines 261-266 __PACKAGE__->belongs_to( Link Here
261
  },
261
  },
262
);
262
);
263
263
264
__PACKAGE__->belongs_to(
265
  "library",
266
  "Koha::Schema::Result::Branch",
267
  { "foreign.branchcode" => "self.branchcode" },
268
  {
269
    is_deferrable => 1,
270
    join_type     => "LEFT",
271
  },
272
);
273
264
sub koha_object_class {
274
sub koha_object_class {
265
    'Koha::Old::Checkout';
275
    'Koha::Old::Checkout';
266
}
276
}
(-)a/t/db_dependent/Koha/Checkout.t (+50 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
use t::lib::TestBuilder;
24
25
use Koha::Database;
26
27
my $builder = t::lib::TestBuilder->new;
28
my $schema  = Koha::Database->new->schema;
29
30
subtest 'library() tests' => sub {
31
32
    plan tests => 2;
33
34
    $schema->storage->txn_begin;
35
36
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
37
    my $checkout = $builder->build_object(
38
        {
39
            class => 'Koha::Checkouts',
40
            value => {
41
                branchcode => $library->branchcode
42
            }
43
        }
44
    );
45
46
    is( ref($checkout->library), 'Koha::Library', 'Object type is correct' );
47
    is( $checkout->library->branchcode, $library->branchcode, 'Right library linked' );
48
49
    $schema->storage->txn_rollback;
50
};
(-)a/t/db_dependent/Koha/Old.t (-6 / +35 lines)
Lines 19-41 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Old::Patrons;
25
use Koha::Old::Patrons;
26
use Koha::Old::Biblios;
26
use Koha::Old::Biblios;
27
use Koha::Old::Checkouts;
27
use Koha::Old::Items;
28
use Koha::Old::Items;
28
29
29
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
30
31
31
my $schema = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
35
34
36
subtest 'Koha::Old::Patrons' => sub {
35
subtest 'Koha::Old::Patrons' => sub {
36
37
    plan tests => 1;
37
    plan tests => 1;
38
38
39
    $schema->storage->txn_begin;
40
39
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
41
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
40
    my $patron_unblessed = $patron->unblessed;
42
    my $patron_unblessed = $patron->unblessed;
41
    $patron->move_to_deleted;
43
    $patron->move_to_deleted;
Lines 48-57 subtest 'Koha::Old::Patrons' => sub { Link Here
48
    delete $deleted_patron->{updated_on};
50
    delete $deleted_patron->{updated_on};
49
    delete $patron_unblessed->{updated_on};
51
    delete $patron_unblessed->{updated_on};
50
    is_deeply( $deleted_patron, $patron_unblessed );
52
    is_deeply( $deleted_patron, $patron_unblessed );
53
54
    $schema->storage->txn_rollback;
51
};
55
};
52
56
53
subtest 'Koha::Old::Biblios and Koha::Old::Items' => sub {
57
subtest 'Koha::Old::Biblios and Koha::Old::Items' => sub {
54
    # Cannot be tested in a meaningful way so far
58
    # Cannot be tested in a meaningful way so far
55
    ok(1);
59
    ok(1);
56
};
60
};
57
$schema->storage->txn_rollback;
61
62
subtest 'Koha::Old::Checkout->library() tests' => sub {
63
64
    plan tests => 3;
65
66
    $schema->storage->txn_begin;
67
68
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
69
    my $checkout = $builder->build_object(
70
        {
71
            class => 'Koha::Old::Checkouts',
72
            value => {
73
                branchcode => $library->branchcode
74
            }
75
        }
76
    );
77
78
    is( ref($checkout->library), 'Koha::Library', 'Object type is correct' );
79
    is( $checkout->library->branchcode, $library->branchcode, 'Right library linked' );
80
81
    $library->delete;
82
    $checkout->discard_changes;
83
84
    is( $checkout->library, undef, 'If the library has been deleted, undef is returned' );
85
86
    $schema->storage->txn_rollback;
87
};
58
- 

Return to bug 26327