Bug 24300

Summary: Add a 'payout amount' option to accounts
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: Fines and feesAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: CLOSED FIXED QA Contact: Tomás Cohen Arazi (tcohen) <tomascohen>
Severity: enhancement    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, nick, sally.healey, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27636
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This enhancement adds a 'Payout amount' button to the borrowers account details page when there is outstanding credit. This allows a library to payout multiple outstanding credits in one action.
Version(s) released in:
21.05.00
Circulation function:
Bug Depends on: 24080, 27927, 27967    
Bug Blocks: 27971    
Attachments: Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: (QA follow-up) Add Unit Tests
Bug 24300: (follow-up) Set minimum for amount input
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: (QA follow-up) Add Unit Tests
Bug 24300: (follow-up) Set minimum for amount input
Bug 24300: (QA follow-up) Update payout_amount to use internal methods
Bug 24300: (QA follow-up) Enhance test and catch failures
Bug 24300: (QA follow-up) Enhance test and catch failures
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: (QA follow-up) Add Unit Tests
Bug 24300: (follow-up) Set minimum for amount input
Bug 24300: (QA follow-up) Update payout_amount to use internal methods
Bug 24300: (QA follow-up) Enhance test and catch failures
Bug 24300: (QA follow-up) Enhance test and catch failures
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: (QA follow-up) Add Unit Tests
Bug 24300: (follow-up) Set minimum for amount input
Bug 24300: (QA follow-up) Update payout_amount to use internal methods
Bug 24300: (QA follow-up) Enhance test and catch failures
Bug 24300: Add payout_amount method to Koha::Account
Bug 24300: Add payout amount to boraccount page
Bug 24300: (QA follow-up) Add Unit Tests
Bug 24300: (follow-up) Set minimum for amount input
Bug 24300: (QA follow-up) Update payout_amount to use internal methods
Bug 24300: (QA follow-up) Enhance test and catch failures

Description Martin Renvoize (ashimema) 2019-12-23 12:55:28 UTC
Bug 24080 adds a payout option to allow paying out amounts against individual credits. We should also allow for a 'payout amount' option which allows for paying out against any total outstanding credit.
Comment 1 Martin Renvoize (ashimema) 2021-02-05 13:13:47 UTC
I'm thinking of adding a payout_amount method within Koha::Account that does similar to the offset_amount method I'm looking to add in bug 27636 but in the reverse direction.. i.e. it adds a PAYOUT debit line and offsets it against a set of passed CREDIT lines.
Comment 2 Martin Renvoize (ashimema) 2021-02-05 14:32:22 UTC
Created attachment 116395 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account
Comment 3 Martin Renvoize (ashimema) 2021-02-05 15:13:05 UTC
Created attachment 116412 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account
Comment 4 Martin Renvoize (ashimema) 2021-02-05 15:13:08 UTC
Created attachment 116413 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff
Comment 5 Martin Renvoize (ashimema) 2021-02-05 15:15:09 UTC
This will need some unit tests adding for QA, but it's ready for an initial testing phase.

I'm not entirely sure I like how it works.. at the moment you can payout prior to paying off debts so you may result in an account that more in debt than before the payout.

Feedback welcome.
Comment 6 ByWater Sandboxes 2021-02-12 15:52:15 UTC
Created attachment 116837 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 7 ByWater Sandboxes 2021-02-12 15:52:18 UTC
Created attachment 116838 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 8 Sally 2021-02-12 15:59:39 UTC
Patch works as described.

An account being more in debt is ok - there are sometimes circumstances where a patron might owe money, but they also need a refund for an unrelated transaction.
  
With that in mind, it might be nice to have the option to pay out the credit despite the patron being in debt.

e.g.

Patron owes £20.00 for lost book - but let's say this is in dispute.
Patron borrows 5 x DVDs at £2 each.
Patron is given a credit for all 5 DVDs.
Patron then decides to have a refund rather than replacement DVDs.

There is no payout button because the account says £10.00 (£20 owed minus £10 credit).  It would be nice to have a payout button for the £10 credit, rather than having to issue payout across 5 individual lines.  

Equally, on the payment page, it would be nice to be able to use the credit against selected lines - a bit like 'Pay Selected' or 'Write off Selected', it'd be nice to 'Use Credit against Selected' - so again, we can use the credit against the DVDs and not against the lost book.

I get the feeling that's all out of scope of this bug though.  But the patch works as described, so I'm signing off.
Comment 9 Katrin Fischer 2021-03-06 12:50:20 UTC
Hi Martin, please add unit tests!
Comment 10 Martin Renvoize (ashimema) 2021-03-08 09:11:30 UTC
(In reply to Katrin Fischer from comment #9)
> Hi Martin, please add unit tests!

Dang, how did I forget that!..
Comment 11 Martin Renvoize (ashimema) 2021-03-08 11:20:38 UTC
Created attachment 117917 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

This patch adds a 'payout_amount' method to the Koha::Account class to
allow payout of an amount against a list of credits (or any outstanding
credits, oldest to newest).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 12 Martin Renvoize (ashimema) 2021-03-08 11:20:41 UTC
Created attachment 117918 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 13 Martin Renvoize (ashimema) 2021-03-08 11:20:45 UTC
Created attachment 117919 [details] [review]
Bug 24300: (QA follow-up) Add Unit Tests

Doh! I forgot the unit tests first time around!
Comment 14 Martin Renvoize (ashimema) 2021-03-16 16:08:04 UTC
Created attachment 118335 [details] [review]
Bug 24300: (follow-up) Set minimum for amount input

Add a 'min' attribute for validation of the amount field in the payout
modal so that negative amounts cannot be submitted.
Comment 15 Tomás Cohen Arazi (tcohen) 2021-03-16 17:03:40 UTC
Works as expected. Tests pass. My QA concerns were promptly addressed by the follow-up. QA script happy.

Good job
Comment 16 Owen Leonard 2021-03-16 17:37:58 UTC
Tomás I think you forgot to add the signed-off patches
Comment 17 Martin Renvoize (ashimema) 2021-03-17 14:22:44 UTC
Created attachment 118392 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

This patch adds a 'payout_amount' method to the Koha::Account class to
allow payout of an amount against a list of credits (or any outstanding
credits, oldest to newest).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 18 Martin Renvoize (ashimema) 2021-03-17 14:22:47 UTC
Created attachment 118393 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 19 Martin Renvoize (ashimema) 2021-03-17 14:22:51 UTC
Created attachment 118394 [details] [review]
Bug 24300: (QA follow-up) Add Unit Tests

Doh! I forgot the unit tests first time around!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 20 Martin Renvoize (ashimema) 2021-03-17 14:22:54 UTC
Created attachment 118395 [details] [review]
Bug 24300: (follow-up) Set minimum for amount input

Add a 'min' attribute for validation of the amount field in the payout
modal so that negative amounts cannot be submitted.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 21 Martin Renvoize (ashimema) 2021-03-17 14:22:57 UTC
Created attachment 118396 [details] [review]
Bug 24300: (QA follow-up) Update payout_amount to use internal methods

Tomas pointed out that we could, and probably should, use the internal
'add_debit' method within this function.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 22 Martin Renvoize (ashimema) 2021-03-17 14:23:22 UTC
I took the liberty of attaching the patches with Tomas's SO lines ;)
Comment 23 Tomás Cohen Arazi (tcohen) 2021-03-17 14:34:34 UTC
(In reply to Owen Leonard from comment #16)
> Tomás I think you forgot to add the signed-off patches

You are right!
Comment 24 Tomás Cohen Arazi (tcohen) 2021-03-17 14:34:52 UTC
(In reply to Martin Renvoize from comment #22)
> I took the liberty of attaching the patches with Tomas's SO lines ;)

Thanks! You saved me some time!
Comment 25 Martin Renvoize (ashimema) 2021-03-18 13:47:56 UTC
Oop, just found a bug in that final QA followup
Comment 26 Martin Renvoize (ashimema) 2021-03-18 14:09:46 UTC
(In reply to Martin Renvoize from comment #25)
> Oop, just found a bug in that final QA followup

And.. I realised I'd missed tests for offset creations too..
Comment 27 Martin Renvoize (ashimema) 2021-03-18 14:47:48 UTC
Created attachment 118464 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them
Comment 28 Martin Renvoize (ashimema) 2021-03-19 10:13:34 UTC
Created attachment 118503 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them
Comment 29 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:14 UTC
Created attachment 118601 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

This patch adds a 'payout_amount' method to the Koha::Account class to
allow payout of an amount against a list of credits (or any outstanding
credits, oldest to newest).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 30 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:19 UTC
Created attachment 118602 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 31 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:23 UTC
Created attachment 118603 [details] [review]
Bug 24300: (QA follow-up) Add Unit Tests

Doh! I forgot the unit tests first time around!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 32 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:28 UTC
Created attachment 118604 [details] [review]
Bug 24300: (follow-up) Set minimum for amount input

Add a 'min' attribute for validation of the amount field in the payout
modal so that negative amounts cannot be submitted.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 33 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:32 UTC
Created attachment 118605 [details] [review]
Bug 24300: (QA follow-up) Update payout_amount to use internal methods

Tomas pointed out that we could, and probably should, use the internal
'add_debit' method within this function.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 34 Tomás Cohen Arazi (tcohen) 2021-03-22 14:42:37 UTC
Created attachment 118606 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them
Comment 35 Martin Renvoize (ashimema) 2021-03-22 15:55:32 UTC
Created attachment 118612 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 36 Martin Renvoize (ashimema) 2021-04-06 11:06:34 UTC
Created attachment 119195 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

This patch adds a 'payout_amount' method to the Koha::Account class to
allow payout of an amount against a list of credits (or any outstanding
credits, oldest to newest).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 37 Martin Renvoize (ashimema) 2021-04-06 11:06:38 UTC
Created attachment 119196 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 38 Martin Renvoize (ashimema) 2021-04-06 11:06:41 UTC
Created attachment 119197 [details] [review]
Bug 24300: (QA follow-up) Add Unit Tests

Doh! I forgot the unit tests first time around!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 39 Martin Renvoize (ashimema) 2021-04-06 11:06:44 UTC
Created attachment 119198 [details] [review]
Bug 24300: (follow-up) Set minimum for amount input

Add a 'min' attribute for validation of the amount field in the payout
modal so that negative amounts cannot be submitted.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 40 Martin Renvoize (ashimema) 2021-04-06 11:06:48 UTC
Created attachment 119199 [details] [review]
Bug 24300: (QA follow-up) Update payout_amount to use internal methods

Tomas pointed out that we could, and probably should, use the internal
'add_debit' method within this function.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 41 Martin Renvoize (ashimema) 2021-04-06 11:06:51 UTC
Created attachment 119200 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 42 Martin Renvoize (ashimema) 2021-04-06 11:08:53 UTC
Tree re-arranged slightly to put bugs that need backporting before these enhancements that don't.

Rebased to accommodate the above.
Comment 43 Jonathan Druart 2021-04-08 09:59:36 UTC
Blocked by bug 27927.
Comment 44 Martin Renvoize (ashimema) 2021-04-22 16:06:59 UTC
Created attachment 120016 [details] [review]
Bug 24300: Add payout_amount method to Koha::Account

This patch adds a 'payout_amount' method to the Koha::Account class to
allow payout of an amount against a list of credits (or any outstanding
credits, oldest to newest).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 45 Martin Renvoize (ashimema) 2021-04-22 16:07:06 UTC
Created attachment 120017 [details] [review]
Bug 24300: Add payout amount to boraccount page

Test plan
1/ Add some debts and credits to a patrons account, resulting in an
overall credit
2/ Note the appearance of a 'Payout amount' button next to the total due
line.
3/ Try paying out an amount with the button
4/ Signoff

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 46 Martin Renvoize (ashimema) 2021-04-22 16:07:11 UTC
Created attachment 120018 [details] [review]
Bug 24300: (QA follow-up) Add Unit Tests

Doh! I forgot the unit tests first time around!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 47 Martin Renvoize (ashimema) 2021-04-22 16:07:15 UTC
Created attachment 120019 [details] [review]
Bug 24300: (follow-up) Set minimum for amount input

Add a 'min' attribute for validation of the amount field in the payout
modal so that negative amounts cannot be submitted.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 48 Martin Renvoize (ashimema) 2021-04-22 16:07:19 UTC
Created attachment 120020 [details] [review]
Bug 24300: (QA follow-up) Update payout_amount to use internal methods

Tomas pointed out that we could, and probably should, use the internal
'add_debit' method within this function.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 49 Martin Renvoize (ashimema) 2021-04-22 16:07:23 UTC
Created attachment 120021 [details] [review]
Bug 24300: (QA follow-up) Enhance test and catch failures

The tests did not include testing for offset lines. This patch adds such
tests and updates the function to pass them

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 50 Jonathan Druart 2021-04-23 09:55:08 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 51 Fridolin Somers 2021-04-30 07:48:59 UTC
Enhancement not pushed to 20.11.x