https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37645

Martin Renvoize (ashimema) <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|Signed Off                  |Failed QA

--- Comment #63 from Martin Renvoize (ashimema) 
<[email protected]> ---
Hi Laura,

Thanks for working on this. Having the cron and the new tool share a single
writeoff() / search_for_writeoff code path is a nice improvement, and the
structure is easy to follow. I applied the patches, ran the new tests
(Permissions.t, Account/Line.t, Account/Lines.t, BackgroundJob/BatchWriteoff.t,
plus Account.t and BackgroundJob.t) and the QA script. They all pass, so what
follows is mostly things the current tests don't exercise. The first two are
the ones I'd really like to see fixed, because both can lead to an unintended
mass writeoff.

BLOCKERS

1. An empty --file writes off everything (misc/cronjobs/writeoff_debts.pl)

Before the patch, an empty list became "accountlines_id IN ()" and matched
nothing. Now search_for_writeoff ignores an empty accountline_ids, and the "at
least one filter" check passes because $file is set. I checked this: with one
outstanding debt in the database, search_for_writeoff({ accountline_ids => []
}) returns it. So "--file empty.txt --confirm" would write off every
outstanding debt, and the same happens if the file only holds blank or
non-numeric lines.

Could you validate and trim the IDs (/^\d+$/), die if --file gives us none, and
make search_for_writeoff treat "IDs supplied but empty" differently from "no ID
filter" (exists $params->{accountline_ids} rather than truthiness)? A test for
that case would be great.

2. The web tool ignores the user's dateformat (tools/writeoff_debts.pl)

The flatpickr fields submit dates in the system preference format, and those
values go straight into "DATE(me.date) <= ?". I checked this too: added_before
=> '2999-01-01' matches my test debt, '01/01/2999' matches nothing. On any
non-ISO site the preview and the writeoff set will be wrong without any
warning.

Please run the values through dt_from_string, hand ISO dates to
search_for_writeoff, and reject anything that doesn't parse. A test with a
non-ISO dateformat would be good.

ON DATE FORMATS GENERALLY

Most of the cron scripts that take dates (delete_patrons.pl,
update_patrons_category.pl, overdue_notices.pl, holds_reminder.pl) use ISO
YYYY-MM-DD parsed with dt_from_string($v, 'iso'). Let's stick with that for the
CLI options here. For the web tool, convert from the user's format to ISO in
the script, and keep search_for_writeoff ISO-only. (cleanup_database.pl and
erm_run_harvester.pl parse in the syspref format instead. That's out of scope
here, but probably worth its own bug.)

SHOULD FIX

3. Cron date semantics changed. It used to be "date < 'YYYY-MM-DD 00:00:00'" /
"date > ...". Now it's DATE(date) <= / >=, so the boundary day is included.
That might be the better behaviour, but it needs to be deliberate, so please
note it in the POD and commit message, or keep the old behaviour. DATE(me.date)
also can't use an index on a big accountlines table, so a range comparison
(date >= ? and date < ? + 1 day) would be kinder.

4. BatchWriteoff::process uses stale data and skips silently. All lines are
loaded up front. If one is paid or changed while the job waits in the queue,
it's written off using the old amount, or fails. Please reload each line
(->discard_changes) before writing it off. Lines that are no longer eligible
are skipped with no message, so total_records and total_success don't add up
and the report doesn't say why. A "skipped / not eligible" message would help.

5. Line::writeoff exceptions. The PAYOUT guard throws IsNotDebit, which is
misleading, so a dedicated exception would be clearer. The state guards also
run before the mandatory-parameter checks, so the error you get depends on the
line. Please document the exceptions in the POD.

6. No error handling in the cron. writeoff can now throw, and the first failure
aborts the whole run. Please catch per line and report under --verbose.

7. Library scoping. The tool offers every library and can write off lines for
any branch, whatever IndependentBranches says. It would be good to match how
the sibling tools handle this. The branch filter also uses
accountlines.branchcode, which can be NULL.

8. Translatable strings and error text (tools/writeoff_debts.pl). The messages
set in Perl (filter_error, "No eligible account lines...") can't be translated,
so please pass flags and keep the wording in the template. error => "$_" also
shows raw exception text to staff. Log it and show something generic.

9. Preview uses cud-form. It works because of the CSRF token, but cud- should
be for state changes, and preview is read-only. The report page also posts the
ID list as a hidden textarea, so a cap on size would be sensible.

10. Duplicate-job check in enqueue. It's race-prone, and $data->{staff_id} eq
$staff_id will warn if $staff_id is undef.

11. Job link permissions. The "view job" link goes to admin/background_jobs.pl,
which requires catalogue. Someone with only tools: batch_writeoff and
updatecharges: writeoff may not be able to open it. Could you check?

TESTS

The current tests don't cover an empty ID list, a non-ISO dateformat, or a line
that changes between enqueue and process, so those would be worth adding
alongside the fixes above.

NITS

- BackgroundJob.pm: batch_writeoff is out of order in core_types_to_classes.
- Exceptions/Account.pm: stray =cut before the next =head2 (the QA script skips
pod_coverage on this file).
- batch_writeoff.inc: empty js block and unused success/warning branches.
- A short comment on the -not { OVERDUE + UNRETURNED } condition would help.
It's easy to misread.
- Please squash the follow-up commits when you attach the next version.

Thanks again, and shout if any of this is unclear.

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to