Bug 21607: Make Koha::Account::Line->apply store credits as negative amounts
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 18 Oct 2018 14:39:37 +0000 (11:39 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 19 Oct 2018 17:27:43 +0000 (17:27 +0000)
This is a trivial patch, that makes offsets have 'amount' stored as
negative values for applied credits.

The behaviour is changed on the tests and adjusted in the code. To test:
- Run
  $ kshell
 k$ prove t/db_dependent/Koha/Account/Lines.t
=> SUCCESS: Tests pass!
- Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Koha/Account/Line.pm
t/db_dependent/Koha/Account/Lines.t

index 9cf8867..3573e60 100644 (file)
@@ -190,7 +190,7 @@ sub apply {
             Koha::Account::Offset->new(
                 {   credit_id => $self->id,
                     debit_id  => $debit->id,
-                    amount    => $amount_to_cancel,
+                    amount    => $amount_to_cancel * -1,
                     type      => $offset_type,
                 }
             )->store();
index 20033e7..eb8dfdd 100755 (executable)
@@ -202,7 +202,7 @@ subtest 'apply() tests' => sub {
     my $offsets = Koha::Account::Offsets->search( { credit_id => $credit->id, debit_id => $debit_1->id } );
     is( $offsets->count, 1, 'Only one offset is generated' );
     my $THE_offset = $offsets->next;
-    is( $THE_offset->amount * 1, 10, 'Amount was calculated correctly (less than the available credit)' );
+    is( $THE_offset->amount * 1, -10, 'Amount was calculated correctly (less than the available credit)' );
     is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
 
     $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
@@ -216,7 +216,7 @@ subtest 'apply() tests' => sub {
     $offsets = Koha::Account::Offsets->search( { credit_id => $credit->id, debit_id => $debit_2->id } );
     is( $offsets->count, 1, 'Only one offset is generated' );
     $THE_offset = $offsets->next;
-    is( $THE_offset->amount * 1, 90, 'Amount was calculated correctly (less than the available credit)' );
+    is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' );
     is( $THE_offset->type, 'Credit Applied', 'Defaults to \'Credit Applied\' offset type' );
 
     $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });