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

(-)a/Koha/Account/Line.pm (+81 lines)
Lines 110-115 sub debit_type { Link Here
110
    return Koha::Account::DebitType->_new_from_dbic( $rs );
110
    return Koha::Account::DebitType->_new_from_dbic( $rs );
111
}
111
}
112
112
113
=head3 credit_offsets
114
  
115
Return the credit_offsets linked to this account line if some exist
116
117
=cut
118
119
sub credit_offsets {
120
    my ( $self ) = @_;
121
    my $rs = $self->_result->account_offsets_credits;
122
    return unless $rs;
123
    return Koha::Account::Offsets->_new_from_dbic($rs);
124
}
125
126
=head3 debit_offsets
127
128
Return the debit_offsets linked to this account line if some exist
129
130
=cut
131
132
sub debit_offsets {
133
    my ( $self ) = @_;
134
    my $rs = $self->_result->account_offsets_debits;
135
    return unless $rs;
136
    return Koha::Account::Offsets->_new_from_dbic($rs);
137
}
138
139
140
=head3 credits
141
  
142
  my $credits = $accountline->credits;
143
  my $credits = $accountline->credits( $cond, $attr );
144
145
Return the credits linked to this account line if some exist.
146
Search conditions and attributes may be passed if you wish to filter 
147
the resultant resultant resultset.
148
149
=cut
150
151
sub credits {
152
    my ( $self, $cond, $attr ) = @_;
153
    
154
    unless ( $self->is_debit ) {
155
        Koha::Exceptions::Account::IsNotCredit->throw(
156
            error => 'Account line ' . $self->id . ' is not a debit'
157
        );
158
    }
159
160
    my $rs =
161
      $self->_result->search_related('account_offsets_debits')
162
      ->search_related( 'credit', $cond, $attr );
163
    return unless $rs;
164
    return Koha::Account::Lines->_new_from_dbic($rs);
165
}
166
167
=head3 debits
168
169
  my $debits = $accountline->debits;
170
  my $debits = $accountline->debits( $cond, $attr );
171
172
Return the debits linked to this account line if some exist.
173
Search conditions and attributes may be passed if you wish to filter 
174
the resultant resultant resultset.
175
176
=cut
177
178
sub debits {
179
    my ( $self, $cond, $attr ) = @_;
180
    
181
    unless ( $self->is_credit ) {
182
        Koha::Exceptions::Account::IsNotCredit->throw(
183
            error => 'Account line ' . $self->id . ' is not a credit'
184
        );
185
    }
186
187
    my $rs =
188
      $self->_result->search_related('account_offsets_credits')
189
      ->search_related( 'debit', $cond, $attr );
190
    return unless $rs;
191
    return Koha::Account::Lines->_new_from_dbic($rs);
192
}
193
113
=head3 void
194
=head3 void
114
195
115
  $payment_accountline->void();
196
  $payment_accountline->void();
(-)a/t/db_dependent/Koha/Account/Lines.t (-2 / +60 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation qw/AddIssue AddReturn/;
25
use C4::Circulation qw/AddIssue AddReturn/;
Lines 518-523 subtest 'checkout() tests' => sub { Link Here
518
    $schema->storage->txn_rollback;
518
    $schema->storage->txn_rollback;
519
};
519
};
520
520
521
subtest 'credits() and debits() tests' => sub {
522
    plan tests => 10;
523
524
    $schema->storage->txn_begin;
525
526
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
527
    my $account = $patron->account;
528
529
    my $debit1 = $account->add_debit({
530
        amount    => 8,
531
        interface => 'commandline',
532
        type      => 'ACCOUNT',
533
    });
534
    my $debit2 = $account->add_debit({
535
        amount    => 12,
536
        interface => 'commandline',
537
        type      => 'ACCOUNT',
538
    });
539
    my $credit1 = $account->add_credit({
540
        amount    => 5,
541
        interface => 'commandline',
542
        type      => 'CREDIT',
543
    });
544
    my $credit2 = $account->add_credit({
545
        amount    => 10,
546
        interface => 'commandline',
547
        type      => 'CREDIT',
548
    });
549
550
    $credit1->apply({ debits => [ $debit1 ] });
551
    $credit2->apply({ debits => [ $debit1, $debit2 ] });
552
553
    my $credits = $debit1->credits;
554
    is($credits->count, 2, '2 Credits applied to debit 1');
555
    my $credit = $credits->next;
556
    is($credit->amount + 0, -5, 'Correct first credit');
557
    $credit = $credits->next;
558
    is($credit->amount + 0, -10, 'Correct second credit');
559
560
    $credits = $debit2->credits;
561
    is($credits->count, 1, '1 Credits applied to debit 2');
562
    $credit = $credits->next;
563
    is($credit->amount + 0, -10, 'Correct first credit');
564
565
    my $debits = $credit1->debits;
566
    is($debits->count, 1, 'Credit 1 applied to 1 debit');
567
    my $debit = $debits->next;
568
    is($debit->amount + 0, 8, 'Correct first debit');
569
570
    $debits = $credit2->debits;
571
    is($debits->count, 2, 'Credit 2 applied to 2 debits');
572
    $debit = $debits->next;
573
    is($debit->amount + 0, 8, 'Correct first debit');
574
    $debit = $debits->next;
575
    is($debit->amount + 0, 12, 'Correct second debit');
576
577
    $schema->storage->txn_rollback;
578
};
579
521
subtest "void() tests" => sub {
580
subtest "void() tests" => sub {
522
581
523
    plan tests => 16;
582
    plan tests => 16;
524
- 

Return to bug 24252