Skip to content

[FIX] thankyou_letters: ids glued together when an entry is reset to draft - #2225

Open
davidwul wants to merge 2 commits into
18.0from
fix-thankyou-cancel-object-ids
Open

davidwul wants to merge 2 commits into
18.0from
fix-thankyou-cancel-object-ids

Conversation

@davidwul

Copy link
Copy Markdown
Contributor

What and why

When a thanked entry is reset to draft (e.g. its bank statement line is reconciled again), cancel_thankyou_letter() deletes its pending thank you and queues a new one for the donations of the other entries it was also for. It removed the entry's lines from object_ids as text:

object_ids.replace(str(line.id), "").replace(",,", "").strip(",")
  • Removing a middle id glued its neighbours together: in production 9511504,,9511476 became the id 95115049511476. The queued thank you job then failed with MissingError and the new thank you missed these two donations.
  • An id contained in another id could also be cut out of it.
  • When several entries of the same thank you were reset to draft in one call (button_cancel, unlink of posted entries, multi-selection), the new thank you also included the donations of the other entries reset with it.

The remaining lines are now computed as records: the lines of the thank you, minus those of every entry being reset, that still exist and whose entry is posted.

Follows #2224 (same thank-you / deleted lines scenario).

Deployment notes

No upgrade needed (Python only). Communications and queue jobs already holding a glued id can be found with:

-- communications listing an id above the last journal item id
WITH mx AS (SELECT max(id) m FROM account_move_line)
SELECT j.id, j.state, j.object_ids
FROM partner_communication_job j, mx,
     unnest(string_to_array(trim(j.object_ids, '[] '), ',')) x(i)
WHERE trim(x.i) ~ '^[0-9]+$' AND trim(x.i)::numeric > mx.m;
-- failed thank-you jobs
SELECT id, state, func_string FROM queue_job
WHERE method_name LIKE 'generate_thank_you%' AND func_string ~ '[0-9]{12,}';

None on a copy of production of 2026-11-20.

Test evidence

Empty database, --test-tags /thankyou_letters:TestThankYouDeletedLine: 8 tests, 0 failed.

  • test_entry_reset_to_draft_keeps_the_other_donations (three entries of one thank you, the middle one reset to draft): with the base account_move.py, FAIL account.move.line(185189,) != account.move.line(185, 189), the glued id.
  • test_entries_reset_to_draft_together (two of three entries reset in one call): with the first commit of this PR, FAIL account.move.line(225, 227) != account.move.line(227,).

The tests capture the job queued by button_draft (with_delay_sh patched on account.move.line, called exactly once) and run it. The test helper now sets the partner on the entry, as on a bank statement entry: account.move.generate_thank_you starts from it.

Sibling paths

Invariant: after donation entries are reset to draft, their pending thank you is deleted and the job queued in its place lists exactly the donation lines of the other entries, still posted.

  • button_draft and, through it, button_cancel, unlink of posted entries, payment action_draft: all reach cancel_thankyou_letter (docstring lists them). One entry and two entries at once are tested; the others share these tests.
  • _compute_amount queues cancel_thankyou_letter per invoice: same method. Not tested; as the review noted, it reads both payment states after the recompute, so it looks unreachable today (existing code, unchanged).
  • Bank statement action_undo_reconciliation and reconciliation rewrites delete lines without reset to draft: handled by account.move.line.unlink since [FIX] thankyou_letters: forget deleted donation lines in pending thank you #2224, which already works on records.
  • No other place removes ids from object_ids as text (searched the addons).

Rules review

Run with the code-rules reviewer on the first commit:

  • Should fix: several entries of one thank you reset to draft together queued the donations of the others: fixed (second commit), test test_entries_reset_to_draft_together.
  • Suggestion: assert the job is queued once: done (assert_called_once).
  • Suggestion: docstring naming the entry points: done.
  • Gap, not changed: get_objects() parses object_ids with int() and asserts one config model. A thank you whose config is on another model, or a malformed object_ids, would now raise here (the text code did not). _get_unsent_communications ([FIX] thankyou_letters: forget deleted donation lines in pending thank you #2224) already relies on the same; not seen in data, not tested.

🤖 Generated with Claude Code

…draft

When a thanked entry is reset to draft (e.g. its bank statement line is
reconciled again), cancel_thankyou_letter() deletes its thank you and
queues a new one for the lines of the other entries. It removed the
entry's lines from object_ids as text: replace(id, "") then
replace(",,", "") glued the neighbours together ("9511504,,9511476"
became the id 95115049511476), and an id contained in another one could
be cut out of it. The new thank you missed these donations and its job
failed with MissingError.

The remaining lines are now computed as records.

Assisted-by: claude-opus-5-5, medium, claude-code
When several entries of the same thank you are reset to draft in one
call (button_cancel, unlink of posted entries, multi-selection), the new
thank you queued by the first one included the donations of the others.
It is now only for the donations of entries still posted.

Assisted-by: claude-opus-5-5, medium, claude-code
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "[FIX] thankyou_letters: entries of one t..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant