Hello to all,

I am trying to do what is in the title of this mail, but there is something surprising:

Everything works perfectly well, except when inserting statistics cookies (for the parent obviously). Indeed, when changing the state of the subtask, the lines like this :

- State " new state" from "old state" [2022-08-04 Thu 16:09]

are not saved under the subtask, but always under the main heading.

To reproduce this curious behavior, you only need this configuration: 

  (setq org-todo-keywords
        '((sequence "TODO(t!)" "|" "DONE(d!)" )))

  (defun org-summary-todo (n-done n-not-done)
    "Switch entry to DONE when all subentries are done, to TODO otherwise."
    (let (org-log-done org-log-states) ; turn off logging
      (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

  (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

;;(setq org-log-into-drawer t) ;;to have a logbook


and try on an org document like this one:


* TODO heading [0/1]

- State "DONE" from "TODO" [2022-08-04 Thu 16:09]

** TODO change the state of this heading !


My org-mode version is 9.5.2 (release_9.5.2-25-gaf6f12 @ /usr/share/emacs/28.1/lisp/org/).


Thank you in advance for your answers