Bug 22421 - accountlines.issue_id is missing a foreign key constraint
Summary: accountlines.issue_id is missing a foreign key constraint
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Database (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Martin Renvoize (ashimema)
QA Contact: Emily Lamancusa (emlam)
URL:
Keywords:
Depends on:
Blocks: 5334 14825 17976
  Show dependency treegraph
 
Reported: 2019-02-27 11:42 UTC by Martin Renvoize (ashimema)
Modified: 2024-11-13 13:55 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 22421: Add tests for new constraints (2.38 KB, patch)
2019-02-27 13:55 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (3.98 KB, patch)
2019-02-27 13:55 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.05 KB, patch)
2019-02-27 13:55 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (2.71 KB, patch)
2019-06-06 11:45 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (4.45 KB, patch)
2019-06-06 11:45 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.21 KB, patch)
2019-06-06 11:45 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (2.70 KB, patch)
2019-06-06 12:26 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (4.45 KB, patch)
2019-06-06 12:26 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.21 KB, patch)
2019-06-06 12:26 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Correct checkout relation (2.22 KB, patch)
2019-06-06 12:26 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (2.77 KB, patch)
2019-06-06 13:09 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (4.51 KB, patch)
2019-06-06 13:09 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.28 KB, patch)
2019-06-06 13:09 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Correct checkout relation (2.29 KB, patch)
2019-06-06 13:09 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (4.38 KB, patch)
2024-02-08 14:42 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (6.49 KB, patch)
2024-02-08 14:42 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.25 KB, patch)
2024-02-08 14:42 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Correct checkout relation (4.52 KB, patch)
2024-02-08 14:42 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Schema Update (4.56 KB, patch)
2024-02-08 14:42 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (3.60 KB, patch)
2024-02-16 20:48 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (5.69 KB, patch)
2024-02-16 20:48 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.30 KB, patch)
2024-02-16 20:49 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 22421: (follow-up) Correct checkout relation (4.57 KB, patch)
2024-02-16 20:49 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 22421: Schema Update (4.62 KB, patch)
2024-02-16 20:49 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 22421: (follow-up) Check issue during add_debit (2.19 KB, patch)
2024-05-13 12:34 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421 (follow-up): Check issue during add_credit (2.37 KB, patch)
2024-10-24 15:57 UTC, Emily Lamancusa (emlam)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Use checkout accessor to get correct issue_id (2.63 KB, patch)
2024-10-24 15:57 UTC, Emily Lamancusa (emlam)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Fix tests (985 bytes, patch)
2024-10-24 15:57 UTC, Emily Lamancusa (emlam)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Improve recoverability if dbrev fails in the middle (3.61 KB, patch)
2024-10-24 18:39 UTC, Emily Lamancusa (emlam)
Details | Diff | Splinter Review
Bug 22421: Add tests for new constraints (3.67 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Add missing constraints (5.75 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Ensure old_issue_id is populated in accountlines (1.37 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Correct checkout relation (4.64 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: Schema Update (4.68 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Check issue during add_debit (2.26 KB, patch)
2024-10-31 13:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up): Check issue during add_credit (2.44 KB, patch)
2024-10-31 13:15 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Use checkout accessor to get correct issue_id (2.70 KB, patch)
2024-10-31 13:15 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Fix tests (1.03 KB, patch)
2024-10-31 13:15 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (follow-up) Improve recoverability if dbrev fails in the middle (3.68 KB, patch)
2024-10-31 13:15 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 22421: (QA follow-up) Update API mapping and specs (3.93 KB, patch)
2024-11-08 15:58 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Renvoize (ashimema) 2019-02-27 11:42:14 UTC

    
Comment 1 Martin Renvoize (ashimema) 2019-02-27 12:30:28 UTC
This is a more challenging one, as issue_id refers to not one but two distinct tables .. issues and old_issues.. as such we either need to merge issues and old_issues or split this constraint into two distinct fields and ensure they're properly populated.

I've opted for the distinct fields in this patch for now as it's the simpler approach and can be easily switched at a later date for the issue/old_issue merge.
Comment 2 Martin Renvoize (ashimema) 2019-02-27 13:55:32 UTC
Created attachment 85773 [details] [review]
Bug 22421: Add tests for new constraints
Comment 3 Martin Renvoize (ashimema) 2019-02-27 13:55:34 UTC
Created attachment 85774 [details] [review]
Bug 22421: Add missing constraints
Comment 4 Martin Renvoize (ashimema) 2019-02-27 13:55:37 UTC
Created attachment 85775 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines
Comment 5 Josef Moravec 2019-03-15 10:15:22 UTC
Sorry, can't apply:

Applying: Bug 22421: Add tests for new constraints
error: sha1 information is lacking or useless (t/db_dependent/Koha/Account/Lines.t).

There are also some templates referencing issue_id, it should be fixed, and  Koha::Accout::Line->checkout should be adjusted too...
Comment 6 Martin Renvoize (ashimema) 2019-06-06 11:45:00 UTC
Created attachment 90352 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 7 Martin Renvoize (ashimema) 2019-06-06 11:45:04 UTC
Created attachment 90353 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Martin Renvoize (ashimema) 2019-06-06 11:45:06 UTC
Created attachment 90354 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 9 Martin Renvoize (ashimema) 2019-06-06 12:26:24 UTC
Created attachment 90359 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 10 Martin Renvoize (ashimema) 2019-06-06 12:26:27 UTC
Created attachment 90360 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 11 Martin Renvoize (ashimema) 2019-06-06 12:26:30 UTC
Created attachment 90361 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 12 Martin Renvoize (ashimema) 2019-06-06 12:26:33 UTC
Created attachment 90362 [details] [review]
Bug 22421: (follow-up) Correct checkout relation

The Koha::Account::Line->checkout relationship accessor needed an update
to respect the new fields and foreign keys introduced here.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 13 Kyle M Hall (khall) 2019-06-06 13:09:13 UTC
Created attachment 90365 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 14 Kyle M Hall (khall) 2019-06-06 13:09:23 UTC
Created attachment 90366 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 15 Kyle M Hall (khall) 2019-06-06 13:09:26 UTC
Created attachment 90367 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 16 Kyle M Hall (khall) 2019-06-06 13:09:28 UTC
Created attachment 90368 [details] [review]
Bug 22421: (follow-up) Correct checkout relation

The Koha::Account::Line->checkout relationship accessor needed an update
to respect the new fields and foreign keys introduced here.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Katrin Fischer 2019-06-12 05:54:18 UTC
Trying to test this, but I am having issues getting a lost replacement fee to charge. I have set a replacement default cost on item level and set WhenLostChargeReplacementFee to Charge. Items are returned on setting the lost status. Not sure if this is related yet, but maybe you can help verify.
Comment 18 Katrin Fischer 2019-06-12 06:01:32 UTC
I also tried charging overdue fines and returning the items. After returning them, the due date and return date information are no longer visible in accountlines (not implemented yet?). old_issue_id is set, so that works.

I'll have to reset my db to check the lost behaviour, running a bit low on time right now, help appreciated.
Comment 19 Katrin Fischer 2019-07-11 06:30:17 UTC
I got myself into trouble here:

1) Check out item backdated, so it's overdue
2) Run fines.pl to accrue fines
3) Return it
4) Verify title etc. still show

- Apply patchset

1) Run updatedatabase and dbic, restart_all
2) Check out same item backdated again
3) Return from patron account

DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_kohadev`.`accountlines`, CONSTRAINT `accountlines_ibfk_issues` FOREIGN KEY (`issue_id`) REFERENCES `issues` (`issue_id`) ON DELETE SET NULL ON UPDATE CASCADE) [for Statement "INSERT INTO `accountlines` ( `accounttype`, `amount`, `amountoutstanding`, `borrowernumber`, `branchcode`, `date`, `description`, `interface`, `issue_id`, `itemnumber`, `manager_id`, `note`, `payment_type`, `status`) VALUES ( ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ?, ?, ?, ?, ? )" with ParamValues: 0='OVERDUE', 1=0.9, 2=0.9, 3=51, 4=undef, 5='Conspirator : 07/01/2019 23:59', 6='intranet', 7=4, 8=22, 9=undef, 10='', 11=undef, 12='UNRETURNED'] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1836.
Broken FK constraint at /usr/share/perl5/Exception/Class/Base.pm line 88
	Exception::Class::Base::throw('Koha::Exceptions::Object::FKConstraint', 'error', 'Broken FK constraint', 'broken_fk', 'issue_id') called at /home/vagrant/kohaclone/Koha/Object.pm line 163
Comment 20 Martin Renvoize (ashimema) 2024-02-08 14:42:42 UTC
Created attachment 161919 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 21 Martin Renvoize (ashimema) 2024-02-08 14:42:45 UTC
Created attachment 161920 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 22 Martin Renvoize (ashimema) 2024-02-08 14:42:48 UTC
Created attachment 161921 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 23 Martin Renvoize (ashimema) 2024-02-08 14:42:51 UTC
Created attachment 161922 [details] [review]
Bug 22421: (follow-up) Correct checkout relation

The Koha::Account::Line->checkout relationship accessor needed an update
to respect the new fields and foreign keys introduced here.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 24 Martin Renvoize (ashimema) 2024-02-08 14:42:53 UTC
Created attachment 161923 [details] [review]
Bug 22421: Schema Update
Comment 25 Martin Renvoize (ashimema) 2024-02-08 14:43:36 UTC
Rebased and brought up to modern standards..

Back to read for QA
Comment 26 Victor Grousset/tuxayo 2024-02-16 20:48:55 UTC
Created attachment 162244 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 27 Victor Grousset/tuxayo 2024-02-16 20:48:58 UTC
Created attachment 162245 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 28 Victor Grousset/tuxayo 2024-02-16 20:49:01 UTC
Created attachment 162246 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 29 Victor Grousset/tuxayo 2024-02-16 20:49:03 UTC
Created attachment 162247 [details] [review]
Bug 22421: (follow-up) Correct checkout relation

The Koha::Account::Line->checkout relationship accessor needed an update
to respect the new fields and foreign keys introduced here.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 30 Victor Grousset/tuxayo 2024-02-16 20:49:06 UTC
Created attachment 162248 [details] [review]
Bug 22421: Schema Update

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 31 Victor Grousset/tuxayo 2024-02-16 20:49:40 UTC
I'm not sure about all of the implications and places to change but at least here is another signoff. Changes in tests make sense.

Additional testing:
Confirmed that purged old_issues (cleanup_database.pl) are handled well :)
(accountlines.issue_id is nulled)
Comment 32 Victor Grousset/tuxayo 2024-02-16 22:03:34 UTC
QA script reports this:

 WARN	C4/Circulation.pm
   WARN	  tidiness
		The file is less tidy than before (bad/messy lines before: 1095, now: 1098)

 WARN	Koha/Schema/Result/Accountline.pm
   WARN	  tidiness
		The file is less tidy than before (bad/messy lines before: 142, now: 162)

 WARN	Koha/Schema/Result/Issue.pm
   WARN	  tidiness
		The file is less tidy than before (bad/messy lines before: 108, now: 112)

 WARN	Koha/Schema/Result/OldIssue.pm
   WARN	  tidiness
		The file is less tidy than before (bad/messy lines before: 106, now: 110)

At the time of the 1st submission these patches, perltidy was already in Coding Guidelines (PERL1), and was about default perltidy config. Likely a lot of current errors are from default config and not or few customization. So at least a lot at the messy lines would be needed.
Comment 33 Emily Lamancusa (emlam) 2024-05-10 21:23:34 UTC
Taking a look at this one...

It looks like there are some test failures:

t/db_dependent/Koha/Account/Line.t .. 1/15     # Looks like you planned 4 tests but ran 2.
#   Failed test 'library() tests'
#   at t/db_dependent/Koha/Account/Line.t line 173.
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Unknown column 'me.old_issue_id' in 'field list' at /kohadevbox/koha/Koha/Objects.pm line 95
# Looks like your test exited with 255 just after 4.
t/db_dependent/Koha/Account/Line.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 12/15 subtests 


t/db_dependent/Circulation.t .. 17/74 
#   Failed test 'CanBookBeRenewed tests'
#   at t/db_dependent/Circulation.t line 1753.
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Unknown column 'me.old_issue_id' in 'field list' at /kohadevbox/koha/Koha/Objects.pm line 319
# Looks like your test exited with 11 just after 17.
t/db_dependent/Circulation.t .. Dubious, test returned 11 (wstat 2816, 0xb00)
Failed 58/74 subtests 


I'm also not sure it makes sense to put all steps of the dbrev inside the "unless" that checks for the existence of the old_issue_id column. If for some reason the column exists but the foreign keys don't exist (e.g. a previous update failed in the middle), the whole dbrev would be skipped and the foreign keys wouldn't be created. I think it should be pretty doable to have a separate check for most individual steps of the dbrev.
Comment 34 Martin Renvoize (ashimema) 2024-05-13 12:34:02 UTC
Created attachment 166631 [details] [review]
Bug 22421: (follow-up) Check issue during add_debit

We need additional handling for the case where a debt may be added with
an issue_id after the issue is returned.

This patch tries to fix that at a low level, but introduces new test
failures in t/db_dependent/Circulation.t to be investigated.
Comment 35 Martin Renvoize (ashimema) 2024-05-13 12:37:28 UTC
More work needed here so leaving in FQA
Comment 36 Katrin Fischer 2024-10-24 07:14:55 UTC
This is needed to move the ODUE notices to TT which would be a real nice thing.
Can we get this moving again?
Comment 37 Emily Lamancusa (emlam) 2024-10-24 15:57:35 UTC
Created attachment 173287 [details] [review]
Bug 22421 (follow-up): Check issue during add_credit

Additional handling for the case where a credit is added with an
issue_id after the issue is returned.

add_credit will keep the same method signature, where the issue_id
parameter may now refer to a current issue or an old issue. It will then
internally determine whether it is a current or old checkout and handle
it appropriately.

If the caller is updating an account line, or adding a credit to refund
an existing debit, they may not need to know whether it is for a current
checkout or an old checkout. In this case, they can use the account
line's ->checkout accessor to pass in the appropriate issue_id
regardless of whether it is a current or old checkout.
Comment 38 Emily Lamancusa (emlam) 2024-10-24 15:57:37 UTC
Created attachment 173288 [details] [review]
Bug 22421: (follow-up) Use checkout accessor to get correct issue_id

In some cases, we may want to update an AccountLine that is linked to a
checkout without knowing whether it is a current or old checkout. In
these cases, use the AccountLines ->checkout accessor to ensure we get
the issue_id correctly, regardless of whether it is a current issue or
and old_issue.

This also applies when generating a new AccountLine based on an existing
AccountLine (for example, adding a credit to refund a previously charged
fine)
Comment 39 Emily Lamancusa (emlam) 2024-10-24 15:57:39 UTC
Created attachment 173289 [details] [review]
Bug 22421: (follow-up) Fix tests

Need to search by old_issue_id instead of issue_id when checking the
value of an accountline after calling AddReturn on the linked checkout
Comment 40 Emily Lamancusa (emlam) 2024-10-24 16:12:35 UTC
I was able to get tests passing again with a few small adjustments to pm files to handle cases where the attached checkout may be a current checkout or an old checkout.

I do still think an improvement could be made to the reliability of the dbrev (see https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22421#c33), so leaving at FQA for now. (I can most likely come back and submit a patch for that later today.)

Finally, removing myself as the QA contact, as I feel I've made enough changes in my follow-up patches to warrant another pair of eyes on them before this moves into PQA status.
Comment 41 Emily Lamancusa (emlam) 2024-10-24 18:39:37 UTC
Created attachment 173305 [details] [review]
Bug 22421: (follow-up) Improve recoverability if dbrev fails in the middle
Comment 42 Martin Renvoize (ashimema) 2024-10-31 13:14:41 UTC
Created attachment 173790 [details] [review]
Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 43 Martin Renvoize (ashimema) 2024-10-31 13:14:44 UTC
Created attachment 173791 [details] [review]
Bug 22421: Add missing constraints

DB update to add a new old_issue_id field to accountlines and set
foreign key constraints for both the new field and the existing issue_id
field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 44 Martin Renvoize (ashimema) 2024-10-31 13:14:47 UTC
Created attachment 173792 [details] [review]
Bug 22421: Ensure old_issue_id is populated in accountlines

Update C4::Circulation::MarkIssueReturned to handle moving issue_id to
old_issue_id in accountlines.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 45 Martin Renvoize (ashimema) 2024-10-31 13:14:50 UTC
Created attachment 173793 [details] [review]
Bug 22421: (follow-up) Correct checkout relation

The Koha::Account::Line->checkout relationship accessor needed an update
to respect the new fields and foreign keys introduced here.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 46 Martin Renvoize (ashimema) 2024-10-31 13:14:54 UTC
Created attachment 173794 [details] [review]
Bug 22421: Schema Update

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 47 Martin Renvoize (ashimema) 2024-10-31 13:14:57 UTC
Created attachment 173795 [details] [review]
Bug 22421: (follow-up) Check issue during add_debit

We need additional handling for the case where a debt may be added with
an issue_id after the issue is returned.

This patch tries to fix that at a low level, but introduces new test
failures in t/db_dependent/Circulation.t to be investigated.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 48 Martin Renvoize (ashimema) 2024-10-31 13:15:00 UTC
Created attachment 173796 [details] [review]
Bug 22421: (follow-up): Check issue during add_credit

Additional handling for the case where a credit is added with an
issue_id after the issue is returned.

add_credit will keep the same method signature, where the issue_id
parameter may now refer to a current issue or an old issue. It will then
internally determine whether it is a current or old checkout and handle
it appropriately.

If the caller is updating an account line, or adding a credit to refund
an existing debit, they may not need to know whether it is for a current
checkout or an old checkout. In this case, they can use the account
line's ->checkout accessor to pass in the appropriate issue_id
regardless of whether it is a current or old checkout.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 49 Martin Renvoize (ashimema) 2024-10-31 13:15:03 UTC
Created attachment 173797 [details] [review]
Bug 22421: (follow-up) Use checkout accessor to get correct issue_id

In some cases, we may want to update an AccountLine that is linked to a
checkout without knowing whether it is a current or old checkout. In
these cases, use the AccountLines ->checkout accessor to ensure we get
the issue_id correctly, regardless of whether it is a current issue or
and old_issue.

This also applies when generating a new AccountLine based on an existing
AccountLine (for example, adding a credit to refund a previously charged
fine)

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 50 Martin Renvoize (ashimema) 2024-10-31 13:15:06 UTC
Created attachment 173798 [details] [review]
Bug 22421: (follow-up) Fix tests

Need to search by old_issue_id instead of issue_id when checking the
value of an accountline after calling AddReturn on the linked checkout

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 51 Martin Renvoize (ashimema) 2024-10-31 13:15:09 UTC
Created attachment 173799 [details] [review]
Bug 22421: (follow-up) Improve recoverability if dbrev fails in the middle

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 52 Martin Renvoize (ashimema) 2024-10-31 13:17:05 UTC
I'm happy with all the follow-ups etc.. it all makes sense to me..

Honestly.. with the first revision of this written by me 5+ years ago I have no recollection of that code.  I think we should set this PQA to prevent further holdup of downstream bugs.
Comment 53 Katrin Fischer 2024-11-08 11:46:05 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 54 Katrin Fischer 2024-11-08 13:41:47 UTC
I am afraid we have some broken tests that probably relate to the changes here:

t_db_dependent_api_v1_patrons_accounts_t
Comment 55 Martin Renvoize (ashimema) 2024-11-08 15:58:51 UTC
Created attachment 174281 [details] [review]
Bug 22421: (QA follow-up) Update API mapping and specs

We missed some cases where the API specs and mappings were missing for
the new old_issue_id field.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 56 Martin Renvoize (ashimema) 2024-11-13 13:47:30 UTC
Please remove the additional_work_needed flag if you're done Katrin.. it's getting impossible to keep on top of this stuff.
Comment 57 Katrin Fischer 2024-11-13 13:55:21 UTC
(In reply to Martin Renvoize (ashimema) from comment #56)
> Please remove the additional_work_needed flag if you're done Katrin.. it's
> getting impossible to keep on top of this stuff.

The keyword is on my review list for today. I usually remove them, but missed the "push note" here too.