Bugzilla – Attachment 81105 Details for
Bug 13098
Item lost multiple times by the same patron will create only be charged once
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13098: Add Koha::Account::Offsets->total
Bug-13098-Add-KohaAccountOffsets-total.patch (text/plain), 4.08 KB, created by
Alex Buckley
on 2018-10-25 03:53:09 UTC
(
hide
)
Description:
Bug 13098: Add Koha::Account::Offsets->total
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2018-10-25 03:53:09 UTC
Size:
4.08 KB
patch
obsolete
>From f153885ca656c666de7c09cdd1b42c658d2fb1cf Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 18 Oct 2018 12:57:33 -0300 >Subject: [PATCH] Bug 13098: Add Koha::Account::Offsets->total > >This patch introduces this trivial method for returning the sum0 result >of the amount columns of a Koha::Account::Offsets set. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/Koha/Account/Offsets.t >- Sign off :-D > >Followed test plan, patch worked as described >Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz> >--- > Koha/Account/Offsets.pm | 15 ++++++++ > t/db_dependent/Koha/Account/Offsets.t | 70 +++++++++++++++++++++++++++++++++++ > 2 files changed, 85 insertions(+) > create mode 100755 t/db_dependent/Koha/Account/Offsets.t > >diff --git a/Koha/Account/Offsets.pm b/Koha/Account/Offsets.pm >index 79c7995..d788058 100644 >--- a/Koha/Account/Offsets.pm >+++ b/Koha/Account/Offsets.pm >@@ -18,6 +18,7 @@ package Koha::Account::Offsets; > use Modern::Perl; > > use Carp; >+use List::Util qw(sum0); > > use Koha::Database; > >@@ -33,6 +34,20 @@ Account offsets track the changes made to the balance of account lines > > =head1 API > >+=head2 Class methods >+ >+=head3 total >+ >+=cut >+ >+sub total { >+ my ( $self ) = @_; >+ >+ my $total = sum0( $self->get_column('amount') ); >+ >+ return $total; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/t/db_dependent/Koha/Account/Offsets.t b/t/db_dependent/Koha/Account/Offsets.t >new file mode 100755 >index 0000000..4ebdc5d >--- /dev/null >+++ b/t/db_dependent/Koha/Account/Offsets.t >@@ -0,0 +1,70 @@ >+#!/usr/bin/perl >+ >+# Copyright 2018 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses> >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Exception; >+ >+use Koha::Account::Offsets; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'total_outstanding() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $line = $builder->build_object( { class => 'Koha::Account::Lines' } ); >+ >+ my $amount_1 = 100; >+ my $amount_2 = 200; >+ my $amount_3 = -100; >+ my $amount_4 = -300; >+ my $amount_5 = 500; >+ >+ my $offset_1 = Koha::Account::Offset->new( >+ { type => 'Fine', amount => $amount_1, credit_id => $line->id } )->store; >+ my $offset_2 = Koha::Account::Offset->new( >+ { type => 'Fine', amount => $amount_2, credit_id => $line->id } )->store; >+ my $offset_3 = Koha::Account::Offset->new( >+ { type => 'Payment', amount => $amount_3, credit_id => $line->id } )->store; >+ my $offset_4 = Koha::Account::Offset->new( >+ { type => 'Payment', amount => $amount_4, credit_id => $line->id } )->store; >+ my $offset_5 = Koha::Account::Offset->new( >+ { type => 'Fine', amount => $amount_5, credit_id => $line->id } )->store; >+ >+ my $debits = Koha::Account::Offsets->search( { type => 'Fine', credit_id => $line->id } ); >+ is( $debits->total, $amount_1 + $amount_2 + $amount_5 ); >+ >+ my $credits = Koha::Account::Offsets->search( { type => 'Payment', credit_id => $line->id } ); >+ is( $credits->total, $amount_3 + $amount_4 ); >+ >+ my $all = Koha::Account::Offsets->search( { credit_id => $line->id } ); >+ is( $all->total, $amount_1 + $amount_2 + $amount_3 + $amount_4 + $amount_5 ); >+ >+ my $none = Koha::Account::Offsets->search( { credit_id => $line->id + 1 } ); >+ is( $none->total, 0, 'No offsets, returns 0' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.1.4
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 13098
:
80507
|
80678
|
80862
|
80863
|
80864
|
81105
|
81106
|
81107
|
81194
|
81195
|
81354
|
81538
|
81539
|
81540
|
81541
|
81542
|
81543