Bugzilla – Attachment 96995 Details for
Bug 24252
Add credits, debits, credit_offsets and debit_offsets relationships to Koha::Account::Line
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24252: Add relations to Koha::Account::Line
Bug-24252-Add-relations-to-KohaAccountLine.patch (text/plain), 5.60 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-01-08 14:08:40 UTC
(
hide
)
Description:
Bug 24252: Add relations to Koha::Account::Line
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-01-08 14:08:40 UTC
Size:
5.60 KB
patch
obsolete
>From ec7fe386c32a6862d5c17ea92d3448a774bc5770 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 13 Sep 2019 14:03:11 +0100 >Subject: [PATCH] Bug 24252: Add relations to Koha::Account::Line > >This patch adds two new relationships to the Koha::Account::Line object. > >* credit_offsets - returns all credit type Koha::Account::Offsets > related to this Koha::Account::Line. >* debit_offsets - returns all debit type Koha::Account::Offsets related > to this Koha::Account::Line. >* credits - returns all credits related to this Koha::Account::Line. >* debits - returns all debits related to this Koha::Account::Line. > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Account/Line.pm | 81 +++++++++++++++++++++++++++++ > t/db_dependent/Koha/Account/Lines.t | 61 +++++++++++++++++++++- > 2 files changed, 141 insertions(+), 1 deletion(-) > >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index 6f1e5b6e00..f84d460178 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -110,6 +110,87 @@ sub debit_type { > return Koha::Account::DebitType->_new_from_dbic( $rs ); > } > >+=head3 credit_offsets >+ >+Return the credit_offsets linked to this account line if some exist >+ >+=cut >+ >+sub credit_offsets { >+ my ( $self ) = @_; >+ my $rs = $self->_result->account_offsets_credits; >+ return unless $rs; >+ return Koha::Account::Offsets->_new_from_dbic($rs); >+} >+ >+=head3 debit_offsets >+ >+Return the debit_offsets linked to this account line if some exist >+ >+=cut >+ >+sub debit_offsets { >+ my ( $self ) = @_; >+ my $rs = $self->_result->account_offsets_debits; >+ return unless $rs; >+ return Koha::Account::Offsets->_new_from_dbic($rs); >+} >+ >+ >+=head3 credits >+ >+ my $credits = $accountline->credits; >+ my $credits = $accountline->credits( $cond, $attr ); >+ >+Return the credits linked to this account line if some exist. >+Search conditions and attributes may be passed if you wish to filter >+the resultant resultant resultset. >+ >+=cut >+ >+sub credits { >+ my ( $self, $cond, $attr ) = @_; >+ >+ unless ( $self->is_debit ) { >+ Koha::Exceptions::Account::IsNotCredit->throw( >+ error => 'Account line ' . $self->id . ' is not a debit' >+ ); >+ } >+ >+ my $rs = >+ $self->_result->search_related('account_offsets_debits') >+ ->search_related( 'credit', $cond, $attr ); >+ return unless $rs; >+ return Koha::Account::Lines->_new_from_dbic($rs); >+} >+ >+=head3 debits >+ >+ my $debits = $accountline->debits; >+ my $debits = $accountline->debits( $cond, $attr ); >+ >+Return the debits linked to this account line if some exist. >+Search conditions and attributes may be passed if you wish to filter >+the resultant resultant resultset. >+ >+=cut >+ >+sub debits { >+ my ( $self, $cond, $attr ) = @_; >+ >+ unless ( $self->is_credit ) { >+ Koha::Exceptions::Account::IsNotCredit->throw( >+ error => 'Account line ' . $self->id . ' is not a credit' >+ ); >+ } >+ >+ my $rs = >+ $self->_result->search_related('account_offsets_credits') >+ ->search_related( 'debit', $cond, $attr ); >+ return unless $rs; >+ return Koha::Account::Lines->_new_from_dbic($rs); >+} >+ > =head3 void > > $payment_accountline->void(); >diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t >index 735b91fc15..6e99bb45eb 100755 >--- a/t/db_dependent/Koha/Account/Lines.t >+++ b/t/db_dependent/Koha/Account/Lines.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 11; > use Test::Exception; > > use C4::Circulation qw/AddIssue AddReturn/; >@@ -518,6 +518,65 @@ subtest 'checkout() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'credits() and debits() tests' => sub { >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $account = $patron->account; >+ >+ my $debit1 = $account->add_debit({ >+ amount => 8, >+ interface => 'commandline', >+ type => 'ACCOUNT', >+ }); >+ my $debit2 = $account->add_debit({ >+ amount => 12, >+ interface => 'commandline', >+ type => 'ACCOUNT', >+ }); >+ my $credit1 = $account->add_credit({ >+ amount => 5, >+ interface => 'commandline', >+ type => 'CREDIT', >+ }); >+ my $credit2 = $account->add_credit({ >+ amount => 10, >+ interface => 'commandline', >+ type => 'CREDIT', >+ }); >+ >+ $credit1->apply({ debits => [ $debit1 ] }); >+ $credit2->apply({ debits => [ $debit1, $debit2 ] }); >+ >+ my $credits = $debit1->credits; >+ is($credits->count, 2, '2 Credits applied to debit 1'); >+ my $credit = $credits->next; >+ is($credit->amount + 0, -5, 'Correct first credit'); >+ $credit = $credits->next; >+ is($credit->amount + 0, -10, 'Correct second credit'); >+ >+ $credits = $debit2->credits; >+ is($credits->count, 1, '1 Credits applied to debit 2'); >+ $credit = $credits->next; >+ is($credit->amount + 0, -10, 'Correct first credit'); >+ >+ my $debits = $credit1->debits; >+ is($debits->count, 1, 'Credit 1 applied to 1 debit'); >+ my $debit = $debits->next; >+ is($debit->amount + 0, 8, 'Correct first debit'); >+ >+ $debits = $credit2->debits; >+ is($debits->count, 2, 'Credit 2 applied to 2 debits'); >+ $debit = $debits->next; >+ is($debit->amount + 0, 8, 'Correct first debit'); >+ $debit = $debits->next; >+ is($debit->amount + 0, 12, 'Correct second debit'); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest "void() tests" => sub { > > plan tests => 16; >-- >2.24.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24252
:
96363
|
96371
|
96518
| 96995 |
110639