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

(-)a/Koha/Account/Offsets.pm (-6 / +14 lines)
Lines 34-47 Account offsets track the changes made to the balance of account lines Link Here
34
34
35
=head2 Class methods
35
=head2 Class methods
36
36
37
=head3 total
38
37
    my $offsets = Koha::Account::Offsets->search({ ...  });
39
    my $offsets = Koha::Account::Offsets->search({ ...  });
38
    my $total   = $offsets->total;
40
    my $total   = $offsets->total;
39
41
40
Returns the sum of the amounts of the account offsets resultset. If the resultset is
42
Returns the sum of the amounts of the account offsets resultset. If the resultset is
41
empty it returns 0.
43
empty it returns 0.
42
44
43
=head3 total
44
45
=cut
45
=cut
46
46
47
sub total {
47
sub total {
Lines 60-70 sub total { Link Here
60
      : 0;
60
      : 0;
61
}
61
}
62
62
63
=head3 filter_by_non_reversable
63
=head3 filter_by_non_reversible
64
65
    my $non_reversible = $debit->->search(..)->filter_by_non_reversible;
66
67
Filter offsets so only non-reversible ones are left in the resultset.
64
68
65
=cut
69
=cut
66
70
67
sub filter_by_non_reversable {
71
sub filter_by_non_reversible {
68
    my ($self) = @_;
72
    my ($self) = @_;
69
73
70
    my $me = $self->_resultset()->current_source_alias;
74
    my $me = $self->_resultset()->current_source_alias;
Lines 82-92 sub filter_by_non_reversable { Link Here
82
    return $self->search( $where, $attr );
86
    return $self->search( $where, $attr );
83
}
87
}
84
88
85
=head3 filter_by_reversable
89
=head3 filter_by_reversible
90
91
    my $reversible = Koha::Account::Offsets->search(..)->filter_by_reversible;
92
93
Filter offsets so only non ones are left in the resultset.
86
94
87
=cut
95
=cut
88
96
89
sub filter_by_reversable {
97
sub filter_by_reversible {
90
    my ($self) = @_;
98
    my ($self) = @_;
91
99
92
    my $me = $self->_resultset()->current_source_alias;
100
    my $me = $self->_resultset()->current_source_alias;
(-)a/t/db_dependent/Koha/Account/Offsets.t (-12 / +11 lines)
Lines 73-79 subtest 'total() tests' => sub { Link Here
73
    $schema->storage->txn_rollback;
73
    $schema->storage->txn_rollback;
74
};
74
};
75
75
76
subtest 'filter_by_non_reversable() and filter_by_reversable() tests' => sub {
76
subtest 'filter_by_non_reversible() and filter_by_reversible() tests' => sub {
77
77
78
    plan tests => 4;
78
    plan tests => 4;
79
79
Lines 90-105 subtest 'filter_by_non_reversable() and filter_by_reversable() tests' => sub { Link Here
90
    $account->pay( { amount => 4, type => 'PAYMENT' } );
90
    $account->pay( { amount => 4, type => 'PAYMENT' } );
91
    $account->pay( { amount => 5, type => 'CREDIT' } );
91
    $account->pay( { amount => 5, type => 'CREDIT' } );
92
92
93
    # non-reversable offsets
93
    # non-reversible offsets
94
    is( $manual_fee->debit_offsets->filter_by_non_reversable->count,
94
    is( $manual_fee->debit_offsets->filter_by_non_reversible->count,
95
        3, '3 non-reversable offsets' );
95
        3, '3 non-reversible offsets' );
96
    is( $manual_fee->debit_offsets->filter_by_non_reversable->total,
96
    is( $manual_fee->debit_offsets->filter_by_non_reversible->total,
97
        -6, '-6 the total amount of the non-reversable offsets' );
97
        -6, '-6 the total amount of the non-reversible offsets' );
98
    # reversable offsets
98
    # reversible offsets
99
    is( $manual_fee->debit_offsets->filter_by_reversable->count,
99
    is( $manual_fee->debit_offsets->filter_by_reversible->count,
100
        2, 'The right reversable offsets count' );
100
        2, 'The right reversible offsets count' );
101
    is( $manual_fee->debit_offsets->filter_by_reversable->total,
101
    is( $manual_fee->debit_offsets->filter_by_reversible->total,
102
        -5, 'The right total amount of the reversable offsets' );
102
        -5, 'The right total amount of the reversible offsets' );
103
103
104
    $schema->storage->txn_rollback;
104
    $schema->storage->txn_rollback;
105
};
105
};
106
- 

Return to bug 29757